in src/transceivercontroller/DefaultTransceiverController.ts [55:95]
async setEncodingParameters(
encodingParamMap: Map<string, RTCRtpEncodingParameters>
): Promise<void> {
if (!this._localCameraTransceiver || this._localCameraTransceiver.direction !== 'sendrecv') {
return;
}
const sender = this._localCameraTransceiver.sender;
if (!encodingParamMap || encodingParamMap.size === 0) {
return;
}
const newEncodingParams = Array.from(encodingParamMap.values());
const oldParam: RTCRtpSendParameters = sender.getParameters();
if (!oldParam.encodings || oldParam.encodings.length === 0) {
oldParam.encodings = newEncodingParams;
} else {
for (const existing of oldParam.encodings) {
for (const changed of newEncodingParams) {
if ((existing.rid || changed.rid) && existing.rid !== changed.rid) {
continue;
}
let key: keyof RTCRtpEncodingParameters;
for (key in changed) {
// These properties can't be changed.
if (key === 'rid' || key === 'codecPayloadType') {
continue;
}
/* istanbul ignore else */
if (changed.hasOwnProperty(key)) {
(existing[key] as RTCRtpEncodingParameters[keyof RTCRtpEncodingParameters]) = changed[
key
];
}
}
}
}
}
await sender.setParameters(oldParam);
}