Skip to content

Commit 65a2cfd

Browse files
committed
fix: Allow muxjs to be loaded after Shaka
In PR #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 #3407 Change-Id: Ia6e0a68bea88f0cdb614e8751edc70147bc67f28
1 parent 8779715 commit 65a2cfd

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

lib/dependencies/all.js

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,23 @@ shaka.dependencies = class {
1414
* Registers a new dependency.
1515
*
1616
* @param {shaka.dependencies.Allowed} key which is used for retrieving a
17-
* dependency
17+
* dependency
1818
* @param {?} dep a dependency
1919
* @export
2020
*/
2121
static add(key, dep) {
2222
if (!shaka.dependencies.Allowed[key]) {
2323
throw new Error(`${key} is not supported`);
2424
}
25-
shaka.dependencies.dependencies_.set(key, dep);
25+
shaka.dependencies.dependencies_.set(key, () => dep);
2626
}
2727

2828
/**
29-
* Check if we have a dependency for the key
30-
* @export
29+
* Check if we have a dependency for the key.
30+
*
3131
* @param {shaka.dependencies.Allowed} key key
3232
* @return {boolean}
33+
* @export
3334
*/
3435
static has(key) {
3536
return shaka.dependencies.dependencies_.has(key);
@@ -38,16 +39,10 @@ shaka.dependencies = class {
3839
/** @return {?muxjs} */
3940
static muxjs() {
4041
return /** @type {?muxjs} */ (shaka.dependencies.dependencies_.get(
41-
shaka.dependencies.Allowed.muxjs));
42+
shaka.dependencies.Allowed.muxjs)());
4243
}
4344
};
4445

45-
/**
46-
* Contains shared dependencies that could be used by other components.
47-
* @private {!Map.<string, Object>}
48-
*/
49-
shaka.dependencies.dependencies_ = new Map();
50-
5146
/**
5247
* @export
5348
* @enum {string}
@@ -56,7 +51,12 @@ shaka.dependencies.Allowed = {
5651
muxjs: 'muxjs',
5752
};
5853

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

0 commit comments

Comments
 (0)