Mercurial > code > home > repos > homeauto
view service/wallscreen/websocket.js @ 82:d288bc1174d4
audio input levels to graphite
Ignore-this: b1422609f3bf51778b8b2284ca914916
author | drewp@bigasterisk.com |
---|---|
date | Fri, 02 Aug 2013 07:55:45 -0700 |
parents | 1afb0564636d |
children |
line wrap: on
line source
// 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(); }