61
|
1 // from the light9/rdfdb one
|
|
2
|
|
3 function reconnectingWebSocket(url, onMessage) {
|
|
4 var pong = 0;
|
|
5 function connect() {
|
|
6 var ws = new WebSocket(url);
|
|
7
|
|
8 ws.onopen = function() { $("#status").text(""); };
|
|
9 ws.onerror = function(e) { $("#status").text("error: "+e); };
|
|
10 ws.onclose = function() {
|
|
11 pong = 1 - pong;
|
|
12 $("#status").text("disconnected (retrying "+(pong ? "😼":"😺")+")");
|
|
13 setTimeout(connect, 2000);
|
|
14 };
|
|
15 ws.onmessage = function (evt) {
|
|
16 onMessage(JSON.parse(evt.data));
|
|
17 };
|
|
18 }
|
|
19 connect();
|
|
20 }
|