Skip to content

Commit 2ee43ca

Browse files
RiotRobotdbkr
andauthored
[Backport staging] Fix screen sharing in recent Chrome (#4243)
Co-authored-by: David Baker <dbkr@users.noreply.github.com>
1 parent 395c3cf commit 2ee43ca

File tree

1 file changed

+29
-11
lines changed

1 file changed

+29
-11
lines changed

src/webrtc/call.ts

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2381,22 +2381,40 @@ export class MatrixCall extends TypedEventEmitter<CallEvent, CallEventHandlerMap
23812381
// RTCRtpReceiver.getCapabilities and RTCRtpSender.getCapabilities don't seem to be supported on FF before v113
23822382
if (!RTCRtpReceiver.getCapabilities || !RTCRtpSender.getCapabilities) return;
23832383

2384+
const screenshareVideoTransceiver = this.transceivers.get(
2385+
getTransceiverKey(SDPStreamMetadataPurpose.Screenshare, "video"),
2386+
);
2387+
2388+
// setCodecPreferences isn't supported on FF (as of v113)
2389+
if (!screenshareVideoTransceiver || !screenshareVideoTransceiver.setCodecPreferences) return;
2390+
23842391
const recvCodecs = RTCRtpReceiver.getCapabilities("video")!.codecs;
23852392
const sendCodecs = RTCRtpSender.getCapabilities("video")!.codecs;
2386-
const codecs = [...sendCodecs, ...recvCodecs];
2393+
const codecs = [];
23872394

2388-
for (const codec of codecs) {
2389-
if (codec.mimeType === "video/rtx") {
2390-
const rtxCodecIndex = codecs.indexOf(codec);
2391-
codecs.splice(rtxCodecIndex, 1);
2395+
for (const codec of [...recvCodecs, ...sendCodecs]) {
2396+
if (codec.mimeType !== "video/rtx") {
2397+
codecs.push(codec);
2398+
try {
2399+
screenshareVideoTransceiver.setCodecPreferences(codecs);
2400+
} catch (e) {
2401+
// Specifically, Chrome around version 125 and Electron 30 (which is Chromium 124) return an H.264 codec in
2402+
// the sender's capabilities but throw when you try to set it. Hence... this mess.
2403+
// Specifically, that codec is:
2404+
// {
2405+
// clockRate: 90000,
2406+
// mimeType: "video/H264",
2407+
// sdpFmtpLine: "level-asymmetry-allowed=1;packetization-mode=1;profile-level-id=640034",
2408+
// }
2409+
logger.info(
2410+
"Working around buggy WebRTC impl: claimed to support codec but threw when setting codec preferences",
2411+
codec,
2412+
e,
2413+
);
2414+
codecs.pop();
2415+
}
23922416
}
23932417
}
2394-
2395-
const screenshareVideoTransceiver = this.transceivers.get(
2396-
getTransceiverKey(SDPStreamMetadataPurpose.Screenshare, "video"),
2397-
);
2398-
// setCodecPreferences isn't supported on FF (as of v113)
2399-
screenshareVideoTransceiver?.setCodecPreferences?.(codecs);
24002418
}
24012419

24022420
private onNegotiationNeeded = async (): Promise<void> => {

0 commit comments

Comments
 (0)