fix SDES issue for prodigal

This commit is contained in:
Hoan HL
2026-06-28 17:55:24 +07:00
parent 8ede0b7dc2
commit 161b8bc401
+40
View File
@@ -549,6 +549,46 @@ class CallSession extends Emitter {
localSdpA: async(sdp, res) => {
this.rtpEngineOpts.uac.tag = res.getParsedHeader('To').params.tag;
/* HACK (rtcp-mux): some far ends answer an m-line WITHOUT a=rtcp-mux even though
we offered it, advertising a separate RTCP port + a 2nd ICE component they never
service. That dead RTCP component blocks ICE completion and therefore DTLS on that
stream (no SRTP keys -> "no crypto suite negotiated", no audio). Force rtcp-mux back
on every audio m-line and drop the standalone a=rtcp port / component-2 candidates
so rtpengine keeps a single muxed component. */
const forceRtcpMux = (sdpStr) => {
if (!sdpStr || !sdpStr.includes('m=')) return sdpStr;
const eol = sdpStr.includes('\r\n') ? '\r\n' : '\n';
const lines = sdpStr.split(/\r?\n/);
const result = [];
let section = [];
let isAudio = false;
const flush = () => {
if (!section.length) return;
if (isAudio) {
const hasMux = section.some((l) => l.startsWith('a=rtcp-mux'));
let kept = section.filter((l) => {
if (/^a=rtcp:\d+/.test(l)) return false; // separate RTCP port
const m = /^a=candidate:\S+\s+(\d+)\s+/.exec(l); // component 2 == RTCP
if (m && m[1] === '2') return false;
return true;
});
if (!hasMux) kept = [kept[0], 'a=rtcp-mux', ...kept.slice(1)];
result.push(...kept);
} else {
result.push(...section);
}
section = [];
};
for (const l of lines) {
if (l.startsWith('m=')) { flush(); section = [l]; isAudio = l.startsWith('m=audio'); }
else if (section.length) section.push(l);
else result.push(l);
}
flush();
return result.join(eol);
};
sdp = forceRtcpMux(sdp);
const opts = {
...this.rtpEngineOpts.common,
...this.rtpEngineOpts.uas.mediaOpts,