From 1bac4cb1f2ce94bd60eab894b459b13485a8d38f Mon Sep 17 00:00:00 2001 From: Stefan Thomas Date: Wed, 13 Feb 2013 09:53:09 +0100 Subject: [PATCH 1/2] JS: Prevent duplicate WebSocket objects. --- src/js/remote.js | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/js/remote.js b/src/js/remote.js index e1fd61c8d..47e468835 100644 --- a/src/js/remote.js +++ b/src/js/remote.js @@ -395,11 +395,13 @@ Remote.prototype.ledger_hash = function () { // Stop from open state. Remote.prototype._connect_stop = function () { - delete this.ws.onerror; - delete this.ws.onclose; + if (this.ws) { + delete this.ws.onerror; + delete this.ws.onclose; - this.ws.terminate(); - delete this.ws; + this.ws.close(); + delete this.ws; + } this._set_state('offline'); }; @@ -458,6 +460,12 @@ Remote.prototype._connect_start = function () { if (this.trace) console.log("remote: connect: %s", url); + // There should not be an active connection at this point, but if there is + // we will shut it down so we don't end up with a duplicate. + if (this.ws) { + this._connect_stop(); + } + var WebSocket = require('ws'); var ws = this.ws = new WebSocket(url); From 85f9f6786560d7b31a2559ce4dd8fa6b903ff297 Mon Sep 17 00:00:00 2001 From: Stefan Thomas Date: Wed, 13 Feb 2013 12:57:59 +0100 Subject: [PATCH 2/2] JS: Fix Transaction#paths. --- src/js/transaction.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/js/transaction.js b/src/js/transaction.js index a6e0621ed..77b8841d4 100644 --- a/src/js/transaction.js +++ b/src/js/transaction.js @@ -401,8 +401,8 @@ Transaction.prototype.destination_tag = function (tag) { Transaction._path_rewrite = function (path) { var path_new = []; - for (var index in path) { - var node = path[index]; + for (var i = 0, l = path.length; i < l; i++) { + var node = path[i]; var node_new = {}; if ('account' in node) @@ -421,7 +421,7 @@ Transaction._path_rewrite = function (path) { } Transaction.prototype.path_add = function (path) { - this.tx_json.Paths = this.tx_json.Paths || [] + this.tx_json.Paths = this.tx_json.Paths || []; this.tx_json.Paths.push(Transaction._path_rewrite(path)); return this; @@ -430,8 +430,8 @@ Transaction.prototype.path_add = function (path) { // --> paths: undefined or array of path // A path is an array of objects containing some combination of: account, currency, issuer Transaction.prototype.paths = function (paths) { - for (var index in paths) { - this.path_add(paths[index]); + for (var i = 0, l = paths.length; i < l; i++) { + this.path_add(paths[i]); } return this;