---
title: "MediaKeySession | JavaScript maps SDK"
description: "Documentation for MapTiler SDK"
---

> For AI agents: a documentation index is available at [/llms.txt](https://docs.maptiler.com/llms.txt). Markdown versions of all pages are available by appending .md to any URL.

# Interface MediaKeySession

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](https://developer.mozilla.org/docs/Web/API/MediaKeySession)

interface MediaKeySession {  
    [closed](#closed): Promise<[MediaKeySessionClosedReason](https://docs.maptiler.com/sdk-js/api-reference/types/Externals.MediaKeySessionClosedReason/)\>;  
    [expiration](#expiration): number;  
    [keyStatuses](#keystatuses): [MediaKeyStatusMap](https://docs.maptiler.com/sdk-js/api-reference/interfaces/Externals.MediaKeyStatusMap/);  
    [onkeystatuseschange](#onkeystatuseschange): ((this: MediaKeySession, ev: Event) \=> any) | null;  
    [onmessage](#onmessage):  
        | ((this: MediaKeySession, ev: [MediaKeyMessageEvent](https://docs.maptiler.com/sdk-js/api-reference/interfaces/Externals.MediaKeyMessageEvent/)) \=> any)  
        | null;  
    [sessionId](#sessionid): string;  
    [addEventListener](#addeventlistener-1)<[K](#addeventlistenerk) extends keyof [MediaKeySessionEventMap](https://docs.maptiler.com/sdk-js/api-reference/interfaces/Externals.MediaKeySessionEventMap/)\>(  
        type: [K](#addeventlistenerk),  
        listener: (this: MediaKeySession, ev: [MediaKeySessionEventMap](https://docs.maptiler.com/sdk-js/api-reference/interfaces/Externals.MediaKeySessionEventMap/)\[[K](#addeventlistenerk)\]) \=> any,  
        options?: boolean | AddEventListenerOptions,  
    ): void;  
    [addEventListener](#addeventlistener-2)(  
        type: string,  
        listener: [EventListenerOrEventListenerObject](https://docs.maptiler.com/sdk-js/api-reference/types/Externals.EventListenerOrEventListenerObject/),  
        options?: boolean | AddEventListenerOptions,  
    ): void;  
    [close](#close-1)(): Promise<void\>;  
    [dispatchEvent](#dispatchevent-1)(event: Event): boolean;  
    [generateRequest](#generaterequest-1)(  
        initDataType: string,  
        initData: [BufferSource](https://docs.maptiler.com/sdk-js/api-reference/types/Externals.BufferSource/),  
    ): Promise<void\>;  
    [load](#load-1)(sessionId: string): Promise<boolean\>;  
    [remove](#remove-1)(): Promise<void\>;  
    [removeEventListener](#removeeventlistener-1)<[K](#removeeventlistenerk) extends keyof [MediaKeySessionEventMap](https://docs.maptiler.com/sdk-js/api-reference/interfaces/Externals.MediaKeySessionEventMap/)\>(  
        type: [K](#removeeventlistenerk),  
        listener: (this: MediaKeySession, ev: [MediaKeySessionEventMap](https://docs.maptiler.com/sdk-js/api-reference/interfaces/Externals.MediaKeySessionEventMap/)\[[K](#removeeventlistenerk)\]) \=> any,  
        options?: boolean | EventListenerOptions,  
    ): void;  
    [removeEventListener](#removeeventlistener-2)(  
        type: string,  
        listener: [EventListenerOrEventListenerObject](https://docs.maptiler.com/sdk-js/api-reference/types/Externals.EventListenerOrEventListenerObject/),  
        options?: boolean | EventListenerOptions,  
    ): void;  
    [update](#update-1)(response: [BufferSource](https://docs.maptiler.com/sdk-js/api-reference/types/Externals.BufferSource/)): Promise<void\>;  
}

#### Hierarchy

-   EventTarget
    -   MediaKeySession

##### Index

### Properties[](#properties)

[closed](#closed) [expiration](#expiration) [keyStatuses](#keystatuses) [onkeystatuseschange](#onkeystatuseschange) [onmessage](#onmessage) [sessionId](#sessionid)

### Methods[](#methods)

[addEventListener](#addeventlistener) [close](#close) [dispatchEvent](#dispatchevent) [generateRequest](#generaterequest) [load](#load) [remove](#remove) [removeEventListener](#removeeventlistener) [update](#update)

## Properties[](#properties-1)

### `Readonly`closed[](#closed)

closed: Promise<[MediaKeySessionClosedReason](https://docs.maptiler.com/sdk-js/api-reference/types/Externals.MediaKeySessionClosedReason/)\>

The **`closed`** read-only property of the MediaKeySession interface returns a Promise signaling when a MediaKeySession closes. This promise can only be fulfilled and is never rejected. Closing a session means that licenses and keys associated with it are no longer valid for decrypting media data.

[MDN Reference](https://developer.mozilla.org/docs/Web/API/MediaKeySession/closed)

### `Readonly`expiration[](#expiration)

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](https://developer.mozilla.org/docs/Web/API/MediaKeySession/expiration)

### `Readonly`keyStatuses[](#keystatuses)

keyStatuses: [MediaKeyStatusMap](https://docs.maptiler.com/sdk-js/api-reference/interfaces/Externals.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](https://developer.mozilla.org/docs/Web/API/MediaKeySession/keyStatuses)

### onkeystatuseschange[](#onkeystatuseschange)

onkeystatuseschange: ((this: MediaKeySession, ev: Event) \=> any) | null

[MDN Reference](https://developer.mozilla.org/docs/Web/API/MediaKeySession/keystatuseschange_event)

### onmessage[](#onmessage)

onmessage: ((this: MediaKeySession, ev: [MediaKeyMessageEvent](https://docs.maptiler.com/sdk-js/api-reference/interfaces/Externals.MediaKeyMessageEvent/)) \=> any) | null

[MDN Reference](https://developer.mozilla.org/docs/Web/API/MediaKeySession/message_event)

### `Readonly`sessionId[](#sessionid)

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](https://developer.mozilla.org/docs/Web/API/MediaKeySession/sessionId)

## Methods[](#methods-1)

### addEventListener[](#addeventlistener)

-   addEventListener<[K](#addeventlistenerk) extends keyof [MediaKeySessionEventMap](https://docs.maptiler.com/sdk-js/api-reference/interfaces/Externals.MediaKeySessionEventMap/)\>(  
        type: [K](#addeventlistenerk),  
        listener: (this: MediaKeySession, ev: [MediaKeySessionEventMap](https://docs.maptiler.com/sdk-js/api-reference/interfaces/Externals.MediaKeySessionEventMap/)\[[K](#addeventlistenerk)\]) \=> any,  
        options?: boolean | AddEventListenerOptions,  
    ): void[](#addeventlistener-1)
    
    The **`addEventListener()`** method of the EventTarget interface sets up a function that will be called whenever the specified event is delivered to the target.
    
    [MDN Reference](https://developer.mozilla.org/docs/Web/API/EventTarget/addEventListener)
    
    #### Type Parameters
    
    -   K extends keyof [MediaKeySessionEventMap](https://docs.maptiler.com/sdk-js/api-reference/interfaces/Externals.MediaKeySessionEventMap/)
    
    #### Parameters
    
    -   type: [K](#addeventlistenerk)
    -   listener: (this: MediaKeySession, ev: [MediaKeySessionEventMap](https://docs.maptiler.com/sdk-js/api-reference/interfaces/Externals.MediaKeySessionEventMap/)\[[K](#addeventlistenerk)\]) \=> any
    -   `Optional`options: boolean | AddEventListenerOptions
    
    #### Returns void
    
    Overrides EventTarget.addEventListener
    
-   addEventListener(  
        type: string,  
        listener: [EventListenerOrEventListenerObject](https://docs.maptiler.com/sdk-js/api-reference/types/Externals.EventListenerOrEventListenerObject/),  
        options?: boolean | AddEventListenerOptions,  
    ): void[](#addeventlistener-2)
    
    The **`addEventListener()`** method of the EventTarget interface sets up a function that will be called whenever the specified event is delivered to the target.
    
    [MDN Reference](https://developer.mozilla.org/docs/Web/API/EventTarget/addEventListener)
    
    #### Parameters
    
    -   type: string
    -   listener: [EventListenerOrEventListenerObject](https://docs.maptiler.com/sdk-js/api-reference/types/Externals.EventListenerOrEventListenerObject/)
    -   `Optional`options: boolean | AddEventListenerOptions
    
    #### Returns void
    
    Overrides EventTarget.addEventListener
    

### close[](#close)

-   close(): Promise<void\>[](#close-1)
    
    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. Then, it returns a Promise.
    
    [MDN Reference](https://developer.mozilla.org/docs/Web/API/MediaKeySession/close)
    
    #### Returns Promise<void\>
    

### dispatchEvent[](#dispatchevent)

-   dispatchEvent(event: Event): boolean[](#dispatchevent-1)
    
    The **`dispatchEvent()`** method of the EventTarget sends an Event to the object, (synchronously) invoking the affected event listeners in the appropriate order. The normal event processing rules (including the capturing and optional bubbling phase) also apply to events dispatched manually with dispatchEvent().
    
    [MDN Reference](https://developer.mozilla.org/docs/Web/API/EventTarget/dispatchEvent)
    
    #### Parameters
    
    -   event: Event
    
    #### Returns boolean
    
    Inherited from EventTarget.dispatchEvent
    

### generateRequest[](#generaterequest)

-   generateRequest(initDataType: string, initData: [BufferSource](https://docs.maptiler.com/sdk-js/api-reference/types/Externals.BufferSource/)): Promise<void\>[](#generaterequest-1)
    
    The **`generateRequest()`** method of the MediaKeySession interface returns a Promise after generating a license request based on initialization data.
    
    [MDN Reference](https://developer.mozilla.org/docs/Web/API/MediaKeySession/generateRequest)
    
    #### Parameters
    
    -   initDataType: string
    -   initData: [BufferSource](https://docs.maptiler.com/sdk-js/api-reference/types/Externals.BufferSource/)
    
    #### Returns Promise<void\>
    

### load[](#load)

-   load(sessionId: string): Promise<boolean\>[](#load-1)
    
    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](https://developer.mozilla.org/docs/Web/API/MediaKeySession/load)
    
    #### Parameters
    
    -   sessionId: string
    
    #### Returns Promise<boolean\>
    

### remove[](#remove)

-   remove(): Promise<void\>[](#remove-1)
    
    The **`remove()`** method of the MediaKeySession interface returns a Promise after removing any session data associated with the current object.
    
    [MDN Reference](https://developer.mozilla.org/docs/Web/API/MediaKeySession/remove)
    
    #### Returns Promise<void\>
    

### removeEventListener[](#removeeventlistener)

-   removeEventListener<[K](#removeeventlistenerk) extends keyof [MediaKeySessionEventMap](https://docs.maptiler.com/sdk-js/api-reference/interfaces/Externals.MediaKeySessionEventMap/)\>(  
        type: [K](#removeeventlistenerk),  
        listener: (this: MediaKeySession, ev: [MediaKeySessionEventMap](https://docs.maptiler.com/sdk-js/api-reference/interfaces/Externals.MediaKeySessionEventMap/)\[[K](#removeeventlistenerk)\]) \=> any,  
        options?: boolean | EventListenerOptions,  
    ): void[](#removeeventlistener-1)
    
    The **`removeEventListener()`** method of the EventTarget interface removes an event listener previously registered with EventTarget.addEventListener() from the target. The event listener to be removed is identified using a combination of the event type, the event listener function itself, and various optional options that may affect the matching process; see Matching event listeners for removal.
    
    [MDN Reference](https://developer.mozilla.org/docs/Web/API/EventTarget/removeEventListener)
    
    #### Type Parameters
    
    -   K extends keyof [MediaKeySessionEventMap](https://docs.maptiler.com/sdk-js/api-reference/interfaces/Externals.MediaKeySessionEventMap/)
    
    #### Parameters
    
    -   type: [K](#removeeventlistenerk)
    -   listener: (this: MediaKeySession, ev: [MediaKeySessionEventMap](https://docs.maptiler.com/sdk-js/api-reference/interfaces/Externals.MediaKeySessionEventMap/)\[[K](#removeeventlistenerk)\]) \=> any
    -   `Optional`options: boolean | EventListenerOptions
    
    #### Returns void
    
    Overrides EventTarget.removeEventListener
    
-   removeEventListener(  
        type: string,  
        listener: [EventListenerOrEventListenerObject](https://docs.maptiler.com/sdk-js/api-reference/types/Externals.EventListenerOrEventListenerObject/),  
        options?: boolean | EventListenerOptions,  
    ): void[](#removeeventlistener-2)
    
    The **`removeEventListener()`** method of the EventTarget interface removes an event listener previously registered with EventTarget.addEventListener() from the target. The event listener to be removed is identified using a combination of the event type, the event listener function itself, and various optional options that may affect the matching process; see Matching event listeners for removal.
    
    [MDN Reference](https://developer.mozilla.org/docs/Web/API/EventTarget/removeEventListener)
    
    #### Parameters
    
    -   type: string
    -   listener: [EventListenerOrEventListenerObject](https://docs.maptiler.com/sdk-js/api-reference/types/Externals.EventListenerOrEventListenerObject/)
    -   `Optional`options: boolean | EventListenerOptions
    
    #### Returns void
    
    Overrides EventTarget.removeEventListener
    

### update[](#update)

-   update(response: [BufferSource](https://docs.maptiler.com/sdk-js/api-reference/types/Externals.BufferSource/)): Promise<void\>[](#update-1)
    
    The **`update()`** method of the MediaKeySession interface loads messages and licenses to the CDM, and then returns a Promise.
    
    [MDN Reference](https://developer.mozilla.org/docs/Web/API/MediaKeySession/update)
    
    #### Parameters
    
    -   response: [BufferSource](https://docs.maptiler.com/sdk-js/api-reference/types/Externals.BufferSource/)
    
    #### Returns Promise<void\>
