aboutsummaryrefslogtreecommitdiffhomepage
path: root/client
diff options
context:
space:
mode:
Diffstat (limited to 'client')
-rw-r--r--client/src/app/+videos/+video-watch/video-watch.component.ts19
-rw-r--r--client/src/assets/player/shared/manager-options/manager-options-builder.ts1
-rw-r--r--client/src/assets/player/shared/peertube/peertube-plugin.ts11
-rw-r--r--client/src/assets/player/types/manager-options.ts2
-rw-r--r--client/src/assets/player/types/peertube-videojs-typings.ts2
-rw-r--r--client/src/standalone/videos/shared/player-manager-options.ts1
6 files changed, 23 insertions, 13 deletions
diff --git a/client/src/app/+videos/+video-watch/video-watch.component.ts b/client/src/app/+videos/+video-watch/video-watch.component.ts
index 84548de97..19ad97d42 100644
--- a/client/src/app/+videos/+video-watch/video-watch.component.ts
+++ b/client/src/app/+videos/+video-watch/video-watch.component.ts
@@ -91,6 +91,8 @@ export class VideoWatchComponent implements OnInit, OnDestroy {
91 91
92 private hotkeys: Hotkey[] = [] 92 private hotkeys: Hotkey[] = []
93 93
94 private static VIEW_VIDEO_INTERVAL_MS = 5000
95
94 constructor ( 96 constructor (
95 private elementRef: ElementRef, 97 private elementRef: ElementRef,
96 private route: ActivatedRoute, 98 private route: ActivatedRoute,
@@ -613,16 +615,18 @@ export class VideoWatchComponent implements OnInit, OnDestroy {
613 const byLocalStorage = getStoredVideoWatchHistory(video.uuid) 615 const byLocalStorage = getStoredVideoWatchHistory(video.uuid)
614 616
615 if (byUrl) return timeToInt(urlOptions.startTime) 617 if (byUrl) return timeToInt(urlOptions.startTime)
616 if (byHistory) return video.userHistory.currentTime
617 if (byLocalStorage) return byLocalStorage.duration
618 618
619 return 0 619 let startTime = 0
620 } 620 if (byHistory) startTime = video.userHistory.currentTime
621 if (byLocalStorage) startTime = byLocalStorage.duration
621 622
622 let startTime = getStartTime() 623 // If we are at the end of the video, reset the timer
624 if (video.duration - startTime <= 1) startTime = 0
625
626 return startTime
627 }
623 628
624 // If we are at the end of the video, reset the timer 629 const startTime = getStartTime()
625 if (video.duration - startTime <= 1) startTime = 0
626 630
627 const playerCaptions = videoCaptions.map(c => ({ 631 const playerCaptions = videoCaptions.map(c => ({
628 label: c.language.label, 632 label: c.language.label,
@@ -679,6 +683,7 @@ export class VideoWatchComponent implements OnInit, OnDestroy {
679 videoViewUrl: video.privacy.id !== VideoPrivacy.PRIVATE 683 videoViewUrl: video.privacy.id !== VideoPrivacy.PRIVATE
680 ? this.videoService.getVideoViewUrl(video.uuid) 684 ? this.videoService.getVideoViewUrl(video.uuid)
681 : null, 685 : null,
686 videoViewIntervalMs: VideoWatchComponent.VIEW_VIDEO_INTERVAL_MS,
682 authorizationHeader: () => this.authService.getRequestHeaderValue(), 687 authorizationHeader: () => this.authService.getRequestHeaderValue(),
683 688
684 serverUrl: environment.originServerUrl || window.location.origin, 689 serverUrl: environment.originServerUrl || window.location.origin,
diff --git a/client/src/assets/player/shared/manager-options/manager-options-builder.ts b/client/src/assets/player/shared/manager-options/manager-options-builder.ts
index c820d637b..5d3ee4c4a 100644
--- a/client/src/assets/player/shared/manager-options/manager-options-builder.ts
+++ b/client/src/assets/player/shared/manager-options/manager-options-builder.ts
@@ -35,6 +35,7 @@ export class ManagerOptionsBuilder {
35 35
36 ...pick(commonOptions, [ 36 ...pick(commonOptions, [
37 'videoViewUrl', 37 'videoViewUrl',
38 'videoViewIntervalMs',
38 'authorizationHeader', 39 'authorizationHeader',
39 'startTime', 40 'startTime',
40 'videoDuration', 41 'videoDuration',
diff --git a/client/src/assets/player/shared/peertube/peertube-plugin.ts b/client/src/assets/player/shared/peertube/peertube-plugin.ts
index ec8fbb320..b5f177f30 100644
--- a/client/src/assets/player/shared/peertube/peertube-plugin.ts
+++ b/client/src/assets/player/shared/peertube/peertube-plugin.ts
@@ -27,9 +27,7 @@ class PeerTubePlugin extends Plugin {
27 private readonly videoUUID: string 27 private readonly videoUUID: string
28 private readonly startTime: number 28 private readonly startTime: number
29 29
30 private readonly CONSTANTS = { 30 private readonly videoViewIntervalMs: number
31 USER_VIEW_VIDEO_INTERVAL: 5000 // Every 5 seconds, notify the user is watching the video
32 }
33 31
34 private videoCaptions: VideoJSCaption[] 32 private videoCaptions: VideoJSCaption[]
35 private defaultSubtitle: string 33 private defaultSubtitle: string
@@ -48,6 +46,7 @@ class PeerTubePlugin extends Plugin {
48 this.authorizationHeader = options.authorizationHeader 46 this.authorizationHeader = options.authorizationHeader
49 this.videoUUID = options.videoUUID 47 this.videoUUID = options.videoUUID
50 this.startTime = timeToInt(options.startTime) 48 this.startTime = timeToInt(options.startTime)
49 this.videoViewIntervalMs = options.videoViewIntervalMs
51 50
52 this.videoCaptions = options.videoCaptions 51 this.videoCaptions = options.videoCaptions
53 this.initialInactivityTimeout = this.player.options_.inactivityTimeout 52 this.initialInactivityTimeout = this.player.options_.inactivityTimeout
@@ -188,7 +187,7 @@ class PeerTubePlugin extends Plugin {
188 }) 187 })
189 188
190 this.player.one('ended', () => { 189 this.player.one('ended', () => {
191 const currentTime = Math.round(this.player.duration()) 190 const currentTime = Math.floor(this.player.duration())
192 lastCurrentTime = currentTime 191 lastCurrentTime = currentTime
193 192
194 this.notifyUserIsWatching(currentTime, lastViewEvent) 193 this.notifyUserIsWatching(currentTime, lastViewEvent)
@@ -197,7 +196,7 @@ class PeerTubePlugin extends Plugin {
197 }) 196 })
198 197
199 this.videoViewInterval = setInterval(() => { 198 this.videoViewInterval = setInterval(() => {
200 const currentTime = Math.round(this.player.currentTime()) 199 const currentTime = Math.floor(this.player.currentTime())
201 200
202 // No need to update 201 // No need to update
203 if (currentTime === lastCurrentTime) return 202 if (currentTime === lastCurrentTime) return
@@ -213,7 +212,7 @@ class PeerTubePlugin extends Plugin {
213 if (!this.authorizationHeader()) { 212 if (!this.authorizationHeader()) {
214 saveVideoWatchHistory(this.videoUUID, currentTime) 213 saveVideoWatchHistory(this.videoUUID, currentTime)
215 } 214 }
216 }, this.CONSTANTS.USER_VIEW_VIDEO_INTERVAL) 215 }, this.videoViewIntervalMs)
217 } 216 }
218 217
219 private notifyUserIsWatching (currentTime: number, viewEvent: VideoViewEvent) { 218 private notifyUserIsWatching (currentTime: number, viewEvent: VideoViewEvent) {
diff --git a/client/src/assets/player/types/manager-options.ts b/client/src/assets/player/types/manager-options.ts
index 3fbcec29c..c14fd7e99 100644
--- a/client/src/assets/player/types/manager-options.ts
+++ b/client/src/assets/player/types/manager-options.ts
@@ -55,6 +55,8 @@ export interface CommonOptions extends CustomizationOptions {
55 inactivityTimeout: number 55 inactivityTimeout: number
56 poster: string 56 poster: string
57 57
58 videoViewIntervalMs: number
59
58 instanceName: string 60 instanceName: string
59 61
60 theaterButton: boolean 62 theaterButton: boolean
diff --git a/client/src/assets/player/types/peertube-videojs-typings.ts b/client/src/assets/player/types/peertube-videojs-typings.ts
index 5674f78cb..eadf56cfa 100644
--- a/client/src/assets/player/types/peertube-videojs-typings.ts
+++ b/client/src/assets/player/types/peertube-videojs-typings.ts
@@ -108,6 +108,8 @@ type PeerTubePluginOptions = {
108 isLive: boolean 108 isLive: boolean
109 109
110 videoUUID: string 110 videoUUID: string
111
112 videoViewIntervalMs: number
111} 113}
112 114
113type MetricsPluginOptions = { 115type MetricsPluginOptions = {
diff --git a/client/src/standalone/videos/shared/player-manager-options.ts b/client/src/standalone/videos/shared/player-manager-options.ts
index f09c86d14..43ae22a3b 100644
--- a/client/src/standalone/videos/shared/player-manager-options.ts
+++ b/client/src/standalone/videos/shared/player-manager-options.ts
@@ -217,6 +217,7 @@ export class PlayerManagerOptions {
217 videoCaptions, 217 videoCaptions,
218 inactivityTimeout: 2500, 218 inactivityTimeout: 2500,
219 videoViewUrl: this.videoFetcher.getVideoViewsUrl(video.uuid), 219 videoViewUrl: this.videoFetcher.getVideoViewsUrl(video.uuid),
220 videoViewIntervalMs: 5000,
220 metricsUrl: window.location.origin + '/api/v1/metrics/playback', 221 metricsUrl: window.location.origin + '/api/v1/metrics/playback',
221 222
222 videoShortUUID: video.shortUUID, 223 videoShortUUID: video.shortUUID,