middleware.js

Members

static, constant allowedGetters :Object

[tech/middleware.js](https://docs.videojs.com/tech_middleware.js.html), [line 183](https://docs.videojs.com/tech_middleware.js.html#line183)

Enumeration of allowed getters where the keys are method names.

static, constant allowedMediators :Object

[tech/middleware.js](https://docs.videojs.com/tech_middleware.js.html), [line 210](https://docs.videojs.com/tech_middleware.js.html#line210)

Enumeration of allowed mediators where the keys are method names.

static, constant allowedSetters :Object

[tech/middleware.js](https://docs.videojs.com/tech_middleware.js.html), [line 199](https://docs.videojs.com/tech_middleware.js.html#line199)

Enumeration of allowed setters where the keys are method names.

Methods

static clearCacheForPlayer(player)

[tech/middleware.js](https://docs.videojs.com/tech_middleware.js.html), [line 246](https://docs.videojs.com/tech_middleware.js.html#line246)

Clear the middleware cache for a player.

Parameters:
NameTypeDescription
playerPlayer

A Player instance.

static get(middleware, tech, method) → {Mixed}

[tech/middleware.js](https://docs.videojs.com/tech_middleware.js.html), [line 115](https://docs.videojs.com/tech_middleware.js.html#line115)

Calls a getter on the tech first, through each middleware from right to left to the player.

Parameters:
NameTypeDescription
middlewareArray.<Object>

An array of middleware instances.

techTech

The current tech.

methodstring

A method name.

Returns:

Mixed -

The final value from the tech after middleware has intercepted it.

static getMiddleware(type) → {Array.<function()>|undefined}

[tech/middleware.js](https://docs.videojs.com/tech_middleware.js.html), [line 60](https://docs.videojs.com/tech_middleware.js.html#line60)

Gets middlewares by type (or all middlewares).

Parameters:
NameTypeDescription
typestring

The MIME type to match or “*” for all MIME types.

Returns:

Array.<function()> | undefined -

An array of middlewares or undefined if none exist.

static mediate(middleware, tech, method, arg) → {Mixed}

[tech/middleware.js](https://docs.videojs.com/tech_middleware.js.html), [line 165](https://docs.videojs.com/tech_middleware.js.html#line165)

Takes the argument given to the player and calls the call version of the method on each middleware from left to right.

Then, call the passed in method on the tech and return the result unchanged back to the player, through middleware, this time from right to left.

Parameters:
NameTypeDescription
middlewareArray.<Object>

An array of middleware instances.

techTech

The current tech.

methodstring

A method name.

argMixed

The value to set on the tech.

Returns:

Mixed -

The return value of the method of the tech, regardless of the return values of middlewares.

static set(middleware, tech, method, arg) → {Mixed}

[tech/middleware.js](https://docs.videojs.com/tech_middleware.js.html), [line 138](https://docs.videojs.com/tech_middleware.js.html#line138)

Takes the argument given to the player and calls the setter method on each middleware from left to right to the tech.

Parameters:
NameTypeDescription
middlewareArray.<Object>

An array of middleware instances.

techTech

The current tech.

methodstring

A method name.

argMixed

The value to set on the tech.

Returns:

Mixed -

The return value of the method of the tech.

static setSource(player, src, The)

[tech/middleware.js](https://docs.videojs.com/tech_middleware.js.html), [line 82](https://docs.videojs.com/tech_middleware.js.html#line82)

Asynchronously sets a source using middleware by recursing through any matching middlewares and calling setSource on each, passing along the previous returned value each time.

Parameters:
NameTypeDescription
playerPlayer

A Player instance.

srcTech~SourceObject

A source object.

Thefunction

next middleware to run.

static setTech(middleware, tech)

[tech/middleware.js](https://docs.videojs.com/tech_middleware.js.html), [line 95](https://docs.videojs.com/tech_middleware.js.html#line95)

When the tech is set, passes the tech to each middleware’s setTech method.

Parameters:
NameTypeDescription
middlewareArray.<Object>

An array of middleware instances.

techTech

A Video.js tech.

static use(type, middleware)

[tech/middleware.js](https://docs.videojs.com/tech_middleware.js.html), [line 46](https://docs.videojs.com/tech_middleware.js.html#line46)

Define a middleware that the player should use by way of a factory function that returns a middleware object.

Parameters:
NameTypeDescription
typestring

The MIME type to match or “*” for all MIME types.

middlewareMiddlewareFactory

A middleware factory function that will be executed for matching types.

Type Definitions

MiddlewareFactory(player)

[tech/middleware.js](https://docs.videojs.com/tech_middleware.js.html), [line 23](https://docs.videojs.com/tech_middleware.js.html#line23)

A middleware factory function that should return a MiddlewareObject.

This factory will be called for each player when needed, with the player passed in as an argument.

Parameters:
NameTypeDescription
playerPlayer

A Video.js player.

MiddlewareObject

[tech/middleware.js](https://docs.videojs.com/tech_middleware.js.html), [line 13](https://docs.videojs.com/tech_middleware.js.html#line13)

A middleware object is a plain JavaScript object that has methods that match the Tech methods found in the lists of allowed getters, setters, and mediators.