mirror of
https://github.com/jambonz/sbc-inbound.git
synced 2026-10-10 05:14:30 +00:00
31 lines
989 B
JavaScript
31 lines
989 B
JavaScript
const config = require('config');
|
|
let idx = 0;
|
|
|
|
function isWSS(req) {
|
|
return req.getParsedHeader('Via')[0].protocol.toLowerCase().startsWith('ws');
|
|
}
|
|
|
|
function getAppserver() {
|
|
const len = config.get('trunks.appserver').length;
|
|
return config.get('trunks.appserver')[ idx++ % len];
|
|
}
|
|
|
|
function makeRtpEngineOpts(req, srcIsUsingSrtp, dstIsUsingSrtp) {
|
|
const from = req.getParsedHeader('from');
|
|
const common = {'call-id': req.get('Call-ID'), 'from-tag': from.params.tag};
|
|
const rtpCharacteristics = config.get('transcoding.rtpCharacteristics');
|
|
const srtpCharacteristics = config.get('transcoding.srtpCharacteristics');
|
|
return {
|
|
common,
|
|
offer: Object.assign({'sdp': req.body, 'replace': ['origin', 'session-connection']}, common,
|
|
dstIsUsingSrtp ? srtpCharacteristics : rtpCharacteristics),
|
|
answer: Object.assign({}, common, srcIsUsingSrtp ? srtpCharacteristics : rtpCharacteristics)
|
|
};
|
|
}
|
|
|
|
module.exports = {
|
|
isWSS,
|
|
getAppserver,
|
|
makeRtpEngineOpts
|
|
};
|