]> www.average.org Git - loctrkd.git/commitdiff
Webdemo use its url as the base for ws url
authorEugene Crosser <crosser@average.org>
Fri, 6 May 2022 15:24:48 +0000 (17:24 +0200)
committerEugene Crosser <crosser@average.org>
Fri, 6 May 2022 15:24:48 +0000 (17:24 +0200)
webdemo/index.html

index ad1152c89b7506f590f49e61609c23a0bf03aebd..f356f96339b3fc784ee38e2d29710cc1813b0831 100644 (file)
@@ -8,6 +8,10 @@
        <script type="text/javascript">
                const urlParams = new URLSearchParams(window.location.search);
                const qimei = urlParams.get("imei");
+               const wsproto = window.protocol === "https" ? "wss" : "ws";
+               const wshost = window.hostname ? window.hostname : "localhost";
+               const wsport = window.port ? window.port : 5049;
+
                var sts;
                var ws;
                var map;
                }
 
                function open_ws() {
-                       ws = new WebSocket("ws://localhost:5049");
+                       wsurl = new URL("ws://localhost/");
+                       wsurl.protocol = wsproto
+                       wsurl.hostname = wshost
+                       wsurl.port = wsport
+                       console.log("wsurl is " + wsurl)
+                       ws = new WebSocket(wsurl);
                        ws.onopen = ws_onopen;
                        ws.onmessage = ws_onmessage;
                        ws.onerror = ws_onerror;