From 9961aca55fb74ae045593ceac6ce5f5fcea6d7e5 Mon Sep 17 00:00:00 2001 From: neilyoung Date: Mon, 15 Nov 2021 22:22:25 +0100 Subject: [PATCH 1/2] Update prefer-codecs.js Took me a while to figure out that the /g flag is deadly in case there is more than one codec definition in the SDP. The second is simply not detected by the regexp, even though the regexp is completely fine - except the /g --- prefer-codecs.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/prefer-codecs.js b/prefer-codecs.js index 24dc2ff..9c3f874 100644 --- a/prefer-codecs.js +++ b/prefer-codecs.js @@ -1,7 +1,7 @@ var parser = require('./index'); var tools = require('./tools'); var ianaCodecs = require('./iana-codecs'); -var reRtpMap = /^rtpmap:([0-9]*)\s*([^\s]*)/ig; +var reRtpMap = /^rtpmap:([0-9]*)\s*([^\s]*)/i; /** From 6b827fe32eff880412ed5ae09d12d3d76cd27485 Mon Sep 17 00:00:00 2001 From: neilyoung Date: Sun, 21 Nov 2021 17:05:15 +0100 Subject: [PATCH 2/2] Prefer the first appearance of a particular codec... ...not the last one --- prefer-codecs.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/prefer-codecs.js b/prefer-codecs.js index 9c3f874..29ae939 100644 --- a/prefer-codecs.js +++ b/prefer-codecs.js @@ -42,10 +42,12 @@ module.exports = function(desiredCodecs, mediaType) { // Build the codec definition var codec = result[2]; var typeNum = result[1]; - r[codec.toUpperCase()] = { - num: typeNum, - codec: codec - } + // Use the first appearance of the specific codec, not the last + if (!r[codec.toUpperCase()]) + r[codec.toUpperCase()] = { + num: typeNum, + codec: codec + } return r; }