Mercurial > code > home > repos > homeauto
view service/wallscreen/websocket.js @ 1259:672a3d830e7f
arduinoNode: build updates, stats support, etc
Ignore-this: 39386eb7644e3cf522e0f72a874eadba
darcs-hash:b6fa9fbda226917dd3b94d8a87556c4cd6d51180
author | drewp <drewp@bigasterisk.com> |
---|---|
date | Sat, 20 Apr 2019 23:28:29 -0700 |
parents | a99b4d5afb83 |
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(); }