From e8cd18eac2d87e53153bcfe896633a1ff0e8c83a Mon Sep 17 00:00:00 2001 From: advplyr Date: Fri, 3 Jun 2022 19:11:13 -0500 Subject: [PATCH] Add:Alert when progress is not syncing --- client/components/app/StreamContainer.vue | 7 ++++++- client/players/PlayerHandler.js | 11 ++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/client/components/app/StreamContainer.vue b/client/components/app/StreamContainer.vue index c44a3af0..45fc2734 100644 --- a/client/components/app/StreamContainer.vue +++ b/client/components/app/StreamContainer.vue @@ -71,7 +71,8 @@ export default { sleepTimerRemaining: 0, sleepTimer: null, displayTitle: null, - initialPlaybackRate: 1 + initialPlaybackRate: 1, + syncFailedToast: null } }, computed: { @@ -380,6 +381,10 @@ export default { }, pauseItem() { this.playerHandler.pause() + }, + showFailedProgressSyncs() { + if (!isNaN(this.syncFailedToast)) this.$toast.dismiss(this.syncFailedToast) + this.syncFailedToast = this.$toast('Progress is not being synced. Restart playback', { timeout: false, type: 'error' }) } }, mounted() { diff --git a/client/players/PlayerHandler.js b/client/players/PlayerHandler.js index 497fcd13..aa2c5346 100644 --- a/client/players/PlayerHandler.js +++ b/client/players/PlayerHandler.js @@ -20,6 +20,7 @@ export default class PlayerHandler { this.currentSessionId = null this.startTime = 0 + this.failedProgressSyncs = 0 this.lastSyncTime = 0 this.lastSyncedAt = 0 this.listeningTimeSinceSync = 0 @@ -186,6 +187,7 @@ export default class PlayerHandler { } prepareSession(session) { + this.failedProgressSyncs = 0 this.startTime = session.currentTime this.currentSessionId = session.id this.displayTitle = session.displayTitle @@ -286,8 +288,15 @@ export default class PlayerHandler { currentTime } this.listeningTimeSinceSync = 0 - this.ctx.$axios.$post(`/api/session/${this.currentSessionId}/sync`, syncData, { timeout: 1000 }).catch((error) => { + this.ctx.$axios.$post(`/api/session/${this.currentSessionId}/sync`, syncData, { timeout: 1000 }).then(() => { + this.failedProgressSyncs = 0 + }).catch((error) => { console.error('Failed to update session progress', error) + this.failedProgressSyncs++ + if (this.failedProgressSyncs >= 2) { + this.ctx.showFailedProgressSyncs() + this.failedProgressSyncs = 0 + } }) }