Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix screen sharing in recent Chrome #4241

Merged
merged 4 commits into from
Jun 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 29 additions & 11 deletions src/webrtc/call.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2381,22 +2381,40 @@ export class MatrixCall extends TypedEventEmitter<CallEvent, CallEventHandlerMap
// RTCRtpReceiver.getCapabilities and RTCRtpSender.getCapabilities don't seem to be supported on FF before v113
if (!RTCRtpReceiver.getCapabilities || !RTCRtpSender.getCapabilities) return;

const screenshareVideoTransceiver = this.transceivers.get(
getTransceiverKey(SDPStreamMetadataPurpose.Screenshare, "video"),
);

// setCodecPreferences isn't supported on FF (as of v113)
if (!screenshareVideoTransceiver || !screenshareVideoTransceiver.setCodecPreferences) return;

const recvCodecs = RTCRtpReceiver.getCapabilities("video")!.codecs;
const sendCodecs = RTCRtpSender.getCapabilities("video")!.codecs;
const codecs = [...sendCodecs, ...recvCodecs];
const codecs = [];

for (const codec of codecs) {
if (codec.mimeType === "video/rtx") {
const rtxCodecIndex = codecs.indexOf(codec);
codecs.splice(rtxCodecIndex, 1);
for (const codec of [...recvCodecs, ...sendCodecs]) {
if (codec.mimeType !== "video/rtx") {
codecs.push(codec);
try {
screenshareVideoTransceiver.setCodecPreferences(codecs);
} catch (e) {
// Specifically, Chrome around version 125 and Electron 30 (which is Chromium 124) return an H.264 codec in
// the sender's capabilities but throw when you try to set it. Hence... this mess.
// Specifically, that codec is:
// {
// clockRate: 90000,
// mimeType: "video/H264",
// sdpFmtpLine: "level-asymmetry-allowed=1;packetization-mode=1;profile-level-id=640034",
// }
logger.info(
"Working around buggy WebRTC impl: claimed to support codec but threw when setting codec preferences",
codec,
e,
);
codecs.pop();
}
}
}

const screenshareVideoTransceiver = this.transceivers.get(
getTransceiverKey(SDPStreamMetadataPurpose.Screenshare, "video"),
);
// setCodecPreferences isn't supported on FF (as of v113)
screenshareVideoTransceiver?.setCodecPreferences?.(codecs);
}

private onNegotiationNeeded = async (): Promise<void> => {
Expand Down
Loading