diff --git a/lib/spotify.js b/lib/spotify.js index a051e03..f2f1a02 100644 --- a/lib/spotify.js +++ b/lib/spotify.js @@ -436,6 +436,8 @@ Spotify.prototype._onmessagecommand = function (command, args) { } } else if ('login_complete' == command) { // ignore... + } else if ('disconnect' == command) { + this.disconnect(); } else { // unhandled message console.error(command, args); @@ -647,10 +649,10 @@ Spotify.prototype.disconnect = function () { this.connected = false; clearInterval(this._heartbeatId); this._heartbeatId = null; - if (this.ws) { - this.ws.close(); - this.ws = null; + if (this.ws && this.ws.readyState == 1) { + this.ws.close(); } + this.ws = null; }; /**