Mercurial > code > home > repos > homeauto
view service/wallscreen/websocket.js @ 114:4cd065b97fa1
bugs in async http client. move trig helpers to rdflibtrig, which can work with rdflib 4
Ignore-this: 81dc30256f5d2658e53fce60abea66db
author | drewp@bigasterisk.com |
---|---|
date | Tue, 10 Sep 2013 00:38:52 -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(); }