js: Add close() method to close WebSocket without reconnecting
This commit is contained in:
parent
43316babcd
commit
8d3fd46808
@ -119,6 +119,11 @@ Mopidy.prototype._resetBackoffDelay = function () {
|
||||
this._backoffDelay = this._settings.backoffDelayMin;
|
||||
};
|
||||
|
||||
Mopidy.prototype.close = function () {
|
||||
this.off("state:offline", this._reconnect);
|
||||
this._webSocket.close();
|
||||
};
|
||||
|
||||
Mopidy.prototype._handleWebSocketError = function (error) {
|
||||
this._console.warn("WebSocket error:", error.stack || error);
|
||||
};
|
||||
|
||||
@ -254,6 +254,23 @@ buster.testCase("Mopidy", {
|
||||
}
|
||||
},
|
||||
|
||||
"close": {
|
||||
"unregisters reconnection hooks": function () {
|
||||
this.stub(this.mopidy, "off");
|
||||
|
||||
this.mopidy.close();
|
||||
|
||||
assert.calledOnceWith(
|
||||
this.mopidy.off, "state:offline", this.mopidy._reconnect);
|
||||
},
|
||||
|
||||
"closes the WebSocket": function () {
|
||||
this.mopidy.close();
|
||||
|
||||
assert.calledOnceWith(this.mopidy._webSocket.close);
|
||||
}
|
||||
},
|
||||
|
||||
"._handleWebSocketError": {
|
||||
"is called on 'websocket:error' event": function () {
|
||||
var error = {};
|
||||
|
||||
@ -1028,6 +1028,11 @@ Mopidy.prototype._resetBackoffDelay = function () {
|
||||
this._backoffDelay = this._settings.backoffDelayMin;
|
||||
};
|
||||
|
||||
Mopidy.prototype.close = function () {
|
||||
this.off("state:offline", this._reconnect);
|
||||
this._webSocket.close();
|
||||
};
|
||||
|
||||
Mopidy.prototype._handleWebSocketError = function (error) {
|
||||
this._console.warn("WebSocket error:", error.stack || error);
|
||||
};
|
||||
|
||||
2
mopidy/frontends/http/data/mopidy.min.js
vendored
2
mopidy/frontends/http/data/mopidy.min.js
vendored
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user