From 8d64e317943a529b96a15d4d12f0af368a92e043 Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Sun, 1 Sep 2013 16:37:54 -0400 Subject: [PATCH] auto-reconnect when we get an error --- js/mpc.js | 6 ++++++ main.js | 4 ++++ manifest.json | 2 +- 3 files changed, 11 insertions(+), 1 deletion(-) 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" -- 2.39.2