MediaKeySession Class
A key session of a MediaKeys object (https://w3c.github.io/encrypted-media/#mediakeysession-interface): the application generates a license request from Initialization Data (MediaKeySession.GenerateRequest), sends the message event to the license server, and gives the license to MediaKeySession.Update. With Clear Key, the license is a JSON Web Key Set that contains the keys.
public sealed class MediaKeySession : EventTarget- Inheritance
EventTargetMediaKeySession
Properties
| Name | Description |
|---|---|
| Closed | Gets the task that completes with the reason when the session is closed (it never fails). |
| Expiration | Gets the expiration time of the keys, in milliseconds since the epoch, or NaN (always NaN with Clear Key). |
| KeyStatuses | Gets the statuses of the keys known to the session. |
| OnKeyStatusesChange | Gets or sets the event handler of the keystatuseschange event. |
| OnMessage | Gets or sets the event handler of the message event. |
| SessionId | Gets the session ID, or the empty string until the license request is generated or the session is loaded. |
Closed
MediaKeySession.csGets the task that completes with the reason when the session is closed (it never fails).
public Task<MediaKeySessionClosedReason> Closed { get; }Expiration
MediaKeySession.csGets the expiration time of the keys, in milliseconds since the epoch, or NaN (always NaN with Clear Key).
public double Expiration { get; }KeyStatuses
MediaKeySession.csGets the statuses of the keys known to the session.
public MediaKeyStatusMap KeyStatuses { get; }Property value
See also
OnKeyStatusesChange
MediaKeySession.csGets or sets the event handler of the keystatuseschange event.
OnMessage
MediaKeySession.csGets or sets the event handler of the message event.
Property value
See also
SessionId
MediaKeySession.csGets the session ID, or the empty string until the license request is generated or the session is loaded.
public string SessionId { get; }Methods
| Name | Description |
|---|---|
| Close() | Closes the session (https://w3c.github.io/encrypted-media/#dom-mediakeysession-close): its keys are no longer usable, and MediaKeySession.Closed completes with MediaKeySessionClosedReason.ClosedByApplication. The data of a persistent session stays stored. |
| GenerateRequest(string, ReadOnlySpan<byte>) | Generates a license request from Initialization Data (https://w3c.github.io/encrypted-media/#dom-mediakeysession-generaterequest): the request is the MediaKeyMessageEvent fired once the task completes. With Clear Key, the request lists the key IDs of the Initialization Data. The task fails with a TypeErrorException when the data is empty or invalid, a NotSupportedError when the type is not supported or the data has no key ID for Clear Key, and an InvalidStateError when the session is already initialized or closed. |
| Load(string) | Loads the data stored for a persistent session (https://w3c.github.io/encrypted-media/#dom-mediakeysession-load): the task completes with false when no data is stored for the session ID. The keys of the license are usable; a session whose license was removed has its record of license destruction, sent again as a license-release message. |
| Remove() | Removes the license and the keys of the session (https://w3c.github.io/encrypted-media/#dom-mediakeysession-remove): the key statuses are cleared. A persistent session stores a record of license destruction, sent as a license-release message until its acknowledgement is given to MediaKeySession.Update. |
| Update(ReadOnlySpan<byte>) | Provides a message of the license server to the CDM (https://w3c.github.io/encrypted-media/#dom-mediakeysession-update): with Clear Key, a license (a JSON Web Key Set, https://w3c.github.io/encrypted-media/#clear-key-license-format) whose keys become usable, or the acknowledgement of a license release, which closes the session. The task fails with a TypeErrorException when the response is empty or invalid, and an InvalidStateError when the session has no license request or is closed. |
Close()
MediaKeySession.csCloses the session (https://w3c.github.io/encrypted-media/#dom-mediakeysession-close): its keys are no longer usable, and MediaKeySession.Closed completes with MediaKeySessionClosedReason.ClosedByApplication. The data of a persistent session stays stored.
public Task Close()GenerateRequest(string, ReadOnlySpan<byte>)
MediaKeySession.csGenerates a license request from Initialization Data (https://w3c.github.io/encrypted-media/#dom-mediakeysession-generaterequest): the request is the MediaKeyMessageEvent fired once the task completes. With Clear Key, the request lists the key IDs of the Initialization Data. The task fails with a TypeErrorException when the data is empty or invalid, a NotSupportedError when the type is not supported or the data has no key ID for Clear Key, and an InvalidStateError when the session is already initialized or closed.
public Task GenerateRequest(string initDataType, ReadOnlySpan<byte> initData)Parameters
initDataTypestring- The Initialization Data Type:
cenc,keyidsorwebm. initDataReadOnlySpan<byte>- The Initialization Data.
Returns
See also
Load(string)
MediaKeySession.csLoads the data stored for a persistent session (https://w3c.github.io/encrypted-media/#dom-mediakeysession-load): the task completes with false when no data is stored for the session ID. The keys of the license are usable; a session whose license was removed has its record of license destruction, sent again as a license-release message.
Remove()
MediaKeySession.csRemoves the license and the keys of the session (https://w3c.github.io/encrypted-media/#dom-mediakeysession-remove): the key statuses are cleared. A persistent session stores a record of license destruction, sent as a license-release message until its acknowledgement is given to MediaKeySession.Update.
public Task Remove()Update(ReadOnlySpan<byte>)
MediaKeySession.csProvides a message of the license server to the CDM (https://w3c.github.io/encrypted-media/#dom-mediakeysession-update): with Clear Key, a license (a JSON Web Key Set, https://w3c.github.io/encrypted-media/#clear-key-license-format) whose keys become usable, or the acknowledgement of a license release, which closes the session. The task fails with a TypeErrorException when the response is empty or invalid, and an InvalidStateError when the session has no license request or is closed.
public Task Update(ReadOnlySpan<byte> response)Parameters
responseReadOnlySpan<byte>- The response (UTF-8 JSON for Clear Key, at most 64 KiB).