view service/wallscreen/websocket.js @ 1147:ef494fe0499f

forgot devices_shared.py Ignore-this: 210e7777d9d4d11f148bb7e63f5de65a darcs-hash:8dd34afc9d00fe796f94da254519e22ca1fa7d03
author drewp <drewp@bigasterisk.com>
date Wed, 04 Apr 2018 14:58:27 -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();
}