Mercurial > code > home > repos > light9
view static/websocket.js @ 1120:f36fd5bc44e5
fix effecteval output code
Ignore-this: 279d8a0be31656be42eaf0e2e6a44a74
author | Drew Perttula <drewp@bigasterisk.com> |
---|---|
date | Fri, 13 Jun 2014 07:23:39 +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(); }