Try fixing ws
This commit is contained in:
parent
088d78d762
commit
ac0b7afc1a
1 changed files with 30 additions and 29 deletions
|
@ -35,37 +35,38 @@ function EventReceiver(websocket, poller, channels, last_msg, onmessage) {
|
||||||
|
|
||||||
this.onwsclose = null;
|
this.onwsclose = null;
|
||||||
if (window.WebSocket) {
|
if (window.WebSocket) {
|
||||||
this.websocket = new WebSocket(websocket);
|
function connect() {
|
||||||
var timeout = setTimeout(function () {
|
this.websocket = new WebSocket(websocket);
|
||||||
receiver.websocket.close();
|
var timeout = setTimeout(function () {
|
||||||
receiver.websocket = null;
|
receiver.websocket.close();
|
||||||
init_poll();
|
receiver.websocket = null;
|
||||||
}, 2000);
|
init_poll();
|
||||||
this.websocket.onopen = function (event) {
|
}, 2000);
|
||||||
clearTimeout(timeout);
|
this.websocket.onopen = function (event) {
|
||||||
this.send(JSON.stringify({
|
clearTimeout(timeout);
|
||||||
command: 'start-msg',
|
this.send(JSON.stringify({
|
||||||
start: last_msg
|
command: 'start-msg',
|
||||||
}));
|
start: last_msg
|
||||||
this.send(JSON.stringify({
|
}));
|
||||||
command: 'set-filter',
|
this.send(JSON.stringify({
|
||||||
filter: channels
|
command: 'set-filter',
|
||||||
}));
|
filter: channels
|
||||||
};
|
}));
|
||||||
this.websocket.onmessage = function (event) {
|
};
|
||||||
var data = JSON.parse(event.data);
|
this.websocket.onmessage = function (event) {
|
||||||
receiver.onmessage(data.message);
|
var data = JSON.parse(event.data);
|
||||||
receiver.last_msg = data.id;
|
receiver.onmessage(data.message);
|
||||||
};
|
receiver.last_msg = data.id;
|
||||||
this.websocket.onclose = function (event) {
|
};
|
||||||
if (event.code != 1000 && receiver.onwsclose !== null)
|
this.websocket.onclose = function (event) {
|
||||||
receiver.onwsclose(event);
|
if (event.code != 1000 && receiver.onwsclose !== null)
|
||||||
if (event.code == 1006) {
|
receiver.onwsclose(event);
|
||||||
setTimeout(function() {
|
if (event.code == 1006) {
|
||||||
connect();
|
setTimeout(connect, 1000);
|
||||||
}, 1000);
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
connect();
|
||||||
} else {
|
} else {
|
||||||
this.websocket = null;
|
this.websocket = null;
|
||||||
init_poll();
|
init_poll();
|
||||||
|
|
Loading…
Reference in a new issue