Skip to content

Commit da15810

Browse files
authored
fix: Check for VTTCue (videojs#8370)
1 parent 452a918 commit da15810

File tree

4 files changed

+28
-5
lines changed

4 files changed

+28
-5
lines changed

package-lock.json

Lines changed: 11 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@
9898
"safe-json-parse": "4.0.0",
9999
"videojs-contrib-quality-levels": "4.0.0",
100100
"videojs-font": "4.1.0",
101-
"videojs-vtt.js": "0.15.4"
101+
"videojs-vtt.js": "0.15.5"
102102
},
103103
"devDependencies": {
104104
"@babel/core": "^7.9.0",

src/js/tracks/text-track.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ class TextTrack extends Track {
391391
addCue(originalCue) {
392392
let cue = originalCue;
393393

394-
if (window.vttjs && !(originalCue instanceof window.vttjs.VTTCue)) {
394+
if (cue.constructor && cue.constructor.name !== 'VTTCue') {
395395
cue = new window.vttjs.VTTCue(originalCue.startTime, originalCue.endTime, originalCue.text);
396396

397397
for (const prop in originalCue) {

test/unit/tracks/text-track.test.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,21 @@ QUnit.test('original cue can be used to remove cue from cues list', function(ass
231231
assert.equal(tt.cues.length, 0, 'we have removed cue1');
232232
});
233233

234+
QUnit.test('non-VTTCue can be used to remove cue from cues list', function(assert) {
235+
const tt = new TextTrack({
236+
tech: this.tech
237+
});
238+
239+
const cue1 = { id: 1, text: 'test' };
240+
241+
assert.equal(tt.cues.length, 0, 'start with zero cues');
242+
tt.addCue(cue1);
243+
assert.equal(tt.cues.length, 1, 'we have one cue');
244+
245+
tt.removeCue(cue1);
246+
assert.equal(tt.cues.length, 0, 'we have removed cue1');
247+
});
248+
234249
QUnit.test('can only remove one cue at a time', function(assert) {
235250
const tt = new TextTrack({
236251
tech: this.tech

0 commit comments

Comments
 (0)