|
4 | 4 | // eslint-disable max-lines |
5 | 5 | // eslint-disable-next-line simple-import-sort/imports |
6 | 6 | import {parseRTCStats, RTCMonitor, RTCPeer} from '@mattermost/calls-common'; |
7 | | -import type {EmojiData, CallsClientJoinData, TrackInfo, RTPEncodingParameters} from '@mattermost/calls-common/lib/types'; |
| 7 | +import {type EmojiData, type CallsClientJoinData, type TrackInfo, type RTPEncodingParameters} from '@mattermost/calls-common/lib/types'; |
8 | 8 |
|
9 | 9 | import {EventEmitter} from 'events'; |
10 | 10 |
|
@@ -75,7 +75,6 @@ export default class CallsClient extends EventEmitter { |
75 | 75 | private connected = false; |
76 | 76 | public initTime = Date.now(); |
77 | 77 | private rtcMonitor: RTCMonitor | null = null; |
78 | | - private av1Codec: RTCRtpCodecCapability | null = null; |
79 | 78 | private defaultAudioTrackOptions: MediaTrackConstraints; |
80 | 79 | private defaultVideoTrackOptions: MediaTrackConstraints; |
81 | 80 | private defaultVideoTrackEncodings: RTPEncodingParameters[]; |
@@ -391,8 +390,7 @@ export default class CallsClient extends EventEmitter { |
391 | 390 | this.channelID = joinData.channelID; |
392 | 391 |
|
393 | 392 | if (this.config.enableAV1 && !this.config.simulcast) { |
394 | | - this.av1Codec = await RTCPeer.getVideoCodec('video/AV1'); |
395 | | - if (this.av1Codec) { |
| 393 | + if (await RTCPeer.getVideoCodec('video/AV1')) { |
396 | 394 | logDebug('client has AV1 support'); |
397 | 395 | joinData.av1Support = true; |
398 | 396 | } |
@@ -478,6 +476,7 @@ export default class CallsClient extends EventEmitter { |
478 | 476 | }, |
479 | 477 | simulcast: this.config.simulcast, |
480 | 478 | dcSignaling: this.config.dcSignaling, |
| 479 | + enableAV1: this.config.enableAV1, |
481 | 480 | }); |
482 | 481 |
|
483 | 482 | this.peer = peer; |
@@ -836,6 +835,9 @@ export default class CallsClient extends EventEmitter { |
836 | 835 | if (this.remoteVideoTracks.length < 1 || this.remoteVideoTracks[this.remoteVideoTracks.length - 1].readyState !== 'live') { |
837 | 836 | return null; |
838 | 837 | } |
| 838 | + |
| 839 | + // We return the last video track since it should be the most recent one with updated encoding if codec changes. |
| 840 | + // Obviously we'll have to review this once we add support for more than one video track (i.e., outside of DMs). |
839 | 841 | return new MediaStream([this.remoteVideoTracks[this.remoteVideoTracks.length - 1]]); |
840 | 842 | } |
841 | 843 |
|
@@ -884,17 +886,8 @@ export default class CallsClient extends EventEmitter { |
884 | 886 | }; |
885 | 887 |
|
886 | 888 | logDebug('adding stream to peer', screenStream.id); |
887 | | - |
888 | | - // Always send a fallback track (VP8 encoded) for receivers that don't yet support AV1. |
889 | 889 | await this.peer.addStream(screenStream); |
890 | 890 |
|
891 | | - if (this.config.enableAV1 && this.av1Codec) { |
892 | | - logDebug('AV1 supported, sending track', this.av1Codec); |
893 | | - await this.peer.addStream(screenStream, [{ |
894 | | - codec: this.av1Codec, |
895 | | - }]); |
896 | | - } |
897 | | - |
898 | 891 | this.ws.send('screen_on', { |
899 | 892 | data: JSON.stringify({ |
900 | 893 | screenStreamID: screenStream.id, |
@@ -1008,13 +1001,6 @@ export default class CallsClient extends EventEmitter { |
1008 | 1001 | await this.peer.replaceTrack(localVideoTrackID, localVideoTrack); |
1009 | 1002 | } else { |
1010 | 1003 | await this.peer.addTrack(localVideoTrack, this.localVideoStream, {encodings: this.defaultVideoTrackEncodings}); |
1011 | | - if (this.config.enableAV1 && this.av1Codec) { |
1012 | | - logDebug('AV1 supported, sending track', this.av1Codec); |
1013 | | - await this.peer.addTrack(localVideoTrack, this.localVideoStream, { |
1014 | | - codec: this.av1Codec, |
1015 | | - encodings: this.defaultVideoTrackEncodings, |
1016 | | - }); |
1017 | | - } |
1018 | 1004 | this.videoTrackAdded = true; |
1019 | 1005 | } |
1020 | 1006 |
|
|
0 commit comments