From d9fe783488465b5ab6088026ff8531c0e54d7549 Mon Sep 17 00:00:00 2001 From: lilia Date: Mon, 27 Jul 2015 19:11:04 -0700 Subject: [PATCH] Accept close code/message via websocket/resources --- js/libtextsecure.js | 20 +++++++++++++------- libtextsecure/account_manager.js | 2 +- libtextsecure/keepalive.js | 4 +++- libtextsecure/websocket-resources.js | 5 +++-- libtextsecure/websocket.js | 9 ++++++--- 5 files changed, 26 insertions(+), 14 deletions(-) diff --git a/js/libtextsecure.js b/js/libtextsecure.js index 9eeed729..aee402d6 100644 --- a/js/libtextsecure.js +++ b/js/libtextsecure.js @@ -38401,8 +38401,8 @@ axolotlInternal.RecipientRecord = function() { /* * var socket = TextSecureWebSocket(url); * - * Returns an adamantium-reinforced super socket, capable of sending - * app-level keep alives and automatically reconnecting. + * Returns an adamantium-reinforced super socket, capable of + * automatically reconnecting. * */ @@ -38421,7 +38421,10 @@ TextSecureWebSocket = function (url, opts) { onclose : function() {}, onerror : function() {}, getStatus : function() { return socket.readyState; }, - close : function() { calledClose = true; socket.close(); } + close : function(code, reason) { + calledClose = true; + socket.close(code, reason); + } }; var error; @@ -38565,8 +38568,9 @@ TextSecureWebSocket = function (url, opts) { return new OutgoingWebSocketRequest(options, socket); }; - this.close = function() { - socket.close(3000); + this.close = function(code, reason) { + if (!code) { code = 3000; } + socket.close(code, reason); }; socket.onmessage = function(socketMessage) { @@ -38640,7 +38644,9 @@ KeepAlive.prototype = { clearTimeout(this.keepAliveTimer); clearTimeout(this.disconnectTimer); this.keepAliveTimer = setTimeout(function() { - this.disconnectTimer = setTimeout(this.wsr.close, 5000); + this.disconnectTimer = setTimeout(function() { + this.wsr.close(3001, 'No response to keepalive request'); + }.bind(this), 5000); this.wsr.sendRequest({ verb: 'GET', path: '/v1/keepalive', @@ -39378,7 +39384,7 @@ TextSecureServer = function () { } else if (request.path == "/v1/message" && request.verb == "PUT") { var envelope = textsecure.protobuf.ProvisionEnvelope.decode(request.body, 'binary'); request.respond(200, 'OK'); - socket.close(); + wsr.close(); resolve(cryptoInfo.decryptAndHandleDeviceInit(envelope).then(function(provisionMessage) { return confirmNumber(provisionMessage.number).then(function(deviceName) { if (typeof deviceName !== 'string' || deviceName.length == 0) { diff --git a/libtextsecure/account_manager.js b/libtextsecure/account_manager.js index b07a17df..b6bea115 100644 --- a/libtextsecure/account_manager.js +++ b/libtextsecure/account_manager.js @@ -55,7 +55,7 @@ } else if (request.path == "/v1/message" && request.verb == "PUT") { var envelope = textsecure.protobuf.ProvisionEnvelope.decode(request.body, 'binary'); request.respond(200, 'OK'); - socket.close(); + wsr.close(); resolve(cryptoInfo.decryptAndHandleDeviceInit(envelope).then(function(provisionMessage) { return confirmNumber(provisionMessage.number).then(function(deviceName) { if (typeof deviceName !== 'string' || deviceName.length == 0) { diff --git a/libtextsecure/keepalive.js b/libtextsecure/keepalive.js index dba193db..039374c6 100644 --- a/libtextsecure/keepalive.js +++ b/libtextsecure/keepalive.js @@ -29,7 +29,9 @@ KeepAlive.prototype = { clearTimeout(this.keepAliveTimer); clearTimeout(this.disconnectTimer); this.keepAliveTimer = setTimeout(function() { - this.disconnectTimer = setTimeout(this.wsr.close, 5000); + this.disconnectTimer = setTimeout(function() { + this.wsr.close(3001, 'No response to keepalive request'); + }.bind(this), 5000); this.wsr.sendRequest({ verb: 'GET', path: '/v1/keepalive', diff --git a/libtextsecure/websocket-resources.js b/libtextsecure/websocket-resources.js index 808a30e0..11b1ae64 100644 --- a/libtextsecure/websocket-resources.js +++ b/libtextsecure/websocket-resources.js @@ -97,8 +97,9 @@ return new OutgoingWebSocketRequest(options, socket); }; - this.close = function() { - socket.close(3000); + this.close = function(code, reason) { + if (!code) { code = 3000; } + socket.close(code, reason); }; socket.onmessage = function(socketMessage) { diff --git a/libtextsecure/websocket.js b/libtextsecure/websocket.js index 8dbb5442..88c2efe1 100644 --- a/libtextsecure/websocket.js +++ b/libtextsecure/websocket.js @@ -17,8 +17,8 @@ /* * var socket = TextSecureWebSocket(url); * - * Returns an adamantium-reinforced super socket, capable of sending - * app-level keep alives and automatically reconnecting. + * Returns an adamantium-reinforced super socket, capable of + * automatically reconnecting. * */ @@ -37,7 +37,10 @@ TextSecureWebSocket = function (url, opts) { onclose : function() {}, onerror : function() {}, getStatus : function() { return socket.readyState; }, - close : function() { calledClose = true; socket.close(); } + close : function(code, reason) { + calledClose = true; + socket.close(code, reason); + } }; var error;