The Network Information API provides an interface for Web Applications to access the underlying network information (e.g. connection info) of the device.

This document is an Editor's draft and should be treated only as such, and is subject to consensus of the DAP WG.

This specification defines conformance criteria that apply to a single product: the user agent that implements the interfaces that it contains.

Implementations that use ECMAScript to implement the APIs defined in this specification must implement them in a manner consistent with the ECMAScript Bindings defined in the Web IDL specification [[!WEBIDL]], as this specification uses that specification and terminology.

Introduction

The Network Information API provides an interface for Web Applications to access the underlying netowrk information (e.g. connection info) of the device.

The devices today are able to connect to multiple networks (e.g. Cellular, WiFi), and this API enables the Web Applications to get accesss to such information i.e. the type of network, so it may present it to the User for information and/or adapt its content to reflect the underlying network connectivity.



	 	   var connection, connectionSpeed, htmlNode, htmlClass;

	   // create a custom object if navigator.connection isn't available
	   connection = navigator.connection || {'type':'0'};

	   // set connectionSpeed
	   switch(connection.type) {
	     case connection.CELL_3G:
	       // 3G
	       connectionSpeed = 'mediumbandwidth';
	       break;
	     case connection.CELL_2G:
	       // 2G
	       connectionSpeed = 'lowbandwidth';
	       break;
	     case connection.NONE:
	       //N
	       connectionSpeed = 'no-connectivity';
	     default:
	       // WIFI, ETHERNET, UNKNOWN, CELL_4G
	       connectionSpeed = 'highbandwidth';
	   }

	   // set the connection speed on the html element's class attribute
	   htmlNode = document.body.parentNode;
	   htmlClass = htmlNode.getAttribute('class') || '';
	   htmlNode.setAttribute('class', htmlClass + ' ' + connectionSpeed);




	

Security and Privacy Considerations

This section is under development.

API Description

NetworkInfo interface

The NetworkInfo interface is exposed on the Navigator interface.

 
readonly attribute Connection connection
The root node from which the connection information (e.g. type) can be accessed.

Connection interface

The Connection interface provides a handle to connection information such as connection type, and roaming information.

const unsigned short UNKNOWN = 0
Indicates an unknown connection type.
const unsigned short ETHERNET = 1
Indicates an Ethernet connection.
const unsigned short WIFI = 2
Indicates a Wi-Fi connection.
const unsigned short CELL_2G = 3
Indicates a 2G connection (e.g. GSM, GPRS, EDGE, CDMA).
const unsigned short CELL_3G = 4
Indicates a 3G connection (e.g. UMTS)
const unsigned short CELL_4G = 5
Indicates a 4G connection (e.g. LTE)
const unsigned short NONE = 6
Indicates no connectivity.
readonly attribute unsigned short type
returns the current connection type. The value returned MUST be one of the constants.

Features for Future Consideration

TBD

Acknowledgements

The editors would like to thank the input from W3C DAP members to date ...