Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Check for VTTCue #8370

Merged
merged 6 commits into from
Jul 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading