JS: Prevent duplicate WebSocket objects.

This commit is contained in:
Stefan Thomas
2013-02-13 09:53:09 +01:00
parent 5596427e30
commit a86584652f

View File

@@ -395,11 +395,13 @@ Remote.prototype.ledger_hash = function () {
// Stop from open state.
Remote.prototype._connect_stop = function () {
if (this.ws) {
delete this.ws.onerror;
delete this.ws.onclose;
this.ws.terminate();
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);