From 8aa831fe49e73a920ccacf09e1733646dfeecc6f Mon Sep 17 00:00:00 2001 From: infinite-persistence Date: Fri, 24 Jun 2022 14:57:25 +0800 Subject: [PATCH] Recsys: fix resumed-send missing `totalPlayTime` Ticket: 1751 ## Issue The `totalPlayTime` resides in the videojs plugin and is only sent to the recsys object in `onPlayerDispose`, so it missed the redux rehydration in the browser close/refresh scenario. ## Change Update the recsys value for `totalPlayTime` immediately so that it'll be part of the redux stashing (and later, rehydration). Note that recsys data is currently being saved to redux in a 15s interval. Will change that in the next commit. --- extras/recsys/recsys.js | 7 +++++++ flow-typed/recsys.js | 1 + .../videoViewer/internal/plugins/videojs-recsys/plugin.js | 1 + 3 files changed, 9 insertions(+) diff --git a/extras/recsys/recsys.js b/extras/recsys/recsys.js index 1c79d85f2..40cc25d39 100644 --- a/extras/recsys/recsys.js +++ b/extras/recsys/recsys.js @@ -156,6 +156,13 @@ const recsys: Recsys = { recsys.log('createRecsysEntry', claimId); }, + updateRecsysEntry: function (claimId, key, value) { + const entry = recsys.entries[claimId]; + if (entry) { + entry[key] = value; + } + }, + /** * Send event for claimId * @param claimId diff --git a/flow-typed/recsys.js b/flow-typed/recsys.js index c0b6fa841..3b92a84d8 100644 --- a/flow-typed/recsys.js +++ b/flow-typed/recsys.js @@ -6,6 +6,7 @@ declare type Recsys = { onClickedRecommended: (parentClaimId: ClaimId, newClaimId: ClaimId) => void, onRecsLoaded: (claimId: ClaimId, uris: Array, uuid: string) => void, createRecsysEntry: (claimId: ClaimId, parentUuid?: ?string, uuid?: string) => void, + updateRecsysEntry: (claimId: ClaimId, key: string, value: string) => void, sendRecsysEntry: (claimId: ClaimId, isTentative?: boolean) => ?Promise, sendEntries: (entries: ?{ [ClaimId]: RecsysEntry }, isResumedSend: boolean) => void, onRecsysPlayerEvent: (claimId: ClaimId, event: RecsysPlaybackEvent, isEmbedded: boolean) => void, diff --git a/ui/component/viewers/videoViewer/internal/plugins/videojs-recsys/plugin.js b/ui/component/viewers/videoViewer/internal/plugins/videojs-recsys/plugin.js index 29a052387..5081fed8e 100644 --- a/ui/component/viewers/videoViewer/internal/plugins/videojs-recsys/plugin.js +++ b/ui/component/viewers/videoViewer/internal/plugins/videojs-recsys/plugin.js @@ -129,6 +129,7 @@ class RecsysPlugin extends Component { if (this.watchedDuration.lastTimestamp !== curTimeSec && !this.inPause) { this.watchedDuration.total += 1; this.watchedDuration.lastTimestamp = curTimeSec; + RecSys.updateRecsysEntry(this.options_.videoId, 'totalPlayTime', this.watchedDuration.total); } }