X-Git-Url: https://git.wh0rd.org/?p=chrome-ext%2Fmusic-player-client.git;a=blobdiff_plain;f=js%2Fmpc.js;h=84eea050a9970ff47ff69ae6e3867dad378f2bef;hp=7fc74393bfa3ee9cbd970f2403308aaa937832f5;hb=c7400cad8000d7fd659ec3259e6bed1c2cdc9c0a;hpb=a0e4d450c94513030ce53ccccbad83570ed21c43 diff --git a/js/mpc.js b/js/mpc.js index 7fc7439..84eea05 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); + } }); } @@ -72,11 +78,13 @@ Mpc.prototype.recv_msg = function(lines) { ++i; } this.state.Playlist = playlist; + this.state.Playlist.lastUpdate = (new Date()).getTime(); this._cb_update_state(this.state); break; case 'currentsong': this.state.Currentsong = this._parse_result(lines).state; + this.state.Currentsong.lastUpdate = (new Date()).getTime(); this._cb_update_state(this.state); break;