2022-01-11 11:26:35 +01:00
|
|
|
import videojs from 'video.js'
|
|
|
|
|
|
|
|
const Component = videojs.getComponent('Component')
|
|
|
|
class PeerTubeMobileButtons extends Component {
|
2023-06-29 15:55:00 +02:00
|
|
|
private mainButton: HTMLDivElement
|
2022-01-11 11:26:35 +01:00
|
|
|
|
2022-01-12 15:07:21 +01:00
|
|
|
private rewind: Element
|
|
|
|
private forward: Element
|
|
|
|
private rewindText: Element
|
|
|
|
private forwardText: Element
|
|
|
|
|
2023-06-29 15:55:00 +02:00
|
|
|
private touchStartHandler: (e: TouchEvent) => void
|
2022-01-11 11:26:35 +01:00
|
|
|
|
2023-06-29 15:55:00 +02:00
|
|
|
createEl () {
|
|
|
|
const container = super.createEl('div', { className: 'vjs-mobile-buttons-overlay' }) as HTMLDivElement
|
|
|
|
this.mainButton = super.createEl('div', { className: 'main-button' }) as HTMLDivElement
|
2022-01-11 11:26:35 +01:00
|
|
|
|
2023-06-29 15:55:00 +02:00
|
|
|
this.touchStartHandler = e => {
|
2022-01-11 11:26:35 +01:00
|
|
|
e.stopPropagation()
|
|
|
|
|
|
|
|
if (this.player_.paused() || this.player_.ended()) {
|
|
|
|
this.player_.play()
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
this.player_.pause()
|
2023-06-29 15:55:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
this.mainButton.addEventListener('touchstart', this.touchStartHandler, { passive: true })
|
2022-01-11 11:26:35 +01:00
|
|
|
|
2022-01-12 15:07:21 +01:00
|
|
|
this.rewind = super.createEl('div', { className: 'rewind-button vjs-hidden' })
|
|
|
|
this.forward = super.createEl('div', { className: 'forward-button vjs-hidden' })
|
|
|
|
|
|
|
|
for (let i = 0; i < 3; i++) {
|
|
|
|
this.rewind.appendChild(super.createEl('span', { className: 'icon' }))
|
|
|
|
this.forward.appendChild(super.createEl('span', { className: 'icon' }))
|
|
|
|
}
|
|
|
|
|
|
|
|
this.rewindText = this.rewind.appendChild(super.createEl('div', { className: 'text' }))
|
|
|
|
this.forwardText = this.forward.appendChild(super.createEl('div', { className: 'text' }))
|
|
|
|
|
|
|
|
container.appendChild(this.rewind)
|
2023-06-29 15:55:00 +02:00
|
|
|
container.appendChild(this.mainButton)
|
2022-01-12 15:07:21 +01:00
|
|
|
container.appendChild(this.forward)
|
2022-01-11 11:26:35 +01:00
|
|
|
|
|
|
|
return container
|
|
|
|
}
|
2022-01-12 15:07:21 +01:00
|
|
|
|
2023-06-29 15:55:00 +02:00
|
|
|
dispose () {
|
|
|
|
if (this.touchStartHandler) this.mainButton.removeEventListener('touchstart', this.touchStartHandler)
|
|
|
|
|
|
|
|
super.dispose()
|
|
|
|
}
|
|
|
|
|
2022-01-12 15:07:21 +01:00
|
|
|
displayFastSeek (amount: number) {
|
|
|
|
if (amount === 0) {
|
|
|
|
this.hideRewind()
|
|
|
|
this.hideForward()
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if (amount > 0) {
|
|
|
|
this.hideRewind()
|
|
|
|
this.displayForward(amount)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if (amount < 0) {
|
|
|
|
this.hideForward()
|
|
|
|
this.displayRewind(amount)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private hideRewind () {
|
|
|
|
this.rewind.classList.add('vjs-hidden')
|
|
|
|
this.rewindText.textContent = ''
|
|
|
|
}
|
|
|
|
|
|
|
|
private displayRewind (amount: number) {
|
|
|
|
this.rewind.classList.remove('vjs-hidden')
|
|
|
|
this.rewindText.textContent = this.player().localize('{1} seconds', [ amount + '' ])
|
|
|
|
}
|
|
|
|
|
|
|
|
private hideForward () {
|
|
|
|
this.forward.classList.add('vjs-hidden')
|
|
|
|
this.forwardText.textContent = ''
|
|
|
|
}
|
|
|
|
|
|
|
|
private displayForward (amount: number) {
|
|
|
|
this.forward.classList.remove('vjs-hidden')
|
|
|
|
this.forwardText.textContent = this.player().localize('{1} seconds', [ amount + '' ])
|
|
|
|
}
|
2022-01-11 11:26:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
videojs.registerComponent('PeerTubeMobileButtons', PeerTubeMobileButtons)
|
2022-01-12 15:07:21 +01:00
|
|
|
|
|
|
|
export {
|
|
|
|
PeerTubeMobileButtons
|
|
|
|
}
|