mirror of
https://github.com/jambonz/sbc-outbound.git
synced 2026-07-04 19:32:04 +00:00
34 lines
1.1 KiB
JavaScript
34 lines
1.1 KiB
JavaScript
const rtpCharacteristics = require('../data/rtp-transcoding');
|
|
const srtpCharacteristics = require('../data/srtp-transcoding');
|
|
const debug = require('debug')('jambonz:sbc-outbound');
|
|
|
|
function makeRtpEngineOpts(req, srcIsUsingSrtp, dstIsUsingSrtp) {
|
|
const from = req.getParsedHeader('from');
|
|
const common = {'call-id': req.get('Call-ID'), 'from-tag': from.params.tag};
|
|
return {
|
|
common,
|
|
offer: Object.assign({'sdp': req.body, 'replace': ['origin', 'session-connection']}, common,
|
|
dstIsUsingSrtp ? srtpCharacteristics : rtpCharacteristics),
|
|
answer: Object.assign({}, common, srcIsUsingSrtp ? srtpCharacteristics : rtpCharacteristics)
|
|
};
|
|
}
|
|
|
|
function selectHostPort(hostport, protocol) {
|
|
debug(`selectHostPort: ${hostport}, ${protocol}`);
|
|
const sel = hostport
|
|
.split(',')
|
|
.map((hp) => {
|
|
const arr = /(.*)\/(.*):(.*)/.exec(hp);
|
|
return [arr[1], arr[2], arr[3]];
|
|
})
|
|
.filter((hp) => {
|
|
return hp[0] === protocol && hp[1] !== '127.0.0.1';
|
|
});
|
|
return sel[0];
|
|
}
|
|
|
|
module.exports = {
|
|
makeRtpEngineOpts,
|
|
selectHostPort
|
|
};
|