UNPKG

1.49 kBJavaScriptView Raw
1import videojs from 'video.js';
2
3/**
4 * The TimelineChangeController acts as a source for segment loaders to listen for and
5 * keep track of latest and pending timeline changes. This is useful to ensure proper
6 * sync, as each loader may need to make a consideration for what timeline the other
7 * loader is on before making changes which could impact the other loader's media.
8 *
9 * @class TimelineChangeController
10 * @extends videojs.EventTarget
11 */
12export default class TimelineChangeController extends videojs.EventTarget {
13 constructor() {
14 super();
15
16 this.pendingTimelineChanges_ = {};
17 this.lastTimelineChanges_ = {};
18 }
19
20 clearPendingTimelineChange(type) {
21 this.pendingTimelineChanges_[type] = null;
22 this.trigger('pendingtimelinechange');
23 }
24
25 pendingTimelineChange({ type, from, to }) {
26 if (typeof from === 'number' && typeof to === 'number') {
27 this.pendingTimelineChanges_[type] = { type, from, to };
28 this.trigger('pendingtimelinechange');
29 }
30 return this.pendingTimelineChanges_[type];
31 }
32
33 lastTimelineChange({ type, from, to }) {
34 if (typeof from === 'number' && typeof to === 'number') {
35 this.lastTimelineChanges_[type] = { type, from, to };
36 delete this.pendingTimelineChanges_[type];
37 this.trigger('timelinechange');
38 }
39 return this.lastTimelineChanges_[type];
40 }
41
42 dispose() {
43 this.trigger('dispose');
44 this.pendingTimelineChanges_ = {};
45 this.lastTimelineChanges_ = {};
46 this.off();
47 }
48}