Skip to content

Module: src/settings/Language

The Language component provides a UI that displays the current media (audio) language, and allows the user to change the language using a menu.

Version
1.0.0
Author
Frank Kudermann - alphanull
License
MIT
Requires
Menu
Source
Language.js, line 11

Constructor

new Language(player, parent, optionsopt)

Creates an instance of the Language component.

Parameters:
Name Type Attributes Description
player Player

Reference to the media player instance.

parent Popup

Reference to the parent instance (In this case the language popup).

options Object optional

Additional options.

Parameters:
Name Type Attributes Description
apiKey symbol optional

Token for extended access to the player API.

Members

Holds the configuration options for the Language component.

Properties
Name Type Attributes Default Description
showPlaceholder boolean optional false

If enabled, display a 'not available' placeholder text if no languages are available, otherwise completely hide the menu.

Type
Object
Source
Language.js, line 18

Reference to the main player instance.

Type
Player
Source
Language.js, line 26

Reference to the parent instance.

Type
Controller
Source
Language.js, line 32

Holds tokens of subscriptions to player events, for later unsubscribe.

Type
Array<number>
Source
Language.js, line 38

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.

Type
symbol
Source
Language.js, line 45

Array of available language objects.

Type
Array<Language~langObj>
Source
Language.js, line 57

The currently selected language.

Type
Language~langObj
Source
Language.js, line 63

Flag indicating if an external update (e.g. From another component) triggered the language change.

Type
boolean
Source
Language.js, line 69

Methods

private #onDataSource(metaData)

Called when a media source has been selected.

Parameters:
Name Type Description
metaData Media~metaData

The new media item data.

Listens
data/source
Source
Language.js, line 117

private #onDataReady(mediaData)

Sets up the component as soon as the media data is available.

Parameters:
Name Type Description
mediaData Object

The data object containing media variants.

Parameters:
Name Type Description
variants Array

Array of variants.

Listens
data/ready
Source
Language.js, line 129

private #onLanguageUpdate(data)

Handles the "language/update" event. Used by Dash and Hls to update the menu with information gathered from the manifests In this case, "externalUpdate" is set to true, so a selection of the language will not use the internal data, but rather delegated to the respective (streaming) component.

Parameters:
Name Type Description
data Object

Object containing updated language information.

Parameters:
Name Type Description
languages Array<Language~langObj>

Array of language objects, containing language code, id and name (optional).

current Language~langObj

The currently selected language, containing language code and id (optional).

Listens
language/update
Source
Language.js, line 153

private #mapLanguages(languages) → Array<Language~langObj>

Maps languages array to internal format, adding localized labels.

Parameters:
Name Type Description
languages Array<string>

Array with language codes to map.

Returns

The mapped array.

Type Array<Language~langObj>
Source
Language.js, line 168

private #updateMenu(metaData)

Updates the language menu to reflect the current language selection.

Parameters:
Name Type Description
metaData Media~metaData

The updated stream object.

Listens
language/active
media/ready
Source
Language.js, line 191

private #toggleLanguage(langObj)

Handler called when the user changes language in the menu.

Parameters:
Name Type Description
langObj Language~langObj

The language code to set.

Fires
language/selected
quality/language/refresh
Source
Language.js, line 209

destroy()

This method removes all events, subscriptions and DOM nodes created by this component.

Source
Language.js, line 234

Type Definitions

A single language data object.

Properties
Name Type Attributes Description
language string

The language code.

langId string optional

The language id (used with Dash and Hls to switch streams correctly).

langName string optional

The language name (used for getting additional labelling information).

Type
Object
Source
Language.js, line 264

Events

language/selected

This event is fired when the media (audio) language is changed by the user.

Parameters:
Name Type Description
langObj Language~langObj

The selected language.

Listeners
Dash#onLanguageSelected
Hls#onLanguageSelected
Source
Language.js, line 244

language/active

The Language component listens for this event to react to outside changes to the current lang. Updates the menu accordingly. Used mainly for external control by components as dash and hls.

Parameters:
Name Type Description
langObj Language~langObj

The selected language.

Listeners
Language#updateMenu
Source
Language.js, line 250

language/update

The Language component listens for this event to react to outside changes to the available languages. Rebuilds the menu accordingly. Used mainly for external control by components as dash and hls.

Parameters:
Name Type Description
languages Array<Language~langObj>

Array with available languages.

Listeners
Language#onLanguageUpdate
Source
Language.js, line 257