@@ -2381,22 +2381,40 @@ export class MatrixCall extends TypedEventEmitter<CallEvent, CallEventHandlerMap
2381
2381
// RTCRtpReceiver.getCapabilities and RTCRtpSender.getCapabilities don't seem to be supported on FF before v113
2382
2382
if ( ! RTCRtpReceiver . getCapabilities || ! RTCRtpSender . getCapabilities ) return ;
2383
2383
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
+
2384
2391
const recvCodecs = RTCRtpReceiver . getCapabilities ( "video" ) ! . codecs ;
2385
2392
const sendCodecs = RTCRtpSender . getCapabilities ( "video" ) ! . codecs ;
2386
- const codecs = [ ... sendCodecs , ... recvCodecs ] ;
2393
+ const codecs = [ ] ;
2387
2394
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
+ }
2392
2416
}
2393
2417
}
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 ) ;
2400
2418
}
2401
2419
2402
2420
private onNegotiationNeeded = async ( ) : Promise < void > => {
0 commit comments