Skip to content

Commit

Permalink
fix(preload): Copy net filters to preload manager (#6709)
Browse files Browse the repository at this point in the history
Some assets might rely on networking engine filters (request and
response filters) to properly download their assets. However, the
preload manager's need to use a fresh networking engine also caused it
to not use any filters set on the player already. This changes the
process of setting up a preload manager, to make it copy over any
filters defined on the player's networking engine.

Fixes #6698
  • Loading branch information
theodab authored May 30, 2024
1 parent 8420c20 commit 1cfb53e
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 0 deletions.
2 changes: 2 additions & 0 deletions docs/tutorials/preload.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ You need a player instance to preload an asset, and you must use the returned
preloadManager on the same player instance.
The preloading process loads the manifest and first segments of the asset. It
will not load the whole asset ahead of time.
If you need to define any response or request filters for your assets to be
downloaded, remember to do it before calling `player.preload`.

The preload method can be provided an optional startTime and mimeType parameter,
much the same as the load method.
Expand Down
13 changes: 13 additions & 0 deletions lib/net/networking_engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,19 @@ shaka.net.NetworkingEngine = class extends shaka.util.FakeEventTarget {
delete shaka.net.NetworkingEngine.schemes_[scheme];
}

/**
* Copies all of the filters from this networking engine into another.
* @param {!shaka.net.NetworkingEngine} other
*/
copyFiltersInto(other) {
for (const filter of this.requestFilters_) {
other.requestFilters_.add(filter);
}
for (const filter of this.responseFilters_) {
other.responseFilters_.add(filter);
}
}

/**
* Registers a new request filter. All filters are applied in the order they
* are registered.
Expand Down
1 change: 1 addition & 0 deletions lib/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -2107,6 +2107,7 @@ shaka.Player = class extends shaka.util.FakeEventTarget {
// Sadly, as the network engine creation code must be replaceable by tests,
// it cannot be made and use the utilities defined in this function.
const networkingEngine = this.createNetworkingEngine(getPreloadManager);
this.networkingEngine_.copyFiltersInto(networkingEngine);

/** @return {!shaka.media.DrmEngine} */
const createDrmEngine = () => {
Expand Down
11 changes: 11 additions & 0 deletions test/test/util/fake_networking_engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,17 @@ shaka.test.FakeNetworkingEngine = class {
return new shaka.util.AbortableOperation(asyncOp(), abortOp);
}

/**
* @param {!shaka.net.NetworkingEngine} other
* @override
*/
copyFiltersInto(other) {
if (this.responseFilter_) {
other.registerResponseFilter(this.responseFilter_);
}
// FakeNetworkingEngine does not have request filters.
}

/**
* Useable by tests directly. Library code will only call this via the Spy on
* registerResponseFilter.
Expand Down

0 comments on commit 1cfb53e

Please sign in to comment.