Network: Device Network Information
These functions provide current EdgerOS device network working information.
Functions
edger.network()
- Returns: {Promise} Promise object.
Get the network connection information of the currently connected EdgerOS device.
Example
edger.network().then(data => {
const { connected, connectionType } = data;
console.log(connected, connectionType);
}).catch(error => {
console.error(error);
});
async / await
async function network() {
try {
return await edger.network();
} catch (error) {
console.error(error);
}
}
The obtained data
object contains the following members:
connected
{Boolean}.connectionType
{String}.
App running in the EdgerOS mobile App and running in a normal browser, connected
and connectionType
have different meanings.
In the EdgerOS mobile App environment:
connected
indicates the network connection status of the mobile phone at this time, the network connection is normal totrue
, otherwise it isfalse
.connectionType
indicates the current network connection type of the mobile phone, which may be:'wifi'
,'cellular'
,'none'
,'unknown'
.In browser environment:
connected
indicates whether the WAN interface of the connected EdgerOS device is connected to the Internet.connectionType
is fixed to'wifi'
.
Events
The unified event listener provided by Web-SDK:
const listener = (payload) => {
// Event handling...
}
// add listener
edger.addEventListener('some-event', listener);
// or
// onAction() is an alias of addEventListener().
edger.onAction('some-event', listener);
// remove listener
edger.removeEventListener('some-event', listener);
// remove all listeners
edger.removeAllListeners();
network
This event will be received when the network connection status changes.
Example
const listener = (payload) => {
const { connected, connectionType } = payload;
console.log(connected, connectionType);
}
edger.addEventListener('network', listener);