Skip to content

Commit

Permalink
fix: Allow muxjs to be loaded after Shaka
Browse files Browse the repository at this point in the history
In PR shaka-project#2683, a dependency-injection system was added to Shaka Player.
However, it would capture default deps from a global scope at
load-time.  This introduced an accidental ordering requirement where
muxjs would have to be loaded first.  This was not required in v3.0.x,
so it should not have become a requirement in v3.1.

To fix this issue, dependencies are now stored as lazy callbacks.  So
long as muxjs is loaded before Shaka Player tries to play TS content,
it no longer matters when they each were loaded into the page.  This
restores the v3.0.x behavior without breaking the dependency-injection
system or its API.

Closes shaka-project#3407

Change-Id: Ia6e0a68bea88f0cdb614e8751edc70147bc67f28
  • Loading branch information
joeyparrish committed May 14, 2021
1 parent 8779715 commit 65a2cfd
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions lib/dependencies/all.js
Expand Up @@ -14,22 +14,23 @@ shaka.dependencies = class {
* Registers a new dependency.
*
* @param {shaka.dependencies.Allowed} key which is used for retrieving a
* dependency
* dependency
* @param {?} dep a dependency
* @export
*/
static add(key, dep) {
if (!shaka.dependencies.Allowed[key]) {
throw new Error(`${key} is not supported`);
}
shaka.dependencies.dependencies_.set(key, dep);
shaka.dependencies.dependencies_.set(key, () => dep);
}

/**
* Check if we have a dependency for the key
* @export
* Check if we have a dependency for the key.
*
* @param {shaka.dependencies.Allowed} key key
* @return {boolean}
* @export
*/
static has(key) {
return shaka.dependencies.dependencies_.has(key);
Expand All @@ -38,16 +39,10 @@ shaka.dependencies = class {
/** @return {?muxjs} */
static muxjs() {
return /** @type {?muxjs} */ (shaka.dependencies.dependencies_.get(
shaka.dependencies.Allowed.muxjs));
shaka.dependencies.Allowed.muxjs)());
}
};

/**
* Contains shared dependencies that could be used by other components.
* @private {!Map.<string, Object>}
*/
shaka.dependencies.dependencies_ = new Map();

/**
* @export
* @enum {string}
Expand All @@ -56,7 +51,12 @@ shaka.dependencies.Allowed = {
muxjs: 'muxjs',
};

// Add global muxjs object for backward compatibility
shaka.dependencies.dependencies_.set(
shaka.dependencies.Allowed.muxjs,
window.muxjs);
/**
* Contains accessor functions to shared dependencies that could be used by
* other components. The default accessors can be overridden.
*
* @private {!Map.<shaka.dependencies.Allowed, function():?>}
*/
shaka.dependencies.dependencies_ = new Map([
[shaka.dependencies.Allowed.muxjs, () => window.muxjs],
]);

0 comments on commit 65a2cfd

Please sign in to comment.