view service/wallscreen/websocket.js @ 462:7ec5945752b7

some old Measurement and Locator edits Ignore-this: 188ecdf63f49b7a58f99a5961c6c23a6
author drewp@bigasterisk.com
date Sat, 20 Apr 2019 23:35:46 -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();
}