Skip to content

Commit

Permalink
fix: Check for VTTCue (#8370)
Browse files Browse the repository at this point in the history
  • Loading branch information
wseymour15 authored Jul 20, 2023
1 parent 452a918 commit da15810
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 5 deletions.
14 changes: 11 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
"safe-json-parse": "4.0.0",
"videojs-contrib-quality-levels": "4.0.0",
"videojs-font": "4.1.0",
"videojs-vtt.js": "0.15.4"
"videojs-vtt.js": "0.15.5"
},
"devDependencies": {
"@babel/core": "^7.9.0",
Expand Down
2 changes: 1 addition & 1 deletion src/js/tracks/text-track.js
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ class TextTrack extends Track {
addCue(originalCue) {
let cue = originalCue;

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

for (const prop in originalCue) {
Expand Down
15 changes: 15 additions & 0 deletions test/unit/tracks/text-track.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,21 @@ QUnit.test('original cue can be used to remove cue from cues list', function(ass
assert.equal(tt.cues.length, 0, 'we have removed cue1');
});

QUnit.test('non-VTTCue can be used to remove cue from cues list', function(assert) {
const tt = new TextTrack({
tech: this.tech
});

const cue1 = { id: 1, text: 'test' };

assert.equal(tt.cues.length, 0, 'start with zero cues');
tt.addCue(cue1);
assert.equal(tt.cues.length, 1, 'we have one cue');

tt.removeCue(cue1);
assert.equal(tt.cues.length, 0, 'we have removed cue1');
});

QUnit.test('can only remove one cue at a time', function(assert) {
const tt = new TextTrack({
tech: this.tech
Expand Down

0 comments on commit da15810

Please sign in to comment.