Mercurial > code > home > repos > light9
view static/websocket.js @ 1187:102a456be7db
refactor EE moving towards the ability to re-bump existing curves
Ignore-this: 3a488225654c1cc8695b5466b2cdbc1c
author | drewp@bigasterisk.com |
---|---|
date | Sun, 15 Jun 2014 17:31:29 +0000 |
parents | a4632a7b2e17 |
children |
line wrap: on
line source
function reconnectingWebSocket(url, onMessage) { var pong = 0; function connect() { var ws = new WebSocket(url); ws.onopen = function() { $("#status").text("connected"); }; ws.onerror = function(e) { $("#status").text("error: "+e); }; ws.onclose = function() { pong = 1 - pong; $("#status").text("disconnected (retrying "+(pong ? "😼":"😺")+")"); // this should be under a requestAnimationFrame to // save resources setTimeout(connect, 2000); }; ws.onmessage = function (evt) { onMessage(JSON.parse(evt.data)); }; } connect(); }