Fix video not showing in Chrome

This commit is contained in:
redphx 2023-07-22 06:36:26 +07:00
parent a009cca866
commit 3a654b99cb

View File

@ -1022,20 +1022,22 @@ function patchRtcCodecs() {
RTCRtpTransceiver.prototype.setCodecPreferences = function(codecs) { RTCRtpTransceiver.prototype.setCodecPreferences = function(codecs) {
// Use the same codecs as desktop // Use the same codecs as desktop
const newCodecs = codecs.slice(); const newCodecs = codecs.slice();
let pos = 0;
newCodecs.forEach((codec, i) => { newCodecs.forEach((codec, i) => {
// Find high quality codecs // Find high quality codecs
if (codec.sdpFmtpLine && codec.sdpFmtpLine.includes('profile-level-id=4d')) { if (codec.sdpFmtpLine && codec.sdpFmtpLine.includes('profile-level-id=4d')) {
// Move it to the top of the array // Move it to the top of the array
newCodecs.splice(i, 1); newCodecs.splice(i, 1);
newCodecs.unshift(codec); newCodecs.splice(pos, 0, codec);
++pos;
} }
}); });
try { try {
this.orgSetCodecPreferences(newCodecs); this.orgSetCodecPreferences.apply(this, [newCodecs]);
} catch (e) { } catch (e) {
console.log(e); console.log(e);
this.orgSetCodecPreferences(codecs); this.orgSetCodecPreferences.apply(this, [codecs]);
} }
} }
} }