-
-
Notifications
You must be signed in to change notification settings - Fork 308
Expand file tree
/
Copy pathrecord-indicator.js
More file actions
103 lines (89 loc) · 2.56 KB
/
record-indicator.js
File metadata and controls
103 lines (89 loc) · 2.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/**
* @file record-indicator.js
* @since 2.0.0
*/
import videojs from 'video.js';
import Event from '../event';
const Component = videojs.getComponent('Component');
/**
* Icon indicating recording is active.
*
* @class
* @augments videojs.Component
*/
class RecordIndicator extends Component {
/**
* The constructor function for the class.
*
* @private
* @param {(videojs.Player|Object)} player - Video.js player instance.
* @param {Object} options - Player options.
*/
constructor(player, options) {
super(player, options);
this.enable();
}
/**
* Create the `RecordIndicator`s DOM element.
*
* @return {Element}
* The dom element that gets created.
*/
createEl() {
let props = {
className: 'vjs-record-indicator vjs-control',
dir: 'ltr'
};
let attr = {
'data-label': this.localize('REC')
};
return super.createEl('div', props, attr);
}
/**
* Enable event handlers.
*/
enable() {
this.on(this.player_, Event.START_RECORD, this.show);
this.on(this.player_, Event.PROGRESS_RECORD, this.onProgress);
this.on(this.player_, Event.STOP_RECORD, this.hide);
}
/**
* Disable event handlers.
*/
disable() {
this.off(this.player_, Event.START_RECORD, this.show);
this.off(this.player_, Event.PROGRESS_RECORD, this.onProgress);
this.off(this.player_, Event.STOP_RECORD, this.hide);
}
/**
* Show the `RecordIndicator` element if it is hidden by removing the
* 'vjs-hidden' class name from it.
*/
show() {
if (this.layoutExclude && this.layoutExclude === true) {
// ignore
return;
}
super.show();
}
/**
* Displays current recording time instead of REC
* @param {Object} label - formatted time.
*/
setProgressValue(label) {
this.el().dataset.label = label;
}
/**
* Invoked during recording and displays the remaining time.
*/
onProgress() {
let recorder = this.player_.record();
let now = performance.now();
let duration = recorder.maxLength;
let currentTime = (now - (recorder.startTime +
recorder.pausedTime)) / 1000; // buddy ignore:line
this.setProgressValue(recorder._formatTime(Math.min(currentTime, duration), duration, recorder.displayMilliseconds));
}
}
Component.registerComponent('RecordIndicator', RecordIndicator);
export default RecordIndicator;