mirror of
https://github.com/videojs/video.js.git
synced 2024-12-14 11:23:30 +02:00
fix: synchronously shim vtt.js when possible (#4083)
This commit is contained in:
parent
a04f387a72
commit
e1b48042dd
@ -506,7 +506,14 @@ class Tech extends Component {
|
|||||||
* @fires Tech#vttjserror
|
* @fires Tech#vttjserror
|
||||||
*/
|
*/
|
||||||
addWebVttScript_() {
|
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');
|
const vtt = require('videojs-vtt.js');
|
||||||
|
|
||||||
// load via require if available and vtt.js script location was not passed in
|
// load via require if available and vtt.js script location was not passed in
|
||||||
@ -551,7 +558,10 @@ class Tech extends Component {
|
|||||||
// we don't overwrite the injected window.WebVTT if it loads right away
|
// we don't overwrite the injected window.WebVTT if it loads right away
|
||||||
window.WebVTT = true;
|
window.WebVTT = true;
|
||||||
this.el().parentNode.appendChild(script);
|
this.el().parentNode.appendChild(script);
|
||||||
|
} else {
|
||||||
|
this.ready(this.addWebVttScript_);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -567,10 +577,7 @@ class Tech extends Component {
|
|||||||
remoteTracks.on('addtrack', handleAddTrack);
|
remoteTracks.on('addtrack', handleAddTrack);
|
||||||
remoteTracks.on('removetrack', handleRemoveTrack);
|
remoteTracks.on('removetrack', handleRemoveTrack);
|
||||||
|
|
||||||
// Initially, Tech.el_ is a child of a dummy-div wait until the Component system
|
this.addWebVttScript_();
|
||||||
// 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_);
|
|
||||||
|
|
||||||
const updateDisplay = () => this.trigger('texttrackchange');
|
const updateDisplay = () => this.trigger('texttrackchange');
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user