{"version":3,"file":"audio-output.cjs","names":[],"sources":["../../src/audio/audio-output.ts"],"sourcesContent":["/** A media element that may support output routing. */\ntype SinkCapableElement = HTMLMediaElement & {\n    setSinkId?: (sinkId: string) => Promise<void>;\n    sinkId?: string;\n};\n\n/**\n * Whether this browser can route audio to a chosen output device.\n *\n * Chromium-only at the time of writing: Firefox has `setSinkId` behind a preference\n * that is off by default, and Safari does not implement it at all. Check this before\n * rendering an output picker, or the control is a lie on two of three engines.\n */\nexport function isAudioOutputSelectionSupported(): boolean {\n    return (\n        typeof HTMLMediaElement !== \"undefined\" &&\n        typeof (HTMLMediaElement.prototype as SinkCapableElement).setSinkId === \"function\"\n    );\n}\n\n/**\n * Send an element's audio to a specific output device.\n *\n * The `sinkId` comes from `useMediaDevices().audioOutputs` — and, like every device\n * label, that list is anonymous until a capture permission has been granted, so an\n * output picker realistically only works after the microphone has been allowed once.\n *\n * Returns `false` instead of throwing when the browser has no `setSinkId`, because\n * \"this engine cannot route audio\" is the common case and not an error the caller can\n * act on: the sound still plays, on the system default device. A rejected\n * `setSinkId` — a device that was unplugged between enumeration and playback is the\n * usual cause — also resolves `false`, and playback continues on the default.\n *\n * @param element - The `<audio>` or `<video>` element to route.\n * @param sinkId - Device id, or `\"\"` for the system default.\n * @returns `true` when the route was applied.\n *\n * @example\n * const ok = await setAudioOutput(audioRef.current, selectedSpeakerId);\n * if (!ok) toast(\"Este navegador não permite escolher a saída de som.\");\n */\nexport async function setAudioOutput(\n    element: HTMLMediaElement | null,\n    sinkId: string,\n): Promise<boolean> {\n    const target = element as SinkCapableElement | null;\n    if (!target || typeof target.setSinkId !== \"function\") return false;\n    try {\n        await target.setSinkId(sinkId);\n        return true;\n    } catch {\n        return false;\n    }\n}\n"],"mappings":"AAaA,SAAgB,GAA2C,CACvD,OACI,OAAO,iBAAqB,KAC5B,OAAQ,iBAAiB,UAAiC,WAAc,UAEhF,CAuBA,eAAsB,EAClB,EACA,EACgB,CAChB,IAAM,EAAS,EACf,GAAI,CAAC,GAAU,OAAO,EAAO,WAAc,WAAY,MAAO,GAC9D,GAAI,CAEA,OADA,MAAM,EAAO,UAAU,CAAM,EACtB,EACX,MAAQ,CACJ,MAAO,EACX,CACJ"}