function fireEvent(type, id, name, value) {
var event = new this.EventObject(type, id, name, value);
+ console.log('Firing ' + type + ' event id=' + id + ', name=' + name + ', value=' + value);
event_callbacks.fire(event);
}
if (call && (!call.done) && (call.transactionid === msg.transactionid)) {
call.finish();
if (msg.error !== undefined) {
- call.errorCB(msg.error);
+ if (call.errorCB) {
+ call.errorCB(msg.error);
+ }
}
- if (msg.value !== undefined && call.successCB && call.errorCB !== undefined) {
+ if (msg.value !== undefined && call.successCB !== undefined) {
switch (msg.type) {
- case WS_REQUEST_TYPE.WIFI:
- if (msg.name === 'is_enabled') {
- /* default to enabled */
- var result = true;
- call.successCB(result);
+ case WS_REQUEST_TYPE.CONNMAN_MANAGER:
+ case WS_REQUEST_TYPE.CONNMAN_TECHNOLOGY:
+ if (msg.name === 'get_technologies') {
+ var results = [
+ [
+ ["/net/connman/technology/ethernet",
+ {
+ "Name": "Wired",
+ "Type": "ethernet",
+ "Powered": true,
+ "Connected": true,
+ "Tethering": false
+ }],
+ ["/net/connman/technology/wifi",
+ {
+ "Name": "WiFi",
+ "Type": "wifi",
+ "Powered": false,
+ "Connected": false,
+ "Tethering": false
+ }],
+ ["/net/connman/technology/bluetooth",
+ {
+ "Name": "Bluetooth",
+ "Type": "bluetooth",
+ "Powered": false,
+ "Connected": false,
+ "Tethering": false
+ }]
+ ]
+ ];
+
+ replyMsg = JSON.stringify(results);
+ call.successCB(results);
return;
- } else if (msg.name === 'enable' && msg.value === true) {
+ } else if (msg.name === 'enable' && msg.value[1] === true) {
call.successCB();
+ fireEvent(WS_EVENT_TYPE.CONNMAN, msg.value[0], 'PropertyChanged', ["Powered", true]);
return;
- } else if (msg.name === 'enable' && msg.value === false) {
+ } else if (msg.name === 'enable' && msg.value[1] === false) {
call.successCB();
+ fireEvent(WS_EVENT_TYPE.CONNMAN, msg.value[0], 'PropertyChanged', ["Powered", false]);
return;
- } else if (msg.name === 'scan') {
+ } else if (msg.name === 'get_services' || msg.name === 'scan') {
var results = [
[
["/net/connman/service/ethernet_0010f32f5a70_cable",
- {}],
+ {
+ "Type": "ethernet",
+ "Security": [],
+ "State": "ready",
+ "AutoConnect": true,
+ "Domains": ["ftrdhcpuser.net"],
+ "Domains.Configuration": [],
+ "Ethernet": {
+ "Address": "10:20:F3:2F:5E:23",
+ "Interface": "eno1",
+ "MTU": 1500,
+ "Method": "auto"
+ },
+ "Favorite": true,
+ "IPv4": {
+ "Address": "192.168.1.20",
+ "Gateway": "192.168.1.1",
+ "Method": "dhcp",
+ "Netmask": "255.255.255.0"
+ },
+ "IPv4.Configuration": {
+ "Method": "dhcp"
+ },
+ "IPv6": {},
+ "IPv6.Configuration": {
+ "Method": "auto",
+ "Privacy": "disabled"
+ },
+ "Immutable": false,
+ "Name": "Wired",
+ "Nameservers": ["192.168.1.1", "184.11.12.13"],
+ "Nameservers.Configuration": [],
+ "Provider": {},
+ "Proxy": {
+ "Method": "direct"
+ },
+ "Proxy.Configuration": {},
+ "Timeservers": ["192.168.1.1", "pool.ntp.org"],
+ "Timeservers.Configuration": []
+ }],
["/net/connman/service/wifi_c8f733acdf96_3558364737_managed_psk",
{
"Type": "wifi",
call.successCB(results);
}, 2000);
return;
- } else if (msg.name === 'connect') {
- call.successCB();
- setTimeout(function() {
- fireEvent(WS_REQUEST_TYPE.WIFI, '/net/connman/service/wifi_c8f733acdf96_3558364737_managed_psk', 'PropertyChanged', ["Connected", true]);
- }, 2000);
+ }
+ case WS_REQUEST_TYPE.CONNMAN_SERVICE:
+ if (msg.name === 'connect') {
+ if (msg.value[0] === '/net/connman/service/wifi_c8f733acdf96_3558364737_managed_psk' && msg.value[1].Passphrase !== '123') {
+ call.errorCB('Invalid passphrase');
+ } else if (msg.value[0] === '/net/connman/service/wifi_c8f733acdf96_446f75636865626167_managed_psk' && msg.value[1].Passphrase !== '123') {
+ call.errorCB('Invalid passphrase');
+ } else {
+ call.successCB();
+ setTimeout(function() {
+ fireEvent(WS_EVENT_TYPE.CONNMAN, msg.value[0], 'PropertyChanged', ["Connected", true]);
+ }, 2000);
+ }
return;
} else if (msg.name === 'disconnect') {
call.successCB();
setTimeout(function() {
- fireEvent(WS_REQUEST_TYPE.WIFI, '/net/connman/service/wifi_c8f733acdf96_3558364737_managed_psk', 'PropertyChanged', ["Connected", false]);
+ fireEvent(WS_EVENT_TYPE.CONNMAN, msg.value[0], 'PropertyChanged', ["Connected", false]);
}, 2000);
return;
} else {
- call.errorCB('Unsupported request: ' + msg.name + ', ' + msg.value);
- return;
- }
- break;
- case WS_REQUEST_TYPE.BLUETOOTH:
- if (msg.name === 'enable' && msg.value === true) {
- call.successCB();
- return;
- } else if (msg.name === 'enable' && msg.value === false) {
- call.successCB();
- return;
- } else {
- call.errorCB('Unsupported request: ' + msg.name + ', ' + msg.value);
+ if (call.errorCB) {
+ call.errorCB('Unsupported request: ' + msg.name + ', ' + msg.value);
+ }
return;
}
break;
case WS_REQUEST_TYPE.DATETIME:
if (msg.name === 'is_time_updates_auto' && msg.value !== undefined) {
/* default to manual */
- var result = false;
- call.successCB(result);
+ call.successCB(false);
return;
} else if (msg.name === 'is_timezone_updates_auto' && msg.value !== undefined) {
/* default to manual */
- var result = false;
- call.successCB(result);
+ call.successCB(false);
return;
} else if (msg.name === 'time' && msg.value !== undefined) {
call.successCB();
call.successCB();
return;
} else {
- call.errorCB('Unsupported request: ' + msg.name + ', ' + msg.value);
+ if (call.errorCB) {
+ call.errorCB('Unsupported request: ' + msg.name + ', ' + msg.value);
+ }
return;
}
break;
case WS_REQUEST_TYPE.DISPLAY:
case WS_REQUEST_TYPE.SOUND:
case WS_REQUEST_TYPE.LOCALE:
- call.errorCB('Request not implemented');
+ if (call.errorCB) {
+ call.errorCB('Request not implemented');
+ }
return;
default:
- call.errorCB('Invalid request type: ' + msg.type);
+ if (call.errorCB) {
+ call.errorCB('Invalid request type: ' + msg.type);
+ }
return;
}
}