- Version
- 1.0.0
- License
- MIT
- Requires
- ExtendedMediaError
- Source
- FairPlay.js, line 59
Constructor
new FairPlay(player, mediaComponent, apiKey)
Members
private #player :Player
Reference to the main player instance.
- Type
- Player
- Source
- FairPlay.js, line 65
private #videoEle :HTMLVideoElement
Reference to the video Element.
- Type
- HTMLVideoElement
- Source
- FairPlay.js, line 71
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.
- Type
- symbol
- Source
- FairPlay.js, line 78
private #licenseUrl :string
License server URL.
- Type
- string
- Source
- FairPlay.js, line 84
private #headers :Object<string, string>
License request headers.
- Type
- Object<string, string>
- Source
- FairPlay.js, line 90
private #keySession :MediaKeySession
The current MediaKeySession instance.
- Type
- MediaKeySession
- Source
- FairPlay.js, line 96
private #resolve :function
The resolve callback to unblock media.load().
- Type
- function
- Source
- FairPlay.js, line 102
Methods
private, static stringToUint16Array(string) → Uint16Array
Converts a string to a Uint16Array.
| Name | Type | Description |
|---|---|---|
string |
string |
Input string. |
- Returns
-
Converted array.
- Type Uint16Array
- Source
- FairPlay.js, line 10
private, static uInt16arrayToString(array) → string
Converts a Uint16Array to a string.
| Name | Type | Description |
|---|---|---|
array |
Uint16Array |
Input array. |
- Returns
-
Converted string.
- Type string
- Source
- FairPlay.js, line 19
private, static uInt8ArrayToString(array) → string
Converts a Uint8Array to a string.
| Name | Type | Description |
|---|---|---|
array |
Uint8Array |
Input array. |
- Returns
-
Converted string.
- Type string
- Source
- FairPlay.js, line 28
private, static base64DecodeUint8Array(input) → Uint8Array
Decodes a base64-encoded string into a Uint8Array.
| Name | Type | Description |
|---|---|---|
input |
string |
Input string. |
- Returns
-
Converted array.
- Type Uint8Array
- Source
- FairPlay.js, line 37
private, static base64EncodeUint8Array(input) → string
Encodes a Uint8Array into base64 string.
| Name | Type | Description |
|---|---|---|
input |
Uint8Array |
Input array. |
- Returns
-
Converted string.
- Type string
- Source
- FairPlay.js, line 46
canPlay(metaData) → string
Checks if this plugin can handle a given MIME type and DRM system.
| Name | Type | Description | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
metaData |
Media~metaData |
The data to test.
|
- Returns
-
"maybe" if playable, otherwise an empty string.
- Type string
- Source
- FairPlay.js, line 134
async load(metaData)
Initializes the FairPlay session if the source is HLS and has FairPlay DRM. Loads the certificate if not provided inline, sets up the video src, and waits for "webkitneedkey" event to start encryption handling.
| Name | Type | Description | ||||||
|---|---|---|---|---|---|---|---|---|
metaData |
Media~metaData |
metaData to load.
|
- Throws
-
If not Safari or .m3u8 or lacking 'drm.FairPlay'.
Type Error - Source
- FairPlay.js, line 147
async, private #encrypted(event, certificate) → Promise<void>
Initializes and prepares the FairPlay key session.
| Name | Type | Description |
|---|---|---|
event |
Event |
The "webkitneedkey" event. |
certificate |
Uint8Array |
The DRM certificate. |
- Returns
- Type Promise<void>
- Throws
-
If creating mediaKeys or the key sessions fails for any reason.
Type Error - Source
- FairPlay.js, line 192
private #keyMessage(event)
Handles license requests when "webkitkeymessage" event is fired.
| Name | Type | Description |
|---|---|---|
event |
Event |
Event containing the license challenge. |
- Source
- FairPlay.js, line 228
private #keyAdded()
Called when "webkitkeyadded" fires, meaning the DRM session is successfully set up.
- Source
- FairPlay.js, line 242
private #keyError()
Called when "webkitkeyerror" fires, meaning the DRM session encountered an error.
- Throws
-
If a key session error code is found.
Type Error - Source
- FairPlay.js, line 252
destroy()
This method removes all events, subscriptions and DOM nodes created by this component.
- Source
- FairPlay.js, line 262
async, private, static #loadCertificate(certificateUrl) → Promise<Uint8Array>
Loads the FairPlay DRM certificate from the specified URL.
| Name | Type | Description |
|---|---|---|
certificateUrl |
string |
URL to the DRM certificate. |
- Returns
-
The fetched certificate as Uint8Array.
- Type Promise<Uint8Array>
- Source
- FairPlay.js, line 279
private, static #createSpc(contentId, initData, cert) → Uint8Array
Creates the FairPlay "SPC" message to request a license.
| Name | Type | Description |
|---|---|---|
contentId |
string |
Content identifier (from SKD URL). |
initData |
Uint8Array |
Initialization data. |
cert |
Uint8Array |
DRM certificate. |
- Returns
-
SPC request message.
- Type Uint8Array
- Source
- FairPlay.js, line 297
async, private, static #getLicense(event, spcPath, headers) → Promise<Uint8Array>
Fetches the license by sending the SPC message to the DRM license server. Expects a base64-encoded response.
| Name | Type | Description |
|---|---|---|
event |
Event |
The webkitkeymessage event containing the message. |
spcPath |
string |
The license server url. |
headers |
Object<string, string> |
HTTP headers for the license request. |
- Returns
-
The license data.
- Type Promise<Uint8Array>
- Source
- FairPlay.js, line 338