{"version":3,"file":"sender-bitrate.cjs","names":[],"sources":["../../src/webrtc/sender-bitrate.ts"],"sourcesContent":["/**\n * Cap what one sender transmits, in bits per second.\n *\n * This is the other half of the pair that confuses people: an Opus `fmtp` line\n * describes what we want **to receive**, while this is what limits what we\n * **send**. Both are needed, and in a mesh topology this one matters more,\n * because the uplink carries one copy of the stream per participant.\n *\n * The read-modify-write is not ceremony. `setParameters` only accepts the very\n * object `getParameters` handed back — a freshly built one is rejected — and a\n * sender that has not negotiated yet reports **no** encodings at all, so writing\n * to `encodings[0]` without checking throws on exactly the call that sets the\n * cap before the first offer.\n *\n * @param sender - The `RTCRtpSender` to cap, from `pc.getSenders()` or\n *   `transceiver.sender`.\n * @param maxBitrate - Ceiling in bits per second, or `null` to lift the cap.\n * @returns `false` when the browser refused the change, which happens when the\n *   sender has no track or the transceiver is gone. Playback continues\n *   uncapped — a call that keeps running beats one that throws over a bitrate.\n *\n * @example\n * const sender = pc.getSenders().find((s) => s.track?.kind === \"audio\");\n * if (sender) await setSenderBitrate(sender, 48_000);\n */\nexport async function setSenderBitrate(\n    sender: RTCRtpSender,\n    maxBitrate: number | null,\n): Promise<boolean> {\n    try {\n        const parameters = sender.getParameters();\n        if (!parameters.encodings || parameters.encodings.length === 0) {\n            parameters.encodings = [{}];\n        }\n        for (const encoding of parameters.encodings) {\n            if (maxBitrate === null) delete encoding.maxBitrate;\n            else encoding.maxBitrate = maxBitrate;\n        }\n        await sender.setParameters(parameters);\n        return true;\n    } catch {\n        return false;\n    }\n}\n"],"mappings":"AAyBA,eAAsB,EAClB,EACA,EACgB,CAChB,GAAI,CACA,IAAM,EAAa,EAAO,cAAc,GACpC,CAAC,EAAW,WAAa,EAAW,UAAU,SAAW,KACzD,EAAW,UAAY,CAAC,CAAC,CAAC,GAE9B,IAAK,IAAM,KAAY,EAAW,UAC1B,IAAe,KAAM,OAAO,EAAS,WACpC,EAAS,WAAa,EAG/B,OADA,MAAM,EAAO,cAAc,CAAU,EAC9B,EACX,MAAQ,CACJ,MAAO,EACX,CACJ"}