view static/websocket.js @ 1080:dfb23566a91f

effecteval don't stop if a curve has 0 pts Ignore-this: 919eace9fc1a927890c08df3f49a41ae
author Drew Perttula <drewp@bigasterisk.com>
date Tue, 03 Jun 2014 08:25:38 +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();
}