Skip to content

Commit

Permalink
Merge pull request #1380 from appsembler/main
Browse files Browse the repository at this point in the history
Update from `main` (production)
  • Loading branch information
bryanlandia authored Sep 20, 2023
2 parents 59a3be5 + 97a3e4d commit b37f4b7
Showing 1 changed file with 12 additions and 37 deletions.
49 changes: 12 additions & 37 deletions common/lib/xmodule/xmodule/js/src/video/01_initialize.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,49 +164,23 @@ function(VideoPlayer, i18n, moment, _) {
// so that it resolves our Deferred object, which will call all of the
// OnYouTubeIframeAPIReady callbacks.
//
// If this global function is already defined, we store it first, and make
// sure that it gets executed when our Deferred object is resolved.
let setupOnYouTubeIframeAPIReadyCallsCount = 0;

setupOnYouTubeIframeAPIReady = function() {
setupOnYouTubeIframeAPIReadyCallsCount++;
if (setupOnYouTubeIframeAPIReadyCallsCount > setupOnYouTubeIframeAPIReadyMaxCalls) {
throw new Error('Too many OnYouTubeIframeAPIReady retries after TypeError...giving up.');
}

handleYTAPIErr = function(ytapierr) {
console.error('Error while trying to resolve the Deferred object responsible for calling OnYouTubeIframeAPIReady callbacks.');
console.debug('window.onYouTubeIframeAPIReady is ' + window.onYouTubeIframeAPIReady);
console.error(ytapierr);
if (ytapierr instanceof TypeError) { // expecting TypeError: window.onYouTubeIframeAPIReady.resolve is not a function
setTimeout(setupOnYouTubeIframeAPIReady, 500); // Try again up to defined max calls.
}
else {
throw ytapierr;
}
};
let setupOnYouTubeIframeAPIReady = function() {

try {
_oldOnYouTubeIframeAPIReady = window.onYouTubeIframeAPIReady || undefined;
// If this global function is already defined, we store it first, and make
// sure that it gets executed when our Deferred object is resolved.
_oldOnYouTubeIframeAPIReady = window.onYouTubeIframeAPIReady || undefined;

window.onYouTubeIframeAPIReady = function() {
try { // this additional inner try/catch shouldn't really be needed but it's here just in case.
window.onYouTubeIframeAPIReady.resolve();
} catch (ytapiresolveerr) {
handleYTAPIErr(ytapiresolveerr);
}
};
window.onYouTubeIframeAPIReady = function() {
_youtubeApiDeferred.resolve();
}

window.onYouTubeIframeAPIReady.resolve = _youtubeApiDeferred.resolve;
window.onYouTubeIframeAPIReady.done = _youtubeApiDeferred.done;
window.onYouTubeIframeAPIReady.resolve = _youtubeApiDeferred.resolve;
window.onYouTubeIframeAPIReady.done = _youtubeApiDeferred.done;

if (_oldOnYouTubeIframeAPIReady) {
window.onYouTubeIframeAPIReady.done(_oldOnYouTubeIframeAPIReady);
}
} catch (ytapierr) {
handleYTAPIErr(ytapierr);
if (_oldOnYouTubeIframeAPIReady) {
window.onYouTubeIframeAPIReady.done(_oldOnYouTubeIframeAPIReady);
}

};

// If a Deferred object hasn't been created yet, create one now. It will
Expand All @@ -230,6 +204,7 @@ function(VideoPlayer, i18n, moment, _) {
window.YT.ready(onYTApiReady);
});
}

} else {
video = VideoPlayer(state);

Expand Down

0 comments on commit b37f4b7

Please sign in to comment.