Constructor
new Player(target, mediaData, playerConfigopt)
Creates a new Player instance.
| Name | Type | Attributes | Description |
|---|---|---|---|
target |
string | HTMLElement |
HTML element (or a selector) to which the player should be attached to (or which should be replaced). |
|
mediaData |
Object |
The media data object. |
|
playerConfig |
Object | optional |
Player configuration object. |
- Throws
-
If player id is invalid.
Type Error -
If query selector is invalid.
Type Error -
If player config is invalid.
Type Error
Members
private #config :Object
Holds the global player configuration as the central storage.
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
secureApi
|
boolean | optional | false | If secure mode is enabled, certain APIs are restricted to internal use, like getComponents(), getElement() or getMediaElement(). In addition, the instance is sealed after components are intialised. |
id
|
string | optional | '' | Defines custom player id. To be used in conjunction with the pubsub event system to access events outside the player instance. If omitted, the id will be autogenerated. |
initOnIntersection
|
boolean | Player~intersectionObserverConfig | optional | false | Intersection Observer config. If |
initOnIdle
|
boolean | optional | false | If |
private #id :string
Internal client ID, used for connecting via PubSub. Can be generated internally or filled with a custom value when instantiating.
private #apiKey :symbol
Secret key only known to the player instance and initialized components. Used to be able to restrict access to API methods in conjunction with secure mode.
private #privateApi :Object
Holds functions provided by other components which are private to this class.
private #components :Map
private #namespaces :Set
Stores references to any namesets that+0may have been created using addApi().
Used to freeze namespaces in secure mode.
private #apiMethods :Map
private #state :Object
private #client :Object
Object containing various information about the client. Can be used by other components for feature detection etc.
private #intersectionObserver :IntersectionObserver
private #idleCallback :number
private, static #formats :Array<Player~mediaFormat>
Array holding supported media formats, containing associated extensions and mime type.
- Type
- Array<Player~mediaFormat>
- Source
- Player.js, line 589
private, static #registeredComponents :Object
Holds component objects available to be initialized with each player instance.
private, static #defaultConfig :Object
private, static #idCounter :number
Methods
private #initialise(mergedData)
Initializes the player. May be invoked by intersection observer or directly.
| Name | Type | Description |
|---|---|---|
mergedData |
Object |
The merged media data. |
private #launchComponents(parent, registeredTree, activeTree)
Launches all registered components by recursively walking the component tree.
| Name | Type | Description |
|---|---|---|
parent |
Object |
Parent component (equals |
registeredTree |
Map |
Static "component registry" in Player.components. |
activeTree |
Map |
Tree of currently instantiated components (under |
private #removeComponents(compsopt, excludesopt)
Recursively removes components from the component tree, optionally excluding a certain key.
| Name | Type | Attributes | Description |
|---|---|---|---|
comps |
Object | optional |
The sub-tree of components to remove. |
excludes |
Array<string> | optional |
If specified, skip removing components. |
getComponent(componentPath, apiKey) → Object|false
Returns a "live" component instance by a path. Not recommended for external usage.
| Name | Type | Description |
|---|---|---|
componentPath |
string |
The path to the desired component, e.g. "ui.scrubber". |
apiKey |
symbol |
Token needed to grant access in secure mode. |
initConfig(key, defaultsopt) → Object
Initializes a configuration section. If the property does not exist yet, it is created using the provided defaults. Used by components to retrieve and initialize their individual configuration.
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
key |
string |
The configuration key to initialize. |
||
defaults |
Object | optional | true |
The default values to apply (used with |
getConfig(searchPathopt) → nullable Object
Gets the current config, as a whole or just a fragment based on the searchPath.
| Name | Type | Attributes | Description |
|---|---|---|---|
searchPath |
string | optional |
If provided, only return a fragment of the config matching the key. The key can also hold "sub-paths", which are separated by a dot. Example: |
setConfig(config, reinitializeopt)
Extends the existing config with the provided object. Optionally re-initializes the player.
| Name | Type | Attributes | Description |
|---|---|---|---|
config |
string | Object |
The config object. |
|
reinitialize |
boolean | optional |
If |
getClient(keyopt) → Object|boolean
Returns player client information, either a property selected by the key or a clone of the whole client object.
| Name | Type | Attributes | Description |
|---|---|---|---|
key |
string | optional |
The key of the desired client property. |
getState(namespaceopt) → Object|any
Returns player state, either a property selected by the key or a clone of the whole state object.
| Name | Type | Attributes | Description |
|---|---|---|---|
namespace |
string | optional |
The namespace of the desired state property. |
setState(namespace, descriptor, apiKey)
Adds an additional state to the state object.
| Name | Type | Description |
|---|---|---|
namespace |
string |
The namespace of the new state. |
descriptor |
Object |
A property descriptor which must contain a getter that returns the state value. State properties should be readonly, so a setter should not be defined. |
apiKey |
symbol |
Token needed to grant access in secure mode. |
removeState(namespaces, apiKey)
Removes one or more states from the state object.
| Name | Type | Description |
|---|---|---|
namespaces |
Array | string |
The namespace(s) of the state property to be removed. |
apiKey |
symbol |
Token needed to grant access in secure mode. |
static setApi(namespace, method, isPrivateopt, apiKeyopt)
Adds a component method to the player API. This method adds the api method to the instance, as opposed to Player.setApi, which adds an API method to the Class itself. NOTE: This does not check for existing methods with the same name, effectively allowing to override the API.
| Name | Type | Attributes | Description |
|---|---|---|---|
namespace |
string |
The API name(space) of the method. |
|
method |
function |
A reference to the method itself. |
|
isPrivate |
boolean | optional |
If |
apiKey |
symbol | optional |
Token for extended access to the player API. |
static removeApi(namespaces, apiKey)
Removes a method from the players' instance API.
| Name | Type | Description |
|---|---|---|
namespaces |
Array | string |
The name(space)s of the method to remove. |
apiKey |
symbol |
Token needed to grant access in secure mode. |
subscribe(topic, handler, optionsopt) → number
This should be used by all components when subscribing to some events.
In essence this just calls the external publisher library, but prefixes each event topic
with 'vip' and the player id, so that they don't need to be added each time manually.
| Name | Type | Attributes | Description | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
topic |
string |
The topic in which the subscriber is interested. Note that you can use wildcards, ie. The topic |
|||||||||||||||||||||||||
handler |
function |
The handler to execute when a matching message is found. |
|||||||||||||||||||||||||
options |
Object | optional |
Additional options.
|
unsubscribe(topicOrToken, handleropt)
This should be used by all components when UNsubscribing some events. In essence this just calls the external publisher library, but prefixes each event topic with "vip" and the player id, so that they don't need to be added each time manually.
| Name | Type | Attributes | Description |
|---|---|---|---|
topicOrToken |
number | string | Array |
The token or the topic to unsubscribe. In the first case, these also can be in an array to support multiple unsubscriptions. |
|
handler |
function | optional |
If specified, the message is only unsubscribed if the handler also matches. |
publish(topic, dataopt, optionsopt, apiKeyopt)
Publishes a message to all matching subscribers. In essence this just calls the external publisher library, but prefixes each event topic with "vip" and the player id, so that they don't need to be added each time manually.
| Name | Type | Attributes | Default | Description | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
topic |
string |
The topic of this message, may be separated with |
||||||||||||||||||||||
data |
Object | optional |
The data that should be sent along with the event. Can be basically any javascript object. |
|||||||||||||||||||||
options |
Object | optional | {} |
Additional options.
|
||||||||||||||||||||
apiKey |
symbol | optional |
Token for extended access to the player API. |
destroy()
This is the "cleanup method" which should be called when removing the player. It is strongly recommended to do so to prevent memory leaks and possible other unwanted side effects. This method removes all component, as well as the player root element.
static addComponent(path, Component, configopt)
Adds (registers) a new component. This method must be invoked on the Class itself, and only components added before creating a player instance will be considered.
| Name | Type | Attributes | Description |
|---|---|---|---|
path |
string |
The path of the component to add. Path segments are separated by |
|
Component |
Object |
The component object or class to be added. |
|
config |
Object | optional |
Additional component config to be injected at build time. |
static removeComponent(path)
Removes a component from the global registry. This method must be invoked on the constructor, not the instance. Only components added before creating a player instance will be considered.
| Name | Type | Description |
|---|---|---|
path |
string |
The path of the component to add. Path segments are separated by ".". |
static setApi(key, method)
Adds a component method to the player API. This method adds the api method to the Class, as opposed to the instance setApi method (see below), which adds an API method to the instance. Warning: this does not check for existing methods with the same name, effectively allowing to override the API.
| Name | Type | Description |
|---|---|---|
key |
string |
The API name of the method. |
method |
function |
A reference to the method itself. |
static removeApi(key)
Removes a method from the players' Class API.
| Name | Type | Description |
|---|---|---|
key |
string |
The name of the method to remove. |
static setDefaultConfig(config)
Sets the default config for new Player instances.
| Name | Type | Description |
|---|---|---|
config |
Object |
The default config to set globally. |
static getFormats() → Array<Player~mediaFormat>
Returns a cloned list of all supported media formats. This list defines which file extensions and MIME types are recognized by the player. Formats can be audio, video, or both. Use this method for inspection or debugging purposes.
- Returns
-
A deep clone of the registered format definitions.
- Type Array<Player~mediaFormat>
- Source
- Player.js, line 759
static addFormat(format)
Adds a new format definition to the global format registry. This allows components to register support for additional media types. The format object should contain at least one file extension and a MIME type for either audio or video.
| Name | Type | Description |
|---|---|---|
format |
Player~mediaFormat |
The format object to register. |
static autoLoad(selector)
Tries to query and convert HTML Elements that match a certain selector into VisionPlayer instances. Also tries to extract config and Media Data.
| Name | Type | Default | Description |
|---|---|---|---|
selector |
string | [data-vision-player] |
The selector to apply. |
private, static #extractElementData(ele) → Object
Parses elements and extracts meta- and config data. Looks for data-vip-media and data-vip-config attributes and tries to parse them as string or JSON.
If ele is a video or audio element, also tries to get the media data from additional element properties, including subtitles and poster image.
| Name | Type | Description |
|---|---|---|
ele |
HTMLElement |
The element to parse. |
Type Definitions
intersectionObserverConfig
Defines the Intersection Observer config.
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
root
|
HTMLElement | optional | document | The root element to observe. |
rootMargin
|
string | optional | '250px' | The margin around the root element. |
scrollMargin
|
string | optional | '0px' | The margin around the scroll container. |
threshold
|
number | optional | 0 | The threshold for the intersection ratio. |
mediaFormat
Defines a supported media format for the player. A format is characterized by its file extensions and optionally by the MIME type for audio and/or video. This structure is used by the player to detect whether a given media file is supported natively or by a plugin.
| Name | Type | Attributes | Description |
|---|---|---|---|
extensions
|
Array<string> | List of associated file extensions (e.g. |
|
mimeTypeAudio
|
string | optional | Optional MIME type for audio streams (e.g. |
mimeTypeVideo
|
string | optional | Optional MIME type for video streams (e.g. |