view service/wallscreen/websocket.js @ 981:d9bbbd8d86f6

arduinoNode: use -v for logging; support a PUT with subj+pred in query, obj in body Ignore-this: 744c3c7d95655430b8ec547e56f6b4bc darcs-hash:20150514082612-312f9-f77a103ef67321aa5a0ffd7991b92befd5dac37f
author drewp <drewp@bigasterisk.com>
date Thu, 14 May 2015 01:26:12 -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();
}