mirror of
https://github.com/jambonz/sbc-outbound.git
synced 2026-07-04 19:32:04 +00:00
make rtpengine transcode if non-preferred codec is selected by far end
This commit is contained in:
+13
-3
@@ -1,4 +1,5 @@
|
||||
const Emitter = require('events');
|
||||
const sdpTransform = require('sdp-transform');
|
||||
const SrsClient = require('@jambonz/siprec-client-utils');
|
||||
const {makeRtpEngineOpts, makeCallCountKey} = require('./utils');
|
||||
const {forwardInDialogRequests} = require('drachtio-fn-b2b-sugar');
|
||||
@@ -49,6 +50,15 @@ const initCdr = (srf, req) => {
|
||||
};
|
||||
};
|
||||
|
||||
const updateRtpEngineFlags = (sdp, opts) => {
|
||||
try {
|
||||
const parsed = sdpTransform.parse(sdp);
|
||||
const codec = parsed.media[0].rtp[0].codec;
|
||||
if (['PCMU', 'PCMA'].includes(codec)) opts.flags.push(`codec-accept-${codec}`);
|
||||
} catch (err) {}
|
||||
return opts;
|
||||
};
|
||||
|
||||
class CallSession extends Emitter {
|
||||
constructor(logger, req, res) {
|
||||
super();
|
||||
@@ -236,16 +246,16 @@ class CallSession extends Emitter {
|
||||
}
|
||||
|
||||
// rtpengine 'offer'
|
||||
const opts = {
|
||||
const opts = updateRtpEngineFlags(this.req.body, {
|
||||
...this.rtpEngineOpts.common,
|
||||
...this.rtpEngineOpts.uac.mediaOpts,
|
||||
'from-tag': this.rtpEngineOpts.uas.tag,
|
||||
direction: ['private', 'public'],
|
||||
sdp: this.req.body
|
||||
};
|
||||
});
|
||||
const response = await this.offer(opts);
|
||||
debug(`response from rtpengine to offer ${JSON.stringify(response)}`);
|
||||
this.logger.debug({offer: opts, response}, 'initial offer to rtpengine');
|
||||
this.logger.info({offer: opts, response}, 'initial offer to rtpengine');
|
||||
if ('ok' !== response.result) {
|
||||
this.logger.error(`rtpengine offer failed with ${JSON.stringify(response)}`);
|
||||
throw new Error('rtpengine failed: answer');
|
||||
|
||||
Generated
+2
-1
@@ -22,7 +22,8 @@
|
||||
"drachtio-fn-b2b-sugar": "^0.0.12",
|
||||
"drachtio-srf": "^4.5.1",
|
||||
"express": "^4.18.1",
|
||||
"pino": "^7.11.0"
|
||||
"pino": "^7.11.0",
|
||||
"sdp-transform": "^2.14.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"bent": "^7.3.12",
|
||||
|
||||
+2
-1
@@ -40,7 +40,8 @@
|
||||
"drachtio-fn-b2b-sugar": "^0.0.12",
|
||||
"drachtio-srf": "^4.5.1",
|
||||
"express": "^4.18.1",
|
||||
"pino": "^7.11.0"
|
||||
"pino": "^7.11.0",
|
||||
"sdp-transform": "^2.14.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"bent": "^7.3.12",
|
||||
|
||||
Reference in New Issue
Block a user