The purpose of this API is to give a boolean go/nogo answer about whether a network request should be made right now. This API will be configurable to allow a level of certainty, but the goal is to keep the output as binary as possible.
The API will be divided into 3 parts:
- Core service that monitors network conditions and stores metadata
- Service for handling requests for that data, or sending notifications about it
- Web API code that proxies requests from web content to that core service and back
At a macro level, we are going to take into account at least the following data:
- Battery level
- Battery charging state
- rxBytes and txBytes from arbitrary time window
- Network latency
- Type of connection
- Quality of connection
The API will be configurable to 3 level of certainty; high, moderate, and low, signified by 1, 2, and 3, respectively. The API will default to 2.
The flow will be this (We will call the API mozIsNowGood, for the moment):
- Call is made to window.navigator.mozIsNowGood() from a web app, without passing in configuration level, so defaults to 2.
- JS called by mozIsNowGood enters a switch/case to set level to 2, or moderate certainty.
- JS enters logic that takes into account the 6 data points listed above, and comes to a go/nogo answer
- Needs to be fleshed out
- JS returns go/nogo answer to the caller of window.navigator.mozIsNowGood()
Here is the diff of mozilla-central with my changes to mozilla-central.
It is currently working for the following platforms:
- Firefox Desktop (untested)
- B2G Desktop (untested)
- B2G Device
- Firefox for Android (untested)
Pull down this repo, then cd into the mozilla-central (m-c) repo that you've already pulled down. Once in the m-c repo, run the command 'hg import path/to/prototype.diff' and that will apply the changes. Then when you run './mach build' it will build with the new changes!
Once it is done building Firefox Desktop, you can launch it and proceed to the next step.
Once you've built and launched your new Firefox, you can open the console and get access to the API via navigator.mozFxOSUService and the following commands are available:
- navigator.mozFxOSUService.batteryLevel();
- navigator.mozFxOSUService.batteryCharging();
- navigator.mozFxOSUService.recentRxTx();
- navigator.mozFxOSUService.receivedBytes();
- navigator.mozFxOSUService.successRate();
- navigator.mozFxOSUService.isConnectionStable();
- navigator.mozFxOSUService.latencyInfo();
- navigator.mozFxOSUService.memoryManager();
- navigator.mozFxOSUService.connectionType();
- navigator.mozFxOSUService.connectionUp();
- navigator.mozFxOSUService.connectionQuality();
- navigator.mozFxOSUService.mozIsNowGood();
I have added the following files:
- dom/fxosu/FxOSUService.js
- dom/fxosu/FxOSUService.manifest
- dom/fxosu/moz.build
- dom/webidl/FxOSUService.webidl
And I have modified these files:
- b2g/installer/package-manifest.in (Lines 387 to 388)
- browser/installer/package-manifest.in (Lines 556 to 557)
- mobile/android/installer/package-manifest.in (Lines 303 to 304)
- dom/apps/PermissionsTable.jsm (Lines 218 to 223)
- dom/webidl/moz.build (Line 155)
- dom/moz.build (Line 58)
- dom/network/NetworkStatsService.jsm (Lines 31-32, 82-83, 224-239, and 251-252)
- Analyze existing efforts (ie ServiceWorkers, RequestSync) to determine if they can be integrated with our system.
- The prototype API should be written in JavaScript.
- The prototype API should be callable by JavaScript executing in a web sandbox.
- The prototype API should be developer configurable, to provide a level of certainty about network quality.
- The prototype API should be able to access data on the charging state of the device in order to determine if a task should be executed.
- The prototype API should be able to access data on the battery level of the device in order to determine if a task should be executed.
- The prototype API should be able to see if the device has an internet connection to determine if a task should be executed.
- The prototype API should be able to access latency-related network information to determine if a task should be executed.
- The prototype API should be able to function without error on Firefox for Desktop.
- The API should be written in C++ or JavaScript.
- The API should integrate with existing efforts wherever possible.
- The API should be developer configurable, to provide a level of certainty about network quality.
- Write a Web IDL specification for the API implementation.
- The API should take into account the type of network connection, whether it be wifi, cellular data, etc.
- The API should be able to access data about system load on the device in order to determine if the device can handle another task.
- The API should be able to access data on the battery level of the device in order to determine if a task should be executed.
- The API should be able to access data about recent tx/rx data.
- The API should be able to access latency-related network information to determine if a task should be executed.
- The API should analyze network data to determine patterns in network reliability.
- The test app for the API should benchmark device resource usage, contrasting use with the API and use without the API.
- The API should integrate with existing efforts wherever possible.
- The API should be able to function without error on Firefox OS, Firefox for Android, and Firefox for Desktop.
- The test app for the API should be written to function on Firefox OS, Firefox for Android, and Firefox for Desktop.
- The API should passively collect network status information.
- Web API Interfaces
- Battery Level
- Charging State
- Recent RX/RX Data
- Network Stats API
- Latency network info (maybe?)
- Connection
- Wifi
- MobileNetworkInfo
- CellInfo
- MobileConnection
- NetworkStats
- NetworkStatsManager
- John Zeller - [email protected] - IRC: zeller
- Pok Yan Tjiam - [email protected]
- Jonathan McNeil - [email protected]