diff light9/web/websocket.js @ 1217:e703b3434dbd

websocket and web cleanup Ignore-this: ac6bd0444bc03ee79ce71c4aa7740bc0
author Drew Perttula <drewp@bigasterisk.com>
date Mon, 08 Jun 2015 02:08:25 +0000
parents 95dfce5c12ce
children f001d689b3e2
line wrap: on
line diff
--- a/light9/web/websocket.js	Mon Jun 08 00:38:49 2015 +0000
+++ b/light9/web/websocket.js	Mon Jun 08 02:08:25 2015 +0000
@@ -1,7 +1,17 @@
+/*
+  url is now relative to the window location
+*/
 function reconnectingWebSocket(url, onMessage) {
     var pong = 0;
+    
+    var fullUrl = (
+        "ws://"
+            + window.location.host
+            + window.location.pathname
+            + (window.location.pathname.match(/\/$/) ? "" : "/")
+            + url);
     function connect() {
-        var ws = new WebSocket(url);
+        var ws = new WebSocket(fullUrl);
         
         ws.onopen = function() {   $("#status").text("connected"); };
         ws.onerror = function(e) { $("#status").text("error: "+e); };
@@ -17,4 +27,4 @@
         };
     }
     connect();
-}
\ No newline at end of file
+}