WebSocketResource exposes socket.close()

Allows for simplification of the keepalive construct.
This commit is contained in:
lilia 2015-07-27 18:51:45 -07:00
parent 98edd3939b
commit 8170a7baae
5 changed files with 16 additions and 10 deletions

View file

@ -38565,6 +38565,10 @@ TextSecureWebSocket = function (url, opts) {
return new OutgoingWebSocketRequest(options, socket);
};
this.close = function() {
socket.close(3000);
};
socket.onmessage = function(socketMessage) {
var blob = socketMessage.data;
var reader = new FileReader();
@ -38621,10 +38625,9 @@ TextSecureWebSocket = function (url, opts) {
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
function KeepAlive(websocketResource, socket) {
function KeepAlive(websocketResource) {
if (websocketResource instanceof WebSocketResource) {
this.wsr = websocketResource;
this.socket = socket;
this.reset();
} else {
throw new TypeError('KeepAlive expected a WebSocketResource');
@ -38637,7 +38640,7 @@ KeepAlive.prototype = {
clearTimeout(this.keepAliveTimer);
clearTimeout(this.disconnectTimer);
this.keepAliveTimer = setTimeout(function() {
this.disconnectTimer = setTimeout(this.socket.close, 10000);
this.disconnectTimer = setTimeout(this.wsr.close, 5000);
this.wsr.sendRequest({
verb: 'GET',
path: '/v1/keepalive',
@ -39393,7 +39396,7 @@ TextSecureServer = function () {
console.log('Unknown websocket message', request.path);
}
});
new KeepAlive(wsr, socket);
new KeepAlive(wsr);
});
}).then(function() {
return generateKeys(100, progressCallback);
@ -39541,7 +39544,7 @@ function generateKeys(count, progressCallback) {
}
this.wsr = new WebSocketResource(this.socket, this.handleRequest.bind(this));
this.keepalive = new KeepAlive(this.wsr, this.socket);
this.keepalive = new KeepAlive(this.wsr);
},
handleRequest: function(request) {

View file

@ -73,7 +73,7 @@
console.log('Unknown websocket message', request.path);
}
});
new KeepAlive(wsr, socket);
new KeepAlive(wsr);
});
}).then(function() {
return generateKeys(100, progressCallback);

View file

@ -14,10 +14,9 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
function KeepAlive(websocketResource, socket) {
function KeepAlive(websocketResource) {
if (websocketResource instanceof WebSocketResource) {
this.wsr = websocketResource;
this.socket = socket;
this.reset();
} else {
throw new TypeError('KeepAlive expected a WebSocketResource');
@ -30,7 +29,7 @@ KeepAlive.prototype = {
clearTimeout(this.keepAliveTimer);
clearTimeout(this.disconnectTimer);
this.keepAliveTimer = setTimeout(function() {
this.disconnectTimer = setTimeout(this.socket.close, 10000);
this.disconnectTimer = setTimeout(this.wsr.close, 5000);
this.wsr.sendRequest({
verb: 'GET',
path: '/v1/keepalive',

View file

@ -45,7 +45,7 @@
}
this.wsr = new WebSocketResource(this.socket, this.handleRequest.bind(this));
this.keepalive = new KeepAlive(this.wsr, this.socket);
this.keepalive = new KeepAlive(this.wsr);
},
handleRequest: function(request) {

View file

@ -97,6 +97,10 @@
return new OutgoingWebSocketRequest(options, socket);
};
this.close = function() {
socket.close(3000);
};
socket.onmessage = function(socketMessage) {
var blob = socketMessage.data;
var reader = new FileReader();