From: Mike Frysinger Date: Sun, 1 Sep 2013 20:37:54 +0000 (-0400) Subject: auto-reconnect when we get an error X-Git-Tag: v3.0 X-Git-Url: https://git.wh0rd.org/?a=commitdiff_plain;h=8d64e317943a529b96a15d4d12f0af368a92e043;p=chrome-ext%2Fmusic-player-client.git auto-reconnect when we get an error --- diff --git a/js/mpc.js b/js/mpc.js index 7fc7439..1e3390b 100644 --- a/js/mpc.js +++ b/js/mpc.js @@ -28,6 +28,12 @@ Mpc.prototype.send = function(msg) { this._queue.push(msg); this._socket.send(msg, function(x) { _this.log(0x1, 'send: ' + msg + ':', x); + if (x.bytesWritten < 0) { + _this.log(0x1, 'reconnecting...'); + _this._socket.reconnect(); + _this.queue = [msg]; + _this._socket.send(msg); + } }); } diff --git a/main.js b/main.js index 26d0bc7..5b05cee 100644 --- a/main.js +++ b/main.js @@ -14,6 +14,10 @@ TcpClientSender.prototype.send = function(data, cb) { TcpClientSender.prototype.poll = function() { this.tcpclient.poll(); } +TcpClientSender.prototype.reconnect = function() { + this.tcpclient.disconnect(); + this.tcpclient.connect(); +} function tramp_mpc_recv(data) { mpc.recv(data); diff --git a/manifest.json b/manifest.json index 605208f..0e1073d 100644 --- a/manifest.json +++ b/manifest.json @@ -2,7 +2,7 @@ "manifest_version": 2, "minimum_chrome_version": "24", "name": "Music Player Client", - "version": "2.0", + "version": "3.0", "description": "Control a Music Player Daemon (MPD)", "icons": { "128": "images/icon-128x128.png"