view service/wallscreen/websocket.js @ 481:f08a0ef88adc

update rdfdb for inGraph bug Ignore-this: aa9dd5b5025f7925530f15942b0043e7
author drewp@bigasterisk.com
date Sat, 20 Apr 2019 23:59:45 -0700
parents 1afb0564636d
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();
}