2020-01-28 10:29:50 -06:00
|
|
|
import videojs, { VideoJsPlayer } from 'video.js'
|
|
|
|
import { EndCardOptions } from './end-card'
|
2019-12-17 09:49:33 -06:00
|
|
|
|
2020-01-28 10:29:50 -06:00
|
|
|
const Plugin = videojs.getPlugin('plugin')
|
2019-12-17 09:49:33 -06:00
|
|
|
|
|
|
|
class UpNextPlugin extends Plugin {
|
2020-01-28 10:29:50 -06:00
|
|
|
|
|
|
|
constructor (player: VideoJsPlayer, options: Partial<EndCardOptions> = {}) {
|
2019-12-17 09:49:33 -06:00
|
|
|
const settings = {
|
|
|
|
next: options.next,
|
|
|
|
getTitle: options.getTitle,
|
|
|
|
timeout: options.timeout || 5000,
|
|
|
|
cancelText: options.cancelText || 'Cancel',
|
|
|
|
headText: options.headText || 'Up Next',
|
2019-12-20 10:49:57 -06:00
|
|
|
suspendedText: options.suspendedText || 'Autoplay is suspended',
|
|
|
|
condition: options.condition,
|
|
|
|
suspended: options.suspended
|
2019-12-17 09:49:33 -06:00
|
|
|
}
|
|
|
|
|
2020-01-28 10:29:50 -06:00
|
|
|
super(player)
|
2019-12-17 09:49:33 -06:00
|
|
|
|
|
|
|
this.player.ready(() => {
|
|
|
|
player.addClass('vjs-upnext')
|
|
|
|
})
|
|
|
|
|
|
|
|
player.addChild('EndCard', settings)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
videojs.registerPlugin('upnext', UpNextPlugin)
|
|
|
|
export { UpNextPlugin }
|