Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Catch and retry video module YT IFrame API ready errs #1361

Merged
merged 2 commits into from
Jul 20, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion common/lib/xmodule/xmodule/js/src/video/01_initialize.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ function(VideoPlayer, i18n, moment, _) {

_youtubeApiDeferred = null,
_oldOnYouTubeIframeAPIReady;
const setupOnYouTubeIframeAPIReadyMaxCalls=3;

Initialize.prototype = methodsDict;

Expand Down Expand Up @@ -165,14 +166,32 @@ function(VideoPlayer, i18n, moment, _) {
//
// 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.');
}

_oldOnYouTubeIframeAPIReady = window.onYouTubeIframeAPIReady || undefined;

window.onYouTubeIframeAPIReady = function() {
window.onYouTubeIframeAPIReady.resolve();
};

window.onYouTubeIframeAPIReady.resolve = _youtubeApiDeferred.resolve;
try {
window.onYouTubeIframeAPIReady.resolve = _youtubeApiDeferred.resolve;
} catch (e) {
console.error('Error while trying to resolve the Deferred object responsible for calling OnYouTubeIframeAPIReady callbacks.');
console.error(e);
if (e instanceof TypeError) {
setupOnYouTubeIframeAPIReady(); // Try again up to defined max calls.
}
else {
throw e;
}
}
window.onYouTubeIframeAPIReady.done = _youtubeApiDeferred.done;

if (_oldOnYouTubeIframeAPIReady) {
Expand Down