diff service/wallscreen/websocket.js @ 61:1afb0564636d

use websockets for temperature update Ignore-this: 558ad53cf5b4b0c013041db555fbb458
author drewp@bigasterisk.com
date Sun, 10 Feb 2013 13:41:35 -0800
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/service/wallscreen/websocket.js	Sun Feb 10 13:41:35 2013 -0800
@@ -0,0 +1,20 @@
+// from the light9/rdfdb one
+
+function reconnectingWebSocket(url, onMessage) {
+    var pong = 0;
+    function connect() {
+        var ws = new WebSocket(url);
+        
+        ws.onopen = function() {   $("#status").text(""); };
+        ws.onerror = function(e) { $("#status").text("error: "+e); };
+        ws.onclose = function() {  
+            pong = 1 - pong;
+            $("#status").text("disconnected (retrying "+(pong ? "😼":"😺")+")"); 
+            setTimeout(connect, 2000);
+        };
+        ws.onmessage = function (evt) {
+            onMessage(JSON.parse(evt.data));
+        };
+    }
+    connect();
+}