Skip to content

Commit

Permalink
fix: synchronously shim vtt.js when possible (#4082)
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonocasey authored Feb 21, 2017
1 parent ce19ed5 commit b5727a6
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions src/js/tech/tech.js
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,14 @@ class Tech extends Component {
* @fires Tech#vttjserror
*/
addWebVttScript_() {
if (!window.WebVTT && this.el().parentNode !== null && this.el().parentNode !== undefined) {
if (window.WebVTT) {
return;
}

// Initially, Tech.el_ is a child of a dummy-div wait until the Component system
// signals that the Tech is ready at which point Tech.el_ is part of the DOM
// before inserting the WebVTT script
if (this.el().parentNode !== null && this.el().parentNode !== undefined) {
const vtt = require('videojs-vtt.js');

// load via require if available and vtt.js script location was not passed in
Expand Down Expand Up @@ -574,7 +581,10 @@ class Tech extends Component {
// we don't overwrite the injected window.WebVTT if it loads right away
window.WebVTT = true;
this.el().parentNode.appendChild(script);
} else {
this.ready(this.addWebVttScript_);
}

}

/**
Expand All @@ -596,10 +606,7 @@ class Tech extends Component {
remoteTracks.on('addtrack', handleAddTrack);
remoteTracks.on('removetrack', handleRemoveTrack);

// Initially, Tech.el_ is a child of a dummy-div wait until the Component system
// signals that the Tech is ready at which point Tech.el_ is part of the DOM
// before inserting the WebVTT script
this.on('ready', this.addWebVttScript_);
this.addWebVttScript_();

const updateDisplay = () => this.trigger('texttrackchange');

Expand Down

0 comments on commit b5727a6

Please sign in to comment.