Skip to content

Commit

Permalink
fix: synchronously shim vtt.js when possible (#4083)
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonocasey authored Feb 21, 2017
1 parent a04f387 commit e1b4804
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 @@ -506,7 +506,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 @@ -551,7 +558,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 @@ -567,10 +577,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 e1b4804

Please sign in to comment.