mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-11-20 12:15:51 +00:00
JS: Prevent duplicate WebSocket objects.
This commit is contained in:
@@ -395,11 +395,13 @@ Remote.prototype.ledger_hash = function () {
|
|||||||
|
|
||||||
// Stop from open state.
|
// Stop from open state.
|
||||||
Remote.prototype._connect_stop = function () {
|
Remote.prototype._connect_stop = function () {
|
||||||
|
if (this.ws) {
|
||||||
delete this.ws.onerror;
|
delete this.ws.onerror;
|
||||||
delete this.ws.onclose;
|
delete this.ws.onclose;
|
||||||
|
|
||||||
this.ws.terminate();
|
this.ws.close();
|
||||||
delete this.ws;
|
delete this.ws;
|
||||||
|
}
|
||||||
|
|
||||||
this._set_state('offline');
|
this._set_state('offline');
|
||||||
};
|
};
|
||||||
@@ -458,6 +460,12 @@ Remote.prototype._connect_start = function () {
|
|||||||
|
|
||||||
if (this.trace) console.log("remote: connect: %s", url);
|
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 WebSocket = require('ws');
|
||||||
var ws = this.ws = new WebSocket(url);
|
var ws = this.ws = new WebSocket(url);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user