@ceeblue/wrts-client
    Preparing search index...

    Class MediaKeysEngine

    MediaKeysEngine handles EME (Encrypted Media Extensions) operations for an HTMLVideoElement. It supports the standard key systems — Widevine, PlayReady, FairPlay, and Clear Key — with multiple robustness configurations per key system, negotiated in order until one is supported by the browser.

    For convenience, MediaKeysEngine is integrated in Player, but it can also be used standalone — useful when you want to drive capabilities explicitly without relying on stream metadata:

    const mediaKeysEngine = new MediaKeysEngine(videoElement);
    mediaKeysEngine.onMediaKeys = () => console.log('MediaKeys ready on', mediaKeysEngine.keySystem);
    mediaKeysEngine.onError = error => console.error('MediaKeysEngine error', error);

    mediaKeysEngine.start({
    contentProtection: {
    'com.widevine.alpha': {
    license: 'https://widevine.example/getLicense',
    configurations: Connect.createMediaKeySystemConfigurations({
    audioContentTypes: ['audio/mp4; codecs="mp4a.40.2"'],
    videoContentTypes: ['video/mp4; codecs="avc1.640028"']
    })
    }
    }
    });

    // later
    await mediaKeysEngine.stop();

    Hierarchy

    • MediaKeysConfig
      • MediaKeysEngine
    Index

    Constructors

    Properties

    log: ILog

    Start a log

    a Log object with the levels of log to call

    DefaultConfiguration: MediaKeySystemConfiguration = ...

    Base MediaKeySystemConfiguration used as a template when the caller does not supply Connect.MediaKeySystem.configurations. Spread first so caller-provided fields override these defaults.

    MEDIA_KEYS_TIMEOUT: number = 8000
    STOP_TIMEOUT: number = 5000

    Accessors

    • get keySystem(): string | undefined

      Get the current key system name, or undefined if MediaKeysEngine is not started or no key system has been successfully set up yet.

      Returns string | undefined

    Methods

    • Build the array of MediaKeySystemConfiguration that will be passed to navigator.requestMediaKeySystemAccess() for a given key system.

      • When keySystemConfig is a bare string (license URL) or has no configurations, a single configuration is returned: baseConfig extended with audio/video capabilities derived from metadata if available.
      • When keySystemConfig.configurations are provided, each is merged with metadata via mergeConfigCapabilities; the caller's fields override baseConfig.

      Parameters

      • keySystemConfig: MediaKeySystem
      • Optionalmetadata: Metadata
      • baseConfig: MediaKeySystemConfiguration = MediaKeysConfig.DefaultConfiguration

      Returns MediaKeySystemConfiguration[]

    • Merge one side (audio or video) of user-provided capabilities with the capabilities derived from stream metadata.

      Rules:

      • If the caller provides no capabilities, metadata-derived capabilities are used as-is.
      • Caller capabilities that include a contentType win over metadata (explicit takes precedence).
      • Caller capabilities without a contentType (e.g. only robustness) are completed by cross-joining them with each metadata contentType.
      • When such unresolved capabilities exist and no metadata is available, they are kept as-is and a warning is logged.

      Parameters

      • configCapabilities: MediaKeySystemMediaCapability[] | undefined
      • metadataCapabilities: MediaKeySystemMediaCapability[] | undefined
      • type: "audio" | "video"

      Returns MediaKeySystemMediaCapability[] | undefined

    • Derive the set of audio/video capabilities from the content-protected tracks of a Metadata object. Each unique codecString produces one capability entry with its contentType (e.g. video/mp4; codecs="avc1.640028"). Returns empty fields when metadata is undefined or no track is content-protected.

      Parameters

      Returns MetadataCapabilities

    • Event unsubscription

      Parameters

      • name:
            | "error"
            | "Error"
            | "MediaKeys"
            | "mediakeys"
            | "KeyStatusChanged"
            | "keystatuschanged"

        Name of event without the 'on' prefix (ex: 'log' to 'onLog' event declared)

      • event: Function

        Unsubscriber Function, must be the one passed to on or once subscription methods

      Returns boolean

    • Event subscription

      Parameters

      • name:
            | "error"
            | "Error"
            | "MediaKeys"
            | "mediakeys"
            | "KeyStatusChanged"
            | "keystatuschanged"

        Name of event without the on prefix (ex: log to onLog event declared)

      • event: Function

        Subscriber Function

      • Optionaloptions: { signal?: AbortSignal }
        • Optionalsignal?: AbortSignal

          Optional AbortSignal to stop this or multiple subscriptions in same time

      Returns void

    • Event subscription only one time, once time fired it's automatically unsubscribe

      Parameters

      • name:
            | "error"
            | "Error"
            | "MediaKeys"
            | "mediakeys"
            | "KeyStatusChanged"
            | "keystatuschanged"

        Name of event without the on prefix (ex: log to onLog event declared)

      • event: Function

        Subscriber Function

      • Optionaloptions: { signal?: AbortSignal }
        • Optionalsignal?: AbortSignal

          Optional AbortSignal to stop this or multiple subscriptions in same time

      Returns void

    • Start the engine by listening to encrypted events on the video element and setting up MediaKeys when needed.

      Call this when receiving the event onMetadata or before if you want to force the capabilities used in the MediaKeySystemConfiguration.

      Parameters

      • params: Params
      • Optionalmetadata: Metadata

      Returns boolean

    • Normalize a Connect.MediaKeyCertificate into a NormalizedMediaKeyCertificate. A string input is treated as a URL to fetch, a Uint8Array as inline certificate bytes, and an object is returned as-is.

      Parameters

      • certificateConfig: MediaKeyCertificate

      Returns NormalizedMediaKeyCertificate

    • Normalize a Connect.MediaKeyLicense (which may be a bare URL string) into an object with url and headers.

      Parameters

      • licenseConfig: MediaKeyLicense

      Returns NormalizedMediaKeyLicense

    Events