server/js: also allow running on localhost
authorMatthew Waters <matthew@centricular.com>
Wed, 22 Nov 2017 13:21:36 +0000 (00:21 +1100)
committerMatthew Waters <matthew@centricular.com>
Wed, 22 Nov 2017 13:29:39 +0000 (00:29 +1100)
webrtc/sendrecv/js/webrtc.js

index 31116c0..b95df54 100644 (file)
@@ -137,7 +137,15 @@ function websocketServerConnect() {
     }
     peer_id = getOurId();
     setStatus("Connecting to server");
-    ws_conn = new WebSocket('wss://' + window.location.hostname + ':8443');
+    loc = null;
+    if (window.location.protocol.startsWith ("file")) {
+        loc = "127.0.0.1";
+    } else if (window.location.protocol.startsWith ("http")) {
+        loc = window.location.hostname;
+    } else {
+        throw new Error ("Don't know how to connect to the signalling server with uri" + window.location);
+    }
+    ws_conn = new WebSocket('wss://' + loc + ':8443');
     /* When connected, immediately register with the server */
     ws_conn.addEventListener('open', (event) => {
         document.getElementById("peer-id").textContent = peer_id;