view static/websocket.js @ 1073:52f049d85f96

less CC crashing. curve points are stored in their own n3 files. fix curve row height edge cases. Ignore-this: 7bd8e0c82d4106d53c24d67b981baf60
author Drew Perttula <drewp@bigasterisk.com>
date Tue, 03 Jun 2014 05:09:41 +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();
}