+
+ private initTouchStartEvents () {
+ this.player.on('touchstart', (event: TouchEvent) => {
+ event.stopPropagation()
+
+ if (this.tapTimeout) {
+ clearTimeout(this.tapTimeout)
+ this.tapTimeout = undefined
+ }
+
+ if (this.lastTapEvent && event.timeStamp - this.lastTapEvent.timeStamp < PeerTubeMobilePlugin.DOUBLE_TAP_DELAY_MS) {
+ logger('Detected double tap')
+
+ this.lastTapEvent = undefined
+ this.onDoubleTap(event)
+ return
+ }
+
+ this.newActiveState = !this.player.userActive()
+
+ this.tapTimeout = setTimeout(() => {
+ logger('No double tap detected, set user active state to %s.', this.newActiveState)
+
+ this.player.userActive(this.newActiveState)
+ }, PeerTubeMobilePlugin.DOUBLE_TAP_DELAY_MS)
+
+ this.lastTapEvent = event
+ })
+ }
+
+ private onDoubleTap (event: TouchEvent) {
+ const playerWidth = this.player.currentWidth()
+
+ const rect = this.findPlayerTarget((event.target as HTMLElement)).getBoundingClientRect()
+ const offsetX = event.targetTouches[0].pageX - rect.left
+
+ logger('Calculating double tap zone (player width: %d, offset X: %d)', playerWidth, offsetX)
+
+ if (offsetX > 0.66 * playerWidth) {
+ if (this.seekAmount < 0) this.seekAmount = 0
+
+ this.seekAmount += 10
+
+ logger('Will forward %d seconds', this.seekAmount)
+ } else if (offsetX < 0.33 * playerWidth) {
+ if (this.seekAmount > 0) this.seekAmount = 0
+
+ this.seekAmount -= 10
+ logger('Will rewind %d seconds', this.seekAmount)
+ }
+
+ this.peerTubeMobileButtons.displayFastSeek(this.seekAmount)
+
+ this.scheduleSetCurrentTime()
+
+ }
+
+ private findPlayerTarget (target: HTMLElement): HTMLElement {
+ if (target.classList.contains('video-js')) return target
+
+ return this.findPlayerTarget(target.parentElement)
+ }
+
+ private scheduleSetCurrentTime () {
+ this.player.pause()
+ this.player.addClass('vjs-fast-seeking')
+
+ if (this.setCurrentTimeTimeout) clearTimeout(this.setCurrentTimeTimeout)
+
+ this.setCurrentTimeTimeout = setTimeout(() => {
+ let newTime = this.player.currentTime() + this.seekAmount
+ this.seekAmount = 0
+
+ newTime = Math.max(0, newTime)
+ newTime = Math.min(this.player.duration(), newTime)
+
+ this.player.currentTime(newTime)
+ this.seekAmount = 0
+ this.peerTubeMobileButtons.displayFastSeek(0)
+
+ this.player.removeClass('vjs-fast-seeking')
+ this.player.userActive(false)
+
+ this.player.play()
+ }, PeerTubeMobilePlugin.SET_CURRENT_TIME_DELAY)
+ }