1
0
mirror of https://github.com/videojs/video.js.git synced 2024-11-30 09:06:49 +02:00

Add middleware method to override currentSource()

This commit is contained in:
Sarah Rimron-Soutter 2023-01-17 14:52:52 +00:00
parent df71bb0a2c
commit 9f640c2225
3 changed files with 21 additions and 1 deletions

View File

@ -3569,7 +3569,9 @@ class Player extends Component {
* The current source object * The current source object
*/ */
currentSource() { currentSource() {
return this.cache_.source || {}; const mw = this.middleware_;
return middleware.currentSource(this.cache_.source, mw) || this.cache_.source || {};
} }
/** /**

View File

@ -82,6 +82,10 @@ export function setSource(player, src, next) {
player.setTimeout(() => setSourceHelper(src, middlewares[src.type], next, player), 1); player.setTimeout(() => setSourceHelper(src, middlewares[src.type], next, player), 1);
} }
export function currentSource(src, middleware) {
return middleware.reduceRight(middlewareIterator('currentSource'), src);
}
/** /**
* When the tech is set, passes the tech to each middleware's `setTech` method. * When the tech is set, passes the tech to each middleware's `setTech` method.
* *

View File

@ -536,3 +536,17 @@ QUnit.test('a middleware without a setSource gets chosen implicitly', function(a
middleware.getMiddleware('video/foo').pop(); middleware.getMiddleware('video/foo').pop();
}); });
QUnit.test('middleware can override currentSource', function(assert) {
const middlewares = [
{
currentSource: (src) => {
return `foo${src}`;
}
}
];
const result = middleware.currentSource('bar', middlewares);
assert.equal(result, 'foobar', 'value of currentSource() is overriden');
});