view service/wallscreen/websocket.js @ 1136:1e43ec4a5f23

build and import updates for rdfdb, etc Ignore-this: 233cb2b31f03be51695f0fff40eecca7 darcs-hash:92c1c526292f9013ad41d2e3b6d11add8fff02ae
author drewp <drewp@bigasterisk.com>
date Mon, 19 Feb 2018 04:21:28 -0800
parents a99b4d5afb83
children
line wrap: on
line source

// from the light9/rdfdb one

function reconnectingWebSocket(url, onMessage) {
    var pong = 0;
    function connect() {
        var ws = new WebSocket(url);
        
        ws.onopen = function() {   $("#status").text(""); };
        ws.onerror = function(e) { $("#status").text("error: "+e); };
        ws.onclose = function() {  
            pong = 1 - pong;
            $("#status").text("disconnected (retrying "+(pong ? "😼":"😺")+")"); 
            setTimeout(connect, 2000);
        };
        ws.onmessage = function (evt) {
            onMessage(JSON.parse(evt.data));
        };
    }
    connect();
}