X-Git-Url: http://www.average.org/gitweb/?a=blobdiff_plain;f=webdemo%2Findex.html;h=20beb34c86f0c9a1239ecf993252b0b0ea7ec080;hb=aeb5721c171af9996ede4b5904d552170b4fe16c;hp=030830240d1e1ef585ee6b24c62490f5f105099b;hpb=db4010362f00b1af85d40a34dae1a031625b7ef1;p=loctrkd.git diff --git a/webdemo/index.html b/webdemo/index.html index 0308302..20beb34 100644 --- a/webdemo/index.html +++ b/webdemo/index.html @@ -10,10 +10,11 @@ const urlParams = new URLSearchParams(window.location.search); const qimei = urlParams.get("imei"); - const ourl = new URL(window.location); - const wsproto = ourl.protocol === "https" ? "wss" : "ws"; - const wshost = ourl.hostname ? ourl.hostname : "localhost"; - const wsport = ourl.port ? ourl.port : 5049; + const wsproto = window.location.protocol === "https" ? "wss" : "ws"; + const wshost = window.location.hostname ? window.location.hostname + : "localhost"; + const wsport = window.location.port ? window.location.port : 5049; + const limei = window.location.pathname.substring(1) const imeis = new Set(); const locations = new Array(); @@ -43,9 +44,12 @@ send = document.getElementById("send"); clear = document.getElementById("clear"); subslist = document.getElementById("subslist"); + devstatus = document.getElementById("devstatus"); tstamp = document.getElementById("tstamp"); if (qimei) { imei.value = qimei; + } else if (limei) { + imei.value = limei; } open_ws(); } @@ -134,6 +138,10 @@ markers.addMarker(new OpenLayers.Marker(lonLat, icon)); map.setCenter(lonLat, 14); } + function display_status(msg) { + console.log("status " + JSON.stringify(msg)); + devstatus.innerHTML = "BAT: " + msg.battery; + } function open_ws() { wsurl = new URL("ws://localhost/"); @@ -153,11 +161,18 @@ imei.disabled = false; send.disabled = false; clear.disabled = false; + locations.splice(0); sendIMEI(); } function ws_onmessage(event) { console.log("message " + event.data); - set_marker(JSON.parse(event.data)); + msg = JSON.parse(event.data); + if (msg.type === "location") { + set_marker(msg); + } else if (msg.type === "status") { + display_status(msg); + } + } function ws_onerror(event) { console.log("error " + event); @@ -204,8 +219,9 @@ - -
+ +
@@ -214,9 +230,15 @@ -
-
-
+
+
+
+ |
+ |
+ | +