-
Notifications
You must be signed in to change notification settings - Fork 25
API: Wifi
Wifi Controls plugin has a dual purpose, control the Wifi state and return the signal strength value.
The plugin adds a phoneStateListener returning the current wifi level when the level changes. When a change occurs the plugin uses 'this.webView.sendJavascript()' to trigger the passed function.
Notice that the triggered function is passed as a string. This is because the sendJavascript builds the function call and then is evaluated once inside the webview.
@return - String, 'enabled'
@callback - String, function name when listener fires.
window.wificontrols.enable({callback:'wifiSignal', success:wifiEnabled});
@return - String, 'disabled'
@callback - String, function name when listener fires.
window.wificontrols.disable({callback:'wifiSignal', success:wifiDisabled});
@return - String, 'enabled/disabled'
@callback - String, function name when listener fires.
window.wificontrols.toggle({callback:'wifiSignal', success:wifiDisabled});
window.wificontrols.stop({});
@return - String, 'enabled/disabled'
@callback - String, function name when listener fires.
window.wificontrols.check({callback:'wifiSignal', success:wifiDisabled});
As to negate any issues, the wifi level is not passed converted to an easily managed scale. This allows for custom changes if there are any qualms with the level conversion.
function wifiSignal(returnVal){
var maxStrength = -50;
var minStrength = -120;
var percentage = Math.round(100 - Math.max(0, Math.min((returnVal - maxStrength) / (minStrength - maxStrength), 1) * 100));
$('#wifiSignal h3').text(percentage+'%');
}