Files @ 19e8a57b060e
Branch filter:

Location: light9/static/websocket.js

drewp@bigasterisk.com
checkpoint show data
Ignore-this: 35532ca55f44d495a30d808ac106db73
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();
}