mirror of
https://github.com/jambonz/sbc-inbound.git
synced 2026-01-24 22:37:51 +00:00
wip (#182)
This commit is contained in:
4
app.js
4
app.js
@@ -67,6 +67,8 @@ const {
|
|||||||
}, logger);
|
}, logger);
|
||||||
const {
|
const {
|
||||||
client: redisClient,
|
client: redisClient,
|
||||||
|
addKey,
|
||||||
|
retrieveKey,
|
||||||
createSet,
|
createSet,
|
||||||
retrieveSet,
|
retrieveSet,
|
||||||
addToSet,
|
addToSet,
|
||||||
@@ -108,6 +110,8 @@ srf.locals = {...srf.locals,
|
|||||||
lookupSystemInformation
|
lookupSystemInformation
|
||||||
},
|
},
|
||||||
realtimeDbHelpers: {
|
realtimeDbHelpers: {
|
||||||
|
addKey,
|
||||||
|
retrieveKey,
|
||||||
createSet,
|
createSet,
|
||||||
incrKey,
|
incrKey,
|
||||||
decrKey,
|
decrKey,
|
||||||
|
|||||||
@@ -7,8 +7,11 @@ const {
|
|||||||
nudgeCallCounts,
|
nudgeCallCounts,
|
||||||
roundTripTime,
|
roundTripTime,
|
||||||
parseConnectionIp,
|
parseConnectionIp,
|
||||||
isPrivateVoipNetwork
|
isPrivateVoipNetwork,
|
||||||
|
makeFullMediaReleaseKey,
|
||||||
|
makePartnerFullMediaReleaseKey
|
||||||
} = require('./utils');
|
} = require('./utils');
|
||||||
|
const { MediaPath } = require('./constants.json');
|
||||||
|
|
||||||
const {forwardInDialogRequests} = require('drachtio-fn-b2b-sugar');
|
const {forwardInDialogRequests} = require('drachtio-fn-b2b-sugar');
|
||||||
const {parseUri, stringifyUri, SipError} = require('drachtio-srf');
|
const {parseUri, stringifyUri, SipError} = require('drachtio-srf');
|
||||||
@@ -61,7 +64,10 @@ class CallSession extends Emitter {
|
|||||||
this.activeCallIds = this.srf.locals.activeCallIds;
|
this.activeCallIds = this.srf.locals.activeCallIds;
|
||||||
|
|
||||||
this.decrKey = req.srf.locals.realtimeDbHelpers.decrKey;
|
this.decrKey = req.srf.locals.realtimeDbHelpers.decrKey;
|
||||||
this._mediaReleased = false;
|
this.addKey = req.srf.locals.realtimeDbHelpers.addKey;
|
||||||
|
this.retrieveKey = req.srf.locals.realtimeDbHelpers.retrieveKey;
|
||||||
|
|
||||||
|
this._mediaPath = MediaPath.FullMedia;
|
||||||
|
|
||||||
this.application_sid = req.locals.application_sid;
|
this.application_sid = req.locals.application_sid;
|
||||||
this.account_sid = req.locals.account_sid;
|
this.account_sid = req.locals.account_sid;
|
||||||
@@ -79,7 +85,7 @@ class CallSession extends Emitter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
get isMediaReleased() {
|
get isMediaReleased() {
|
||||||
return this._mediaReleased;
|
return this._mediaPath !== MediaPath.FullMedia;
|
||||||
}
|
}
|
||||||
|
|
||||||
get isFive9VoiceStream() {
|
get isFive9VoiceStream() {
|
||||||
@@ -392,6 +398,14 @@ class CallSession extends Emitter {
|
|||||||
trace_id: uac.res?.get('X-Trace-ID') || '00000000000000000000000000000000'
|
trace_id: uac.res?.get('X-Trace-ID') || '00000000000000000000000000000000'
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* save far end SDP for later use if we do a full media release */
|
||||||
|
if (process.env.JAMBONES_ENABLE_FULL_MEDIA_RELEASE) {
|
||||||
|
const key = makeFullMediaReleaseKey(this.req.get('Call-ID'));
|
||||||
|
const sdp = this.req.body;
|
||||||
|
this.logger.info({key, sdp}, 'saving far end sdp for full media release feature');
|
||||||
|
this.addKey(key, sdp, 3600).catch((err) => this.logger.error(err, 'Error saving far end sdp'));
|
||||||
|
}
|
||||||
this.uas = uas;
|
this.uas = uas;
|
||||||
this.uac = uac;
|
this.uac = uac;
|
||||||
[uas, uac].forEach((dlg) => {
|
[uas, uac].forEach((dlg) => {
|
||||||
@@ -605,6 +619,7 @@ Duration=${payload.duration} `
|
|||||||
const toTag = dlg.type === 'uas' ? this.rtpEngineOpts.uac.tag : this.rtpEngineOpts.uas.tag;
|
const toTag = dlg.type === 'uas' ? this.rtpEngineOpts.uac.tag : this.rtpEngineOpts.uas.tag;
|
||||||
const reason = req.get('X-Reason');
|
const reason = req.get('X-Reason');
|
||||||
const isReleasingMedia = reason && dlg.type === 'uac' && ['release-media', 'anchor-media'].includes(reason);
|
const isReleasingMedia = reason && dlg.type === 'uac' && ['release-media', 'anchor-media'].includes(reason);
|
||||||
|
const isFullMediaRelease = reason === 'release-media-entirely' && process.env.JAMBONES_ENABLE_FULL_MEDIA_RELEASE;
|
||||||
const offerMedia = dlg.type === 'uas' ? this.rtpEngineOpts.uac.mediaOpts : this.rtpEngineOpts.uas.mediaOpts;
|
const offerMedia = dlg.type === 'uas' ? this.rtpEngineOpts.uac.mediaOpts : this.rtpEngineOpts.uas.mediaOpts;
|
||||||
const answerMedia = dlg.type === 'uas' ? this.rtpEngineOpts.uas.mediaOpts : this.rtpEngineOpts.uac.mediaOpts;
|
const answerMedia = dlg.type === 'uas' ? this.rtpEngineOpts.uas.mediaOpts : this.rtpEngineOpts.uac.mediaOpts;
|
||||||
const direction = dlg.type === 'uas' ? ['public', 'private'] : ['private', 'public'];
|
const direction = dlg.type === 'uas' ? ['public', 'private'] : ['private', 'public'];
|
||||||
@@ -666,6 +681,26 @@ Duration=${payload.duration} `
|
|||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isFullMediaRelease) {
|
||||||
|
const b_sdp = await this.retrieveKey(makePartnerFullMediaReleaseKey(this.req.get('Call-ID')));
|
||||||
|
this.logger.info({b_sdp}, 'reinvite ourselves out of the media path with this reinvite offer');
|
||||||
|
const answerSdp = await dlg.other.modify(b_sdp);
|
||||||
|
this.logger.info({answerSdp}, 'far end response to full media release');
|
||||||
|
res.send(200, {
|
||||||
|
body: dlg.local.sdp,
|
||||||
|
headers: {
|
||||||
|
'Contact': this.contactHeader
|
||||||
|
}
|
||||||
|
});
|
||||||
|
/* no media going through us now we can destroy the rtpengine resource */
|
||||||
|
this.rtpEngineResource.destroy().catch((err) => {
|
||||||
|
this.logger.info({err}, 'Error destroying rtpengine resource after full media release');
|
||||||
|
});
|
||||||
|
this._mediaPath = MediaPath.NoMedia;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const offeredSdp = Array.isArray(req.payload) && req.payload.length > 1 ?
|
const offeredSdp = Array.isArray(req.payload) && req.payload.length > 1 ?
|
||||||
req.payload.find((p) => p.type === 'application/sdp').content :
|
req.payload.find((p) => p.type === 'application/sdp').content :
|
||||||
req.body;
|
req.body;
|
||||||
@@ -695,12 +730,14 @@ Duration=${payload.duration} `
|
|||||||
let sdp;
|
let sdp;
|
||||||
//HL 2024-11-13: previously forwarded re-invites to webrtc clients but further testing has shown to be unnecessary
|
//HL 2024-11-13: previously forwarded re-invites to webrtc clients but further testing has shown to be unnecessary
|
||||||
//if (isReleasingMedia && !this.callerIsUsingSrtp) {
|
//if (isReleasingMedia && !this.callerIsUsingSrtp) {
|
||||||
if (isReleasingMedia) {
|
|
||||||
this.logger.info({response}, `got a reinvite from FS to ${reason}`);
|
//DH 2024-11- 18: if we are going from no-media to either partial or full media, we need reinvite the far end
|
||||||
|
if (isReleasingMedia && this._mediaPath !== MediaPath.NoMedia) {
|
||||||
sdp = dlg.other.remote.sdp;
|
sdp = dlg.other.remote.sdp;
|
||||||
if (!answerMedia.flags.includes('asymmetric')) answerMedia.flags.push('asymmetric');
|
if (!answerMedia.flags.includes('asymmetric')) answerMedia.flags.push('asymmetric');
|
||||||
answerMedia.flags = answerMedia.flags.filter((f) => f !== 'media handover');
|
answerMedia.flags = answerMedia.flags.filter((f) => f !== 'media handover');
|
||||||
this._mediaReleased = 'release-media' === reason;
|
this._mediaPath = 'release-media' === reason ? MediaPath.PartialMedia : MediaPath.FullMedia;
|
||||||
|
this.logger.debug(`media path is now ${this._mediaPath}`);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
sdp = await dlg.other.modify(response.sdp);
|
sdp = await dlg.other.modify(response.sdp);
|
||||||
|
|||||||
@@ -3,5 +3,10 @@
|
|||||||
"ScaleIn": "scale-in",
|
"ScaleIn": "scale-in",
|
||||||
"StandbyEnter": "standby-enter",
|
"StandbyEnter": "standby-enter",
|
||||||
"StandbyExit": "standby-exit"
|
"StandbyExit": "standby-exit"
|
||||||
|
},
|
||||||
|
"MediaPath": {
|
||||||
|
"NoMedia": "no-media",
|
||||||
|
"PartialMedia": "partial-media",
|
||||||
|
"FullMedia": "full-media"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
10
lib/utils.js
10
lib/utils.js
@@ -246,6 +246,12 @@ const parseHostPorts = (logger, hostports, srf) => {
|
|||||||
return obj;
|
return obj;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const makeFullMediaReleaseKey = (callId) => {
|
||||||
|
return `a_sdp:${callId}`;
|
||||||
|
};
|
||||||
|
const makePartnerFullMediaReleaseKey = (callId) => {
|
||||||
|
return `b_sdp:${callId}`;
|
||||||
|
};
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
isWSS,
|
isWSS,
|
||||||
@@ -265,6 +271,8 @@ module.exports = {
|
|||||||
parseConnectionIp,
|
parseConnectionIp,
|
||||||
isMSTeamsCIDR,
|
isMSTeamsCIDR,
|
||||||
isPrivateVoipNetwork,
|
isPrivateVoipNetwork,
|
||||||
parseHostPorts
|
parseHostPorts,
|
||||||
|
makeFullMediaReleaseKey,
|
||||||
|
makePartnerFullMediaReleaseKey
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user