From 4879c3e3ce2a435069cf5139d5a8682e544b1059 Mon Sep 17 00:00:00 2001 From: John Cass Date: Sat, 7 Oct 2017 06:12:19 +0200 Subject: [PATCH] Prevent subsequent sync attempts until getTimePosition returns. (#238) Fixes #237. --- README.rst | 7 +++++++ mopidy_musicbox_webclient/static/js/synced_timer.js | 9 ++++++--- mopidy_musicbox_webclient/static/mb.appcache | 2 +- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/README.rst b/README.rst index c061c13..c53e9d8 100644 --- a/README.rst +++ b/README.rst @@ -105,6 +105,13 @@ Project resources Changelog ========= +(UNRELEASED) +------------ + +**Fixes** + +- Prevent excessive calls to the Mopidy server while buffering. (Fixes: `#237 `_). + v2.4.0 (2017-03-15) ------------------- diff --git a/mopidy_musicbox_webclient/static/js/synced_timer.js b/mopidy_musicbox_webclient/static/js/synced_timer.js index aaa6c04..8aabda8 100644 --- a/mopidy_musicbox_webclient/static/js/synced_timer.js +++ b/mopidy_musicbox_webclient/static/js/synced_timer.js @@ -106,7 +106,9 @@ // check in the timeout callback than doing another function call. clearTimeout(this._scheduleID) this._isSyncScheduled = false - this._scheduleID = setTimeout($.proxy(function () { this._isSyncScheduled = true }, this), milliseconds) + if (milliseconds >= 0) { + this._scheduleID = setTimeout($.proxy(function () { this._isSyncScheduled = true }, this), milliseconds) + } } SyncedProgressTimer.prototype._doSync = function (position, duration) { @@ -116,6 +118,8 @@ return } + this._scheduleSync(-1) // Ensure that only one sync process is active at a time. + var _this = this _this._mopidy.playback.getTimePosition().then(function (targetPosition) { if (_this.syncState === SyncedProgressTimer.SYNC_STATE.NOT_SYNCED) { @@ -179,8 +183,7 @@ SyncedProgressTimer.prototype.stop = function () { this._progressTimer.stop() - clearTimeout(this._scheduleID) - this._isSyncScheduled = false + this._scheduleSync(-1) if (this.syncState !== SyncedProgressTimer.SYNC_STATE.SYNCED && this._previousSyncPosition) { // Timer was busy trying to sync when it was stopped, fallback to displaying the last synced position on screen. this.positionNode.nodeValue = SyncedProgressTimer.format(this._previousSyncPosition) diff --git a/mopidy_musicbox_webclient/static/mb.appcache b/mopidy_musicbox_webclient/static/mb.appcache index 52a48d8..d9397c6 100644 --- a/mopidy_musicbox_webclient/static/mb.appcache +++ b/mopidy_musicbox_webclient/static/mb.appcache @@ -1,6 +1,6 @@ CACHE MANIFEST -# 2017-02-26:v1 +# 2017-04-14:v1 NETWORK: *