Documentation
    Preparing search index...

    Interface MediaServiceOptions

    Optional host callbacks for the media service.

    Host shells can hook session creation and state updates to drive their own UI (e.g., now-playing banner) without replacing the ServiceHandler wholesale.

    const media = createMediaService({
    onSessionCreate: (windowId, sessionId, metadata) => {
    console.log(`[${windowId}] created session ${sessionId}`, metadata);
    },
    onState: (windowId, sessionId, state) => {
    nowPlaying.update(windowId, state);
    },
    });

    runtime.registerService('media', media);
    interface MediaServiceOptions {
        documentTarget?: Document | null;
        hostBridge?: HostMediaBridge;
        mediaSessionTarget?: MediaSessionTarget;
        onCapabilities?: (
            windowId: string,
            sessionId: string,
            actions: unknown,
        ) => void;
        onSessionCreate?: (
            windowId: string,
            sessionId: string,
            metadata?: unknown,
        ) => void;
        onSessionDestroy?: (windowId: string, sessionId: string) => void;
        onSessionUpdate?: (
            windowId: string,
            sessionId: string,
            metadata: unknown,
        ) => void;
        onState?: (windowId: string, sessionId: string, state: unknown) => void;
    }
    Index

    Properties

    documentTarget?: Document | null

    DOM document override (used by default browser bridge only). Defaults to document when available. Set to null to disable the silent-audio prime entirely — useful in unit tests. Ignored when hostBridge is provided.

    hostBridge?: HostMediaBridge

    Optional pluggable backend for metadata/state mirroring + OS action handling. When provided, the service delegates setMetadata / setPlaybackState / onAction to the bridge and skips navigator.mediaSession entirely. When omitted, the service internally uses createBrowserMediaBridge as the default. See HostMediaBridge.

    mediaSessionTarget?: MediaSessionTarget

    MediaSession target override (used by default browser bridge only). Defaults to navigator.mediaSession when running in a browser. Pass a MockMediaSession in unit tests. Ignored when hostBridge is provided.

    onCapabilities?: (windowId: string, sessionId: string, actions: unknown) => void

    Called when a napplet declares capabilities for a session.

    onSessionCreate?: (
        windowId: string,
        sessionId: string,
        metadata?: unknown,
    ) => void

    Called when a napplet creates a session. May inspect/record the session.

    onSessionDestroy?: (windowId: string, sessionId: string) => void

    Called when a napplet destroys a session.

    onSessionUpdate?: (
        windowId: string,
        sessionId: string,
        metadata: unknown,
    ) => void

    Called when a napplet updates session metadata.

    onState?: (windowId: string, sessionId: string, state: unknown) => void

    Called on media.state updates — high-frequency; keep handler work minimal.