Keepalive endpoint
This commit is contained in:
parent
4f97f8c1e4
commit
2209407d5e
1 changed files with 13 additions and 4 deletions
|
@ -25,7 +25,10 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
window.textsecure.websocket = function (url) {
|
window.textsecure.websocket = function (url) {
|
||||||
var socketWrapper = { onmessage: function() {}, ondisconnect: function() {} };
|
var socketWrapper = {
|
||||||
|
onmessage : function() {},
|
||||||
|
ondisconnect : function() {},
|
||||||
|
};
|
||||||
var socket;
|
var socket;
|
||||||
var keepAliveTimer;
|
var keepAliveTimer;
|
||||||
var reconnectSemaphore = 0;
|
var reconnectSemaphore = 0;
|
||||||
|
@ -34,7 +37,13 @@
|
||||||
function resetKeepAliveTimer() {
|
function resetKeepAliveTimer() {
|
||||||
clearTimeout(keepAliveTimer);
|
clearTimeout(keepAliveTimer);
|
||||||
keepAliveTimer = setTimeout(function() {
|
keepAliveTimer = setTimeout(function() {
|
||||||
socket.send(JSON.stringify({type: 1, id: 0}));
|
socket.send(
|
||||||
|
new textsecure.protobuf.WebSocketMessage({
|
||||||
|
type: textsecure.protobuf.WebSocketMessage.Type.REQUEST,
|
||||||
|
request: { verb: 'GET', path: '/v1/keepalive' }
|
||||||
|
}).encode().toArrayBuffer()
|
||||||
|
);
|
||||||
|
|
||||||
resetKeepAliveTimer();
|
resetKeepAliveTimer();
|
||||||
}, 15000);
|
}, 15000);
|
||||||
};
|
};
|
||||||
|
@ -45,7 +54,7 @@
|
||||||
socketWrapper.ondisconnect(e);
|
socketWrapper.ondisconnect(e);
|
||||||
};
|
};
|
||||||
|
|
||||||
var connect = function() {
|
function connect() {
|
||||||
clearTimeout(keepAliveTimer);
|
clearTimeout(keepAliveTimer);
|
||||||
if (++reconnectSemaphore <= 0) { return; }
|
if (++reconnectSemaphore <= 0) { return; }
|
||||||
|
|
||||||
|
@ -64,7 +73,7 @@
|
||||||
socketWrapper.send = function(msg) {
|
socketWrapper.send = function(msg) {
|
||||||
socket.send(msg);
|
socket.send(msg);
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
connect();
|
connect();
|
||||||
return socketWrapper;
|
return socketWrapper;
|
||||||
|
|
Loading…
Reference in a new issue