Update:First sync after 20 seconds listening #1546

This commit is contained in:
advplyr 2023-05-11 15:31:47 -04:00
parent 688531f0a7
commit b0bf9604bb
2 changed files with 14 additions and 7 deletions

View File

@ -15,7 +15,7 @@
</template> </template>
<form class="flex items-center justify-center px-6 py-3" @submit.prevent="submitCustomTime"> <form class="flex items-center justify-center px-6 py-3" @submit.prevent="submitCustomTime">
<ui-text-input v-model="customTime" type="number" step="any" min="0.1" placeholder="Time in minutes" class="w-48" /> <ui-text-input v-model="customTime" type="number" step="any" min="0.1" placeholder="Time in minutes" class="w-48" />
<ui-btn color="success" type="submit" padding-x="0" class="h-9 w-12 flex items-center justify-center ml-1">Set</ui-btn> <ui-btn color="success" type="submit" :padding-x="0" class="h-9 w-12 flex items-center justify-center ml-1">Set</ui-btn>
</form> </form>
</div> </div>
<div v-else class="w-full p-4"> <div v-else class="w-full p-4">

View File

@ -24,7 +24,6 @@ export default class PlayerHandler {
this.failedProgressSyncs = 0 this.failedProgressSyncs = 0
this.lastSyncTime = 0 this.lastSyncTime = 0
this.lastSyncedAt = 0
this.listeningTimeSinceSync = 0 this.listeningTimeSinceSync = 0
this.playInterval = null this.playInterval = null
@ -210,6 +209,8 @@ export default class PlayerHandler {
this.playWhenReady = false this.playWhenReady = false
this.initialPlaybackRate = playbackRate this.initialPlaybackRate = playbackRate
this.startTimeOverride = undefined this.startTimeOverride = undefined
this.lastSyncTime = 0
this.listeningTimeSinceSync = 0
this.prepareSession(session) this.prepareSession(session)
} }
@ -287,7 +288,8 @@ export default class PlayerHandler {
const exactTimeElapsed = ((Date.now() - lastTick) / 1000) const exactTimeElapsed = ((Date.now() - lastTick) / 1000)
lastTick = Date.now() lastTick = Date.now()
this.listeningTimeSinceSync += exactTimeElapsed this.listeningTimeSinceSync += exactTimeElapsed
if (this.listeningTimeSinceSync >= 5) { const TimeToWaitBeforeSync = this.lastSyncTime > 0 ? 5 : 20
if (this.listeningTimeSinceSync >= TimeToWaitBeforeSync) {
this.sendProgressSync(currentTime) this.sendProgressSync(currentTime)
} }
}, 1000) }, 1000)
@ -297,13 +299,17 @@ export default class PlayerHandler {
let syncData = null let syncData = null
if (this.player) { if (this.player) {
const listeningTimeToAdd = Math.max(0, Math.floor(this.listeningTimeSinceSync)) const listeningTimeToAdd = Math.max(0, Math.floor(this.listeningTimeSinceSync))
// When opening player and quickly closing dont save progress
if (listeningTimeToAdd > 20 || this.lastSyncTime > 0) {
syncData = { syncData = {
timeListened: listeningTimeToAdd, timeListened: listeningTimeToAdd,
duration: this.getDuration(), duration: this.getDuration(),
currentTime: this.getCurrentTime() currentTime: this.getCurrentTime()
} }
} }
}
this.listeningTimeSinceSync = 0 this.listeningTimeSinceSync = 0
this.lastSyncTime = 0
return this.ctx.$axios.$post(`/api/session/${this.currentSessionId}/close`, syncData, { timeout: 1000 }).catch((error) => { return this.ctx.$axios.$post(`/api/session/${this.currentSessionId}/close`, syncData, { timeout: 1000 }).catch((error) => {
console.error('Failed to close session', error) console.error('Failed to close session', error)
}) })
@ -322,6 +328,7 @@ export default class PlayerHandler {
duration: this.getDuration(), duration: this.getDuration(),
currentTime currentTime
} }
this.listeningTimeSinceSync = 0 this.listeningTimeSinceSync = 0
this.ctx.$axios.$post(`/api/session/${this.currentSessionId}/sync`, syncData, { timeout: 3000 }).then(() => { this.ctx.$axios.$post(`/api/session/${this.currentSessionId}/sync`, syncData, { timeout: 3000 }).then(() => {
this.failedProgressSyncs = 0 this.failedProgressSyncs = 0