From 96a387f72341bb0e71b58b83ca1d50cefbe9be21 Mon Sep 17 00:00:00 2001 From: Gary Katsevman Date: Mon, 27 Feb 2017 13:52:01 -0500 Subject: [PATCH] feat: update videojs-vtt.js and wrap native cues in TextTrack (#4115) Update videojs-vtt.js and don't auto-export its versions of VTTCue globally. When our TextTrack object is given a cue, if it's a native cue, wrap it in our emulated vttjs.VTTCue. Fixes #4093. --- package.json | 2 +- src/js/tech/tech.js | 3 --- src/js/tracks/text-track.js | 12 +++++++++++- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 96d7fb50a..222b0664d 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,7 @@ "tsml": "1.0.1", "videojs-font": "2.0.0", "videojs-ie8": "1.1.2", - "videojs-vtt.js": "0.12.1", + "videojs-vtt.js": "0.12.2", "xhr": "2.3.3" }, "devDependencies": { diff --git a/src/js/tech/tech.js b/src/js/tech/tech.js index d315cad55..aeab56a80 100644 --- a/src/js/tech/tech.js +++ b/src/js/tech/tech.js @@ -520,9 +520,6 @@ class Tech extends Component { // as an option. novtt builds will turn the above require call into an empty object // which will cause this if check to always fail. if (!this.options_['vtt.js'] && isPlain(vtt) && Object.keys(vtt).length > 0) { - Object.keys(vtt).forEach(function(k) { - window[k] = vtt[k]; - }); this.trigger('vttjsloaded'); return; } diff --git a/src/js/tracks/text-track.js b/src/js/tracks/text-track.js index 6eb8fd01a..4f17142bf 100644 --- a/src/js/tracks/text-track.js +++ b/src/js/tracks/text-track.js @@ -336,7 +336,17 @@ class TextTrack extends Track { * @param {TextTrack~Cue} cue * The cue to add to our internal list */ - addCue(cue) { + addCue(originalCue) { + let cue = originalCue; + + if (!(originalCue instanceof window.vttjs.VTTCue)) { + cue = new window.vttjs.VTTCue(originalCue.startTime, originalCue.endTime, originalCue.text); + + for (const prop in originalCue) { + cue[prop] = originalCue[prop]; + } + } + const tracks = this.tech_.textTracks(); for (let i = 0; i < tracks.length; i++) {