mirror of
https://github.com/jambonz/sbc-inbound.git
synced 2026-10-10 05:14:30 +00:00
46 lines
1.1 KiB
JavaScript
46 lines
1.1 KiB
JavaScript
const rtpCharacteristics = require('../data/rtp-transcoding');
|
|
const srtpCharacteristics = require('../data/srtp-transcoding');
|
|
let idx = 0;
|
|
|
|
function isWSS(req) {
|
|
return req.getParsedHeader('Via')[0].protocol.toLowerCase().startsWith('ws');
|
|
}
|
|
|
|
function getAppserver(srf) {
|
|
const len = srf.locals.featureServers.length;
|
|
return srf.locals.featureServers[ idx++ % len];
|
|
}
|
|
|
|
function makeRtpEngineOpts(req, srcIsUsingSrtp, dstIsUsingSrtp, teams = false) {
|
|
const from = req.getParsedHeader('from');
|
|
const srtpOpts = teams ? srtpCharacteristics['teams'] : srtpCharacteristics['default'];
|
|
const dstOpts = dstIsUsingSrtp ? srtpOpts : rtpCharacteristics;
|
|
const srctOpts = srcIsUsingSrtp ? srtpOpts : rtpCharacteristics;
|
|
const common = {
|
|
'call-id': req.get('Call-ID'),
|
|
'replace': ['origin', 'session-connection']
|
|
};
|
|
return {
|
|
common,
|
|
uas: {
|
|
tag: from.params.tag,
|
|
mediaOpts: srctOpts
|
|
},
|
|
uac: {
|
|
tag: null,
|
|
mediaOpts: dstOpts
|
|
}
|
|
};
|
|
}
|
|
|
|
function SdpWantsSrtp(sdp) {
|
|
return /m=audio.*SAVP/.test(sdp);
|
|
}
|
|
|
|
module.exports = {
|
|
isWSS,
|
|
SdpWantsSrtp,
|
|
getAppserver,
|
|
makeRtpEngineOpts
|
|
};
|