]> git.wh0rd.org Git - chrome-ext/music-player-client.git/commitdiff
auto-reconnect when we get an error v3.0
authorMike Frysinger <vapier@gentoo.org>
Sun, 1 Sep 2013 20:37:54 +0000 (16:37 -0400)
committerMike Frysinger <vapier@gentoo.org>
Sun, 1 Sep 2013 20:38:41 +0000 (16:38 -0400)
js/mpc.js
main.js
manifest.json

index 7fc74393bfa3ee9cbd970f2403308aaa937832f5..1e3390b27b7d21100dfe22d95837c9c508323efe 100644 (file)
--- 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 26d0bc7ae4bd7eb1ceb5ff5375500b3e4a051a18..5b05cee5e2c101192829762c3b542f40b49f9d86 100644 (file)
--- 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);
index 605208f5720a1ebab435a8a94ac6e7597223e87e..0e1073d290550512b9b9cfeee7001d7d47f3396f 100644 (file)
@@ -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"