mirror of
https://github.com/jambonz/jambonz-feature-server.git
synced 2025-12-20 16:50:39 +00:00
dual streams (#467)
* dual streams * dual streams * dual streams * dual streams * use sdp transform
This commit is contained in:
@@ -10,6 +10,7 @@ const HttpRequestor = require('../../utils/http-requestor');
|
||||
const WsRequestor = require('../../utils/ws-requestor');
|
||||
const RootSpan = require('../../utils/call-tracer');
|
||||
const dbUtils = require('../../utils/db-utils');
|
||||
const { mergeSdpMedia, extractSdpMedia } = require('../../utils/sdp-utils');
|
||||
|
||||
router.post('/', async(req, res) => {
|
||||
const {logger} = req.app.locals;
|
||||
@@ -127,16 +128,35 @@ router.post('/', async(req, res) => {
|
||||
|
||||
/* launch outdial */
|
||||
let sdp, sipLogger;
|
||||
let dualEp;
|
||||
let localSdp = ep.local.sdp;
|
||||
|
||||
if (req.body.dual_streams) {
|
||||
dualEp = await ms.createEndpoint();
|
||||
localSdp = mergeSdpMedia(localSdp, dualEp.local.sdp);
|
||||
ep.on('destroy', () => {
|
||||
dualEp.destroy();
|
||||
});
|
||||
}
|
||||
|
||||
const connectStream = async(remoteSdp) => {
|
||||
if (remoteSdp !== sdp) {
|
||||
ep.modify(sdp = remoteSdp);
|
||||
sdp = remoteSdp;
|
||||
if (req.body.dual_streams) {
|
||||
const [sdpLegA, sdpLebB] = extractSdpMedia(remoteSdp);
|
||||
|
||||
await Promise.all([ep.modify(sdpLegA), dualEp.modify(sdpLebB)]);
|
||||
await ep.bridge(dualEp);
|
||||
} else {
|
||||
ep.modify(sdp);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
Object.assign(opts, {
|
||||
proxy: `sip:${sbcAddress}`,
|
||||
localSdp: ep.local.sdp
|
||||
localSdp
|
||||
});
|
||||
if (target.auth) opts.auth = target.auth;
|
||||
|
||||
|
||||
@@ -1,7 +1,32 @@
|
||||
const sdpTransform = require('sdp-transform');
|
||||
|
||||
const isOnhold = (sdp) => {
|
||||
return sdp && (sdp.includes('a=sendonly') || sdp.includes('a=inactive'));
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
isOnhold
|
||||
const mergeSdpMedia = (sdp1, sdp2) => {
|
||||
const parsedSdp1 = sdpTransform.parse(sdp1);
|
||||
const parsedSdp2 = sdpTransform.parse(sdp2);
|
||||
|
||||
parsedSdp1.media.push(...parsedSdp2.media);
|
||||
return sdpTransform.write(parsedSdp1);
|
||||
};
|
||||
|
||||
const extractSdpMedia = (sdp) => {
|
||||
const parsedSdp1 = sdpTransform.parse(sdp);
|
||||
if (parsedSdp1.media.length > 1) {
|
||||
parsedSdp1.media = [parsedSdp1.media[0]];
|
||||
const parsedSdp2 = sdpTransform.parse(sdp);
|
||||
parsedSdp2.media = [parsedSdp2.media[1]];
|
||||
|
||||
return [sdpTransform.write(parsedSdp1), sdpTransform.write(parsedSdp2)];
|
||||
} else {
|
||||
return [sdp, sdp];
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
isOnhold,
|
||||
mergeSdpMedia,
|
||||
extractSdpMedia
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user