fix(screen-share): use sender capabilities for codec preference

setCodecPreferences requires codecs from RTCRtpSender.getCapabilities;
feeding it RTCRtpReceiver.getCapabilities throws InvalidModificationError
in Chrome and the swallowed exception left VP8 as the negotiated codec.
Switch the capability source so H264/AV1 preferences actually apply.
This commit is contained in:
LainHE authored and illusia committed 2026-10-12 13:51:49 +08:00
1 parent d919dbd82a
commit 7a6e054fe9
1 file changed
+1 -1
+1 -1
View File
@@ -413,7 +413,7 @@ export function createScreenShareController(transport: ScreenShareTransport) {
function preferScreenShareCodecs(peer: RTCPeerConnection): void {
const transceiver = peer.getTransceivers().find((candidate) => candidate.sender.track?.kind === "video" || candidate.receiver.track?.kind === "video");
const capabilities = typeof RTCRtpReceiver !== "undefined" ? RTCRtpReceiver.getCapabilities?.("video") : null;
const capabilities = typeof RTCRtpSender !== "undefined" ? RTCRtpSender.getCapabilities?.("video") : null;
if (!transceiver?.setCodecPreferences || !capabilities?.codecs?.length) return;
// Prefer H.264/AV1 for screen content: both compress text/UI far better
// than VP8 at the bitrates typical of relayed screen shares. VP8 stays as