From 2e69630544da219abc49e04ce78411dbbcded921 Mon Sep 17 00:00:00 2001 From: Hoan Luu Huu <110280845+xquanluu@users.noreply.github.com> Date: Wed, 3 Jan 2024 23:10:31 +0700 Subject: [PATCH] fix siprec to remap sdp base on participant label (#587) * fix siprec to remap sdp base on participant label * fix --- lib/utils/siprec-utils.js | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/lib/utils/siprec-utils.js b/lib/utils/siprec-utils.js index 82130db8..bb73cebd 100644 --- a/lib/utils/siprec-utils.js +++ b/lib/utils/siprec-utils.js @@ -97,8 +97,12 @@ const parseSiprecPayload = (req, logger) => { obj[`${prefix}participantstreamassoc`].forEach((ps) => { const part = participants[ps.$.participant_id]; if (part) { - part.send = ps[`${prefix}send`][0]; - part.recv = ps[`${prefix}recv`][0]; + if (ps.hasOwnProperty(`${prefix}send`)) { + part.send = ps[`${prefix}send`][0]; + } + if (ps.hasOwnProperty(`${prefix}recv`)) { + part.recv = ps[`${prefix}recv`][0]; + } } }); } @@ -109,9 +113,9 @@ const parseSiprecPayload = (req, logger) => { obj[`${prefix}stream`].forEach((s) => { const streamId = s.$.stream_id; let sender; - for (const [k, v] of Object.entries(participants)) { + for (const v of Object.values(participants)) { if (v.send === streamId) { - sender = k; + sender = v; break; } } @@ -121,9 +125,15 @@ const parseSiprecPayload = (req, logger) => { sender.label = s[`${prefix}label`][0]; - if (-1 !== ['1', 'a_leg', 'inbound'].indexOf(sender.label)) { - opts.caller.aor = sender.aor ; + if (-1 !== ['1', 'a_leg', 'inbound', '10'].indexOf(sender.label)) { + opts.caller.aor = sender.aor; if (sender.name) opts.caller.name = sender.name; + // Remap the sdp stream base on sender label + if (!opts.sdp1.includes(`a=label:${sender.label}`)) { + const tmp = opts.sdp1; + opts.sdp1 = opts.sdp2; + opts.sdp2 = tmp; + } } else { opts.callee.aor = sender.aor ;