From 30cb9117abd5b14093f01a114e6f13081c23c184 Mon Sep 17 00:00:00 2001 From: Scott Ysebert Date: Mon, 27 Jan 2014 22:48:09 -0800 Subject: [PATCH] handle the "disconnect" command gracefully --- lib/spotify.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) 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; }; /**