Documentation Index
Fetch the complete documentation index at: https://mintlify.com/CeeblueTV/wrts-client/llms.txt
Use this file to discover all available pages before exploring further.
MediaKeysEngine manages the complete W3C Encrypted Media Extensions (EME) lifecycle for an HTMLVideoElement. It handles key system selection (Widevine, PlayReady, FairPlay, and Clear Key), certificate acquisition, license request/response, key session creation, and key status monitoring. The engine supports multiple robustness configurations per key system and negotiates them in order until the browser accepts one. While MediaKeysEngine is integrated in Player and activated automatically when content protection is present, it can also be used standalone when you need explicit control over DRM capabilities without relying on stream metadata.
Constructor
The video element to attach MediaKeys to. The constructor throws if
video.mediaKeys is already set on the element, since only one MediaKeysEngine may own a video element at a time.Static Properties
Maximum time in milliseconds to wait for MediaKeys negotiation to complete. Defaults to
8000 ms. If key system access is not granted within this window, the setup promise rejects.Maximum time in milliseconds to wait for all key sessions to close and MediaKeys to detach from the video element during
stop(). Defaults to 5000 ms.Instance Properties
The name of the key system that was successfully negotiated, e.g.
'com.widevine.alpha', 'com.microsoft.playready', or 'com.apple.fps'. Returns undefined if the engine has not started or has not yet successfully set up a key system.true after start() has been called and before stop() resolves.Methods
Begins the DRM negotiation lifecycle by attaching an Returns
encrypted event listener to the video element. When the first encrypted event fires, the engine calls navigator.requestMediaKeySystemAccess() with the provided key system configurations, creates MediaKeys, optionally loads a server certificate, and attaches the keys to the video element.boolean — false if the engine is already started, currently stopping, contentProtection is missing, or MediaKeys are already set on the element. Fires onError with details in those cases.Releases all key sessions, removes event listeners, and calls Returns
video.setMediaKeys(null) to detach the engine from the video element. Must be awaited before starting a new DRM session on the same video element.Promise<unknown> — resolves when cleanup is complete, or rejects if detaching fails. Subject to MediaKeysEngine.STOP_TIMEOUT.Events
Fired when
MediaKeys have been successfully created and attached to the video element via video.setMediaKeys(). At this point mediaKeysEngine.keySystem is populated and the player is ready to decrypt.Fired when any step of the EME lifecycle fails. The default implementation logs the error at the See MediaKeysEngineError below for all variants.
error level.Fired whenever the status of a decryption key changes inside any active session. The default implementation logs the change at the
info level.MediaKeysEngineError Type
All errors fired throughonError conform to the MediaKeysEngineError discriminated union:
MediaKeys issue
MediaKeys issue
A general EME lifecycle error, including missing
contentProtection in params, failed generateRequest, failed license fetch, failed setMediaKeys, or a concurrent-start guard failure.Unable to create WebKitMediaKeys
Unable to create WebKitMediaKeys
Emitted on WebKit-based browsers (older Safari) when the legacy
WebKitMediaKeys API fails to instantiate.Unable to create session with WebKitMediaKeys
Unable to create session with WebKitMediaKeys
Emitted on WebKit-based browsers when
WebKitMediaKeys.createSession() fails.Standalone Usage Example
The following example showsMediaKeysEngine used independently of Player, driving Widevine DRM with explicit capability declarations:
Player automatically creates and manages a MediaKeysEngine instance when contentProtection is present in the params passed to player.start() and the stream metadata reports DRM-protected tracks. In that scenario you do not need to instantiate MediaKeysEngine directly.