mirror of
https://github.com/videojs/video.js.git
synced 2024-11-28 08:58:46 +02:00
Add middleware method to override currentSource()
This commit is contained in:
parent
df71bb0a2c
commit
9f640c2225
@ -3569,7 +3569,9 @@ class Player extends Component {
|
||||
* The current source object
|
||||
*/
|
||||
currentSource() {
|
||||
return this.cache_.source || {};
|
||||
const mw = this.middleware_;
|
||||
|
||||
return middleware.currentSource(this.cache_.source, mw) || this.cache_.source || {};
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -82,6 +82,10 @@ export function setSource(player, src, next) {
|
||||
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.
|
||||
*
|
||||
|
@ -536,3 +536,17 @@ QUnit.test('a middleware without a setSource gets chosen implicitly', function(a
|
||||
|
||||
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');
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user