Mercurial > code > home > repos > light9
view static/websocket.js @ 1043:aa45e5379c5a
effecteval improvements. displays current song+effect tree
Ignore-this: 94a007b1206c45483d74878fb35248d
author | Drew Perttula <drewp@bigasterisk.com> |
---|---|
date | Wed, 28 May 2014 05:57:08 +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(); }