view service/wallscreen/websocket.js @ 1153:e4f49cd9dda3

add :pointsAtLeastEvery control Ignore-this: 9d0236b56b2a7592211ca68b87b4a5d1 darcs-hash:76e4d358cb6b039351c9b6f8e3bb825aaaefcc57
author drewp <drewp@bigasterisk.com>
date Sun, 15 Apr 2018 04:41:00 -0700
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();
}