mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-11-20 04:05:52 +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.
|
||||
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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user