forked from doublerobotics/d3-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
59 lines (48 loc) · 1.59 KB
/
index.js
File metadata and controls
59 lines (48 loc) · 1.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// DRDoubleSDK is a global object loaded in by Electron in the Standby window and a "Trusted" Accessory window
if (!("DRDoubleSDK" in window)) {
console.error("window.DRDoubleSDK not found. This is required.");
}
function q(selector) {
return document.querySelector(selector);
}
DRDoubleSDK.on("event", (message) => {
// Event messages include: { class: "DRNetwork", key: "info", data: {...} }
switch (message.class + "." + message.key) {
// DRNetwork
case "DRNetwork.info": {
q("#wifi_ssid").innerText = (message.data.connection == "connected" && message.data.ssid) ? message.data.ssid : "Unknown";
q("#wifi_ip").innerText = message.data.internalIp;
break;
}
}
});
function onConnect() {
if (DRDoubleSDK.isConnected()) {
DRDoubleSDK.resetWatchdog();
// Subscribe to events that you will process. You can subscribe to more events at any time.
DRDoubleSDK.sendCommand("events.subscribe", {
events: [
"DRBase.status",
"DRNetwork.info",
]
});
// Send commands any time – here, we're requesting initial info to show
DRDoubleSDK.sendCommand("network.requestInfo");
DRDoubleSDK.sendCommand("base.requestStatus");
// Turn on the screen, but allow the screensaver to kick in later
DRDoubleSDK.sendCommand("screensaver.nudge");
} else {
window.setTimeout(onConnect, 100);
}
}
window.onload = () => {
// REQUIRED: Tell d3-api that we're still running ok (faster than every 3000 ms) or the page will be reloaded.
window.setInterval(() => {
DRDoubleSDK.resetWatchdog();
}, 2000);
// DRDoubleSDK
onConnect();
DRDoubleSDK.on("connect", () => {
onConnect();
});
};