private hotkeys: Hotkey[] = []
+ private static VIEW_VIDEO_INTERVAL_MS = 5000
+
constructor (
private elementRef: ElementRef,
private route: ActivatedRoute,
const byLocalStorage = getStoredVideoWatchHistory(video.uuid)
if (byUrl) return timeToInt(urlOptions.startTime)
- if (byHistory) return video.userHistory.currentTime
- if (byLocalStorage) return byLocalStorage.duration
- return 0
- }
+ let startTime = 0
+ if (byHistory) startTime = video.userHistory.currentTime
+ if (byLocalStorage) startTime = byLocalStorage.duration
- let startTime = getStartTime()
+ // If we are at the end of the video, reset the timer
+ if (video.duration - startTime <= 1) startTime = 0
+
+ return startTime
+ }
- // If we are at the end of the video, reset the timer
- if (video.duration - startTime <= 1) startTime = 0
+ const startTime = getStartTime()
const playerCaptions = videoCaptions.map(c => ({
label: c.language.label,
videoViewUrl: video.privacy.id !== VideoPrivacy.PRIVATE
? this.videoService.getVideoViewUrl(video.uuid)
: null,
+ videoViewIntervalMs: VideoWatchComponent.VIEW_VIDEO_INTERVAL_MS,
authorizationHeader: () => this.authService.getRequestHeaderValue(),
serverUrl: environment.originServerUrl || window.location.origin,
private readonly videoUUID: string
private readonly startTime: number
- private readonly CONSTANTS = {
- USER_VIEW_VIDEO_INTERVAL: 5000 // Every 5 seconds, notify the user is watching the video
- }
+ private readonly videoViewIntervalMs: number
private videoCaptions: VideoJSCaption[]
private defaultSubtitle: string
this.authorizationHeader = options.authorizationHeader
this.videoUUID = options.videoUUID
this.startTime = timeToInt(options.startTime)
+ this.videoViewIntervalMs = options.videoViewIntervalMs
this.videoCaptions = options.videoCaptions
this.initialInactivityTimeout = this.player.options_.inactivityTimeout
})
this.player.one('ended', () => {
- const currentTime = Math.round(this.player.duration())
+ const currentTime = Math.floor(this.player.duration())
lastCurrentTime = currentTime
this.notifyUserIsWatching(currentTime, lastViewEvent)
})
this.videoViewInterval = setInterval(() => {
- const currentTime = Math.round(this.player.currentTime())
+ const currentTime = Math.floor(this.player.currentTime())
// No need to update
if (currentTime === lastCurrentTime) return
if (!this.authorizationHeader()) {
saveVideoWatchHistory(this.videoUUID, currentTime)
}
- }, this.CONSTANTS.USER_VIEW_VIDEO_INTERVAL)
+ }, this.videoViewIntervalMs)
}
private notifyUserIsWatching (currentTime: number, viewEvent: VideoViewEvent) {