]>
Commit | Line | Data |
---|---|---|
1 | import videojs from 'video.js' | |
2 | import { EndCardOptions } from './end-card' | |
3 | ||
4 | const Plugin = videojs.getPlugin('plugin') | |
5 | ||
6 | class UpNextPlugin extends Plugin { | |
7 | ||
8 | constructor (player: videojs.Player, options: Partial<EndCardOptions> = {}) { | |
9 | const settings = { | |
10 | next: options.next, | |
11 | getTitle: options.getTitle, | |
12 | timeout: options.timeout || 5000, | |
13 | cancelText: options.cancelText || 'Cancel', | |
14 | headText: options.headText || 'Up Next', | |
15 | suspendedText: options.suspendedText || 'Autoplay is suspended', | |
16 | condition: options.condition, | |
17 | suspended: options.suspended | |
18 | } | |
19 | ||
20 | super(player) | |
21 | ||
22 | // UpNext plugin can be called later, so ensure the player is not disposed | |
23 | if (this.player.isDisposed()) return | |
24 | ||
25 | this.player.ready(() => { | |
26 | player.addClass('vjs-upnext') | |
27 | }) | |
28 | ||
29 | player.addChild('EndCard', settings) | |
30 | } | |
31 | } | |
32 | ||
33 | videojs.registerPlugin('upnext', UpNextPlugin) | |
34 | export { UpNextPlugin } |