The MediaKeySession interface of the Encrypted Media Extensions API represents a context for message exchange with a content decryption module (CDM). Available only in secure contexts.

MDN Reference

interface MediaKeySession {
    closed: Promise<MediaKeySessionClosedReason>;
    expiration: number;
    keyStatuses: MediaKeyStatusMap;
    onkeystatuseschange: ((this: MediaKeySession, ev: Event) => any) | null;
    onmessage:
        | ((this: MediaKeySession, ev: MediaKeyMessageEvent) => any)
        | null;
    sessionId: string;
    addEventListener<K extends keyof MediaKeySessionEventMap>(
        type: K,
        listener: (this: MediaKeySession, ev: MediaKeySessionEventMap[K]) => any,
        options?: boolean | AddEventListenerOptions,
    ): void;
    addEventListener(
        type: string,
        listener: EventListenerOrEventListenerObject,
        options?: boolean | AddEventListenerOptions,
    ): void;
    close(): Promise<void>;
    dispatchEvent(event: Event): boolean;
    generateRequest(
        initDataType: string,
        initData: BufferSource,
    ): Promise<void>;
    load(sessionId: string): Promise<boolean>;
    remove(): Promise<void>;
    removeEventListener<K extends keyof MediaKeySessionEventMap>(
        type: K,
        listener: (this: MediaKeySession, ev: MediaKeySessionEventMap[K]) => any,
        options?: boolean | EventListenerOptions,
    ): void;
    removeEventListener(
        type: string,
        listener: EventListenerOrEventListenerObject,
        options?: boolean | EventListenerOptions,
    ): void;
    update(response: BufferSource): Promise<void>;
}
Hierarchy
  • EventTarget
    • MediaKeySession
Index

Properties

The closed read-only property of the MediaKeySession interface returns a Promise signaling when a MediaKeySession closes.

MDN Reference

expiration: number

The expiration read-only property of the MediaKeySession interface returns the time after which the keys in the current session can no longer be used to decrypt media data, or NaN if no such time exists.

MDN Reference

keyStatuses: MediaKeyStatusMap

The keyStatuses read-only property of the MediaKeySession interface returns a reference to a read-only MediaKeyStatusMap of the current session's keys and their statuses.

MDN Reference

onkeystatuseschange: ((this: MediaKeySession, ev: Event) => any) | null
onmessage: ((this: MediaKeySession, ev: MediaKeyMessageEvent) => any) | null
sessionId: string

The sessionId read-only property of the MediaKeySession interface contains a unique string generated by the content decryption module (CDM) for the current media object and its associated keys or licenses.

MDN Reference

Methods

  • The close() method of the MediaKeySession interface notifies that the current media session is no longer needed, and that the content decryption module should release any resources associated with this object and close it.

    MDN Reference

    Returns Promise<void>

  • The dispatchEvent() method of the EventTarget sends an Event to the object, (synchronously) invoking the affected event listeners in the appropriate order.

    MDN Reference

    Parameters

    • event: Event

    Returns boolean

  • The generateRequest() method of the MediaKeySession interface returns a Promise after generating a license request based on initialization data.

    MDN Reference

    Parameters

    Returns Promise<void>

  • The load() method of the MediaKeySession interface returns a Promise that resolves to a boolean value after loading data for a specified session object.

    MDN Reference

    Parameters

    • sessionId: string

    Returns Promise<boolean>

  • The remove() method of the MediaKeySession interface returns a Promise after removing any session data associated with the current object.

    MDN Reference

    Returns Promise<void>

  • The removeEventListener() method of the EventTarget interface removes an event listener previously registered with EventTarget.addEventListener() from the target.

    MDN Reference

    Type Parameters

    Parameters

    Returns void

  • The removeEventListener() method of the EventTarget interface removes an event listener previously registered with EventTarget.addEventListener() from the target.

    MDN Reference

    Parameters

    Returns void

  • The update() method of the MediaKeySession interface loads messages and licenses to the CDM, and then returns a Promise.

    MDN Reference

    Parameters

    Returns Promise<void>