mirror of
https://github.com/jambonz/sbc-inbound.git
synced 2026-10-04 10:14:35 +00:00
Compare commits
15
Commits
v0.7.6-rc2
...
v0.7.6
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
acead419d5 | ||
|
|
911d208e0f | ||
|
|
c824367086 | ||
|
|
f39df615f2 | ||
|
|
58e80afc92 | ||
|
|
738f151066 | ||
|
|
a94f25b0bd | ||
|
|
a1542b161b | ||
|
|
4e961491a6 | ||
|
|
4e5f7ae908 | ||
|
|
798e070127 | ||
|
|
2d350d4850 | ||
|
|
baad125924 | ||
|
|
73528f5ce2 | ||
|
|
c8329a94f3 |
+1
-1
@@ -1,4 +1,4 @@
|
||||
FROM --platform=linux/amd64 node:16.15.1-alpine as base
|
||||
FROM --platform=linux/amd64 node:18.6.0-alpine as base
|
||||
|
||||
RUN apk --update --no-cache add --virtual .builds-deps build-base python3
|
||||
|
||||
|
||||
@@ -111,6 +111,7 @@ const activeCallIds = srf.locals.activeCallIds;
|
||||
|
||||
const {
|
||||
initLocals,
|
||||
handleSipRec,
|
||||
identifyAccount,
|
||||
checkLimits,
|
||||
challengeDeviceCalls
|
||||
@@ -161,7 +162,13 @@ if (process.env.NODE_ENV === 'test') {
|
||||
}
|
||||
|
||||
/* install middleware */
|
||||
srf.use('invite', [initLocals, identifyAccount, checkLimits, challengeDeviceCalls]);
|
||||
srf.use('invite', [
|
||||
initLocals,
|
||||
handleSipRec,
|
||||
identifyAccount,
|
||||
checkLimits,
|
||||
challengeDeviceCalls
|
||||
]);
|
||||
|
||||
srf.invite((req, res) => {
|
||||
if (req.has('Replaces')) {
|
||||
|
||||
+113
-11
@@ -1,5 +1,5 @@
|
||||
const Emitter = require('events');
|
||||
const SrsClient = require('./srs-client');
|
||||
const SrsClient = require('@jambonz/siprec-client-utils');
|
||||
const {makeRtpEngineOpts, SdpWantsSrtp, makeCallCountKey} = require('./utils');
|
||||
const {forwardInDialogRequests} = require('drachtio-fn-b2b-sugar');
|
||||
const {parseUri, stringifyUri, SipError} = require('drachtio-srf');
|
||||
@@ -18,6 +18,20 @@ const createBLegFromHeader = (req) => {
|
||||
return '<sip:anonymous@localhost>';
|
||||
};
|
||||
|
||||
const createSiprecBody = (headers, sdp, type, content) => {
|
||||
const sep = 'uniqueBoundary';
|
||||
headers['Content-Type'] = `multipart/mixed;boundary="${sep}"`;
|
||||
return `--${sep}\r
|
||||
Content-Type: application/sdp\r
|
||||
\r
|
||||
${sdp}\r
|
||||
--${sep}\r
|
||||
Content-Type: ${type}\r
|
||||
Content-Disposition: recording-session\r
|
||||
\r
|
||||
${content}`;
|
||||
};
|
||||
|
||||
class CallSession extends Emitter {
|
||||
constructor(logger, req, res) {
|
||||
super();
|
||||
@@ -25,6 +39,8 @@ class CallSession extends Emitter {
|
||||
this.res = res;
|
||||
this.srf = req.srf;
|
||||
this.logger = logger.child({callId: req.get('Call-ID')});
|
||||
this.siprec = req.locals.siprec;
|
||||
this.xml = req.locals.xml;
|
||||
|
||||
this.getRtpEngine = req.srf.locals.getRtpEngine;
|
||||
this.getFeatureServer = req.srf.locals.getFeatureServer;
|
||||
@@ -34,6 +50,7 @@ class CallSession extends Emitter {
|
||||
|
||||
this.decrKey = req.srf.locals.realtimeDbHelpers.decrKey;
|
||||
this.callCountKey = makeCallCountKey(req.locals.account_sid);
|
||||
this._mediaReleased = false;
|
||||
}
|
||||
|
||||
get isFromMSTeams() {
|
||||
@@ -44,7 +61,17 @@ class CallSession extends Emitter {
|
||||
return this.srf.locals.privateSipAddress;
|
||||
}
|
||||
|
||||
get isMediaReleased() {
|
||||
return this._mediaReleased;
|
||||
}
|
||||
|
||||
get callerIsUsingSrtp() {
|
||||
const tp = this.rtpEngineOpts?.uas?.mediaOpts['transport-protocol'];
|
||||
return tp && -1 !== tp.indexOf('SAVP');
|
||||
}
|
||||
|
||||
async connect() {
|
||||
const {sdp} = this.req.locals;
|
||||
this.logger.info('inbound call accepted for routing');
|
||||
const engine = this.getRtpEngine();
|
||||
if (!engine) {
|
||||
@@ -62,6 +89,7 @@ class CallSession extends Emitter {
|
||||
unblockMedia,
|
||||
blockDTMF,
|
||||
unblockDTMF,
|
||||
playDTMF,
|
||||
subscribeDTMF,
|
||||
unsubscribeDTMF,
|
||||
subscribeRequest,
|
||||
@@ -75,6 +103,7 @@ class CallSession extends Emitter {
|
||||
this.unblockMedia = unblockMedia;
|
||||
this.blockDTMF = blockDTMF;
|
||||
this.unblockDTMF = unblockDTMF;
|
||||
this.playDTMF = playDTMF;
|
||||
this.subscribeDTMF = subscribeDTMF;
|
||||
this.unsubscribeDTMF = unsubscribeDTMF;
|
||||
this.subscribeRequest = subscribeRequest;
|
||||
@@ -90,7 +119,7 @@ class CallSession extends Emitter {
|
||||
}
|
||||
this.logger.debug(`using feature server ${featureServer}`);
|
||||
|
||||
this.rtpEngineOpts = makeRtpEngineOpts(this.req, SdpWantsSrtp(this.req.body), false, this.isFromMSTeams);
|
||||
this.rtpEngineOpts = makeRtpEngineOpts(this.req, SdpWantsSrtp(sdp), false, this.isFromMSTeams);
|
||||
this.rtpEngineResource = {destroy: this.del.bind(null, this.rtpEngineOpts.common)};
|
||||
const obj = parseUri(this.req.uri);
|
||||
let proxy, host, uri;
|
||||
@@ -115,7 +144,7 @@ class CallSession extends Emitter {
|
||||
...this.rtpEngineOpts.uac.mediaOpts,
|
||||
'from-tag': this.rtpEngineOpts.uas.tag,
|
||||
direction: ['public', 'private'],
|
||||
sdp: this.req.body
|
||||
sdp
|
||||
};
|
||||
const response = await this.offer(opts);
|
||||
this.logger.debug({opts, response}, 'response from rtpengine to offer');
|
||||
@@ -124,7 +153,6 @@ class CallSession extends Emitter {
|
||||
throw new Error('rtpengine failed: answer');
|
||||
}
|
||||
|
||||
// now send the INVITE in towards the feature servers
|
||||
let headers = {
|
||||
'From': createBLegFromHeader(this.req),
|
||||
'To': this.req.get('To'),
|
||||
@@ -134,6 +162,10 @@ class CallSession extends Emitter {
|
||||
};
|
||||
if (this.privateSipAddress) headers = {...headers, Contact: `<sip:${this.privateSipAddress}>`};
|
||||
|
||||
const spdOfferB = this.siprec && this.xml ?
|
||||
createSiprecBody(headers, response.sdp, this.xml.type, this.xml.content) :
|
||||
response.sdp;
|
||||
|
||||
const responseHeaders = {};
|
||||
if (this.req.locals.carrier) {
|
||||
Object.assign(headers, {
|
||||
@@ -165,6 +197,7 @@ class CallSession extends Emitter {
|
||||
|
||||
if (this.req.canceled) throw new Error('call canceled');
|
||||
|
||||
// now send the INVITE in towards the feature servers
|
||||
debug(`sending INVITE to ${proxy} with ${uri}`);
|
||||
const {uas, uac} = await this.srf.createB2BUA(this.req, this.res, uri, {
|
||||
proxy,
|
||||
@@ -179,7 +212,7 @@ class CallSession extends Emitter {
|
||||
'-X-Subspace-Forwarded-For'
|
||||
],
|
||||
proxyResponseHeaders: ['all', '-X-Trace-ID'],
|
||||
localSdpB: response.sdp,
|
||||
localSdpB: spdOfferB,
|
||||
localSdpA: async(sdp, res) => {
|
||||
this.rtpEngineOpts.uac.tag = res.getParsedHeader('To').params.tag;
|
||||
const opts = {
|
||||
@@ -362,7 +395,19 @@ Duration=${payload.duration} `
|
||||
*/
|
||||
async replaces(req, res) {
|
||||
try {
|
||||
let opts = Object.assign({}, this.rtpEngineOpts.uas.mediaOpts, {sdp: req.body});
|
||||
const fromTag = this.rtpEngineOpts.uas.tag;
|
||||
const toTag = this.rtpEngineOpts.uac.tag;
|
||||
const offerMedia = this.rtpEngineOpts.uac.mediaOpts;
|
||||
const answerMedia = this.rtpEngineOpts.uas.mediaOpts;
|
||||
const direction = ['public', 'private'];
|
||||
let opts = {
|
||||
...this.rtpEngineOpts.common,
|
||||
...offerMedia,
|
||||
'from-tag': fromTag,
|
||||
'to-tag': toTag,
|
||||
direction,
|
||||
sdp: req.body,
|
||||
};
|
||||
let response = await this.offer(opts);
|
||||
if ('ok' !== response.result) {
|
||||
res.send(488);
|
||||
@@ -370,8 +415,13 @@ Duration=${payload.duration} `
|
||||
}
|
||||
this.logger.info({opts, response}, 'sent offer for reinvite to rtpengine');
|
||||
const sdp = await this.uac.modify(response.sdp);
|
||||
opts = Object.assign({}, this.rtpEngineOpts.uac.mediaOpts, {sdp, 'to-tag': this.toTag});
|
||||
Object.assign(this.rtpEngineOpts.uas.mediaOpts, {'to-tag': this.toTag});
|
||||
opts = {
|
||||
...this.rtpEngineOpts.common,
|
||||
...answerMedia,
|
||||
'from-tag': fromTag,
|
||||
'to-tag': toTag,
|
||||
sdp
|
||||
};
|
||||
response = await this.answer(opts);
|
||||
if ('ok' !== response.result) {
|
||||
res.send(488);
|
||||
@@ -417,6 +467,10 @@ Duration=${payload.duration} `
|
||||
res.send(200, {body: dlg.local.sdp});
|
||||
return;
|
||||
}
|
||||
const offeredSdp = Array.isArray(req.payload) && req.payload.length > 1 ?
|
||||
req.payload.find((p) => p.type === 'application/sdp').content :
|
||||
req.body;
|
||||
|
||||
const reason = req.get('X-Reason');
|
||||
const fromTag = dlg.type === 'uas' ? this.rtpEngineOpts.uas.tag : this.rtpEngineOpts.uac.tag;
|
||||
const toTag = dlg.type === 'uas' ? this.rtpEngineOpts.uac.tag : this.rtpEngineOpts.uas.tag;
|
||||
@@ -429,8 +483,9 @@ Duration=${payload.duration} `
|
||||
'from-tag': fromTag,
|
||||
'to-tag': toTag,
|
||||
direction,
|
||||
sdp: req.body,
|
||||
sdp: offeredSdp,
|
||||
};
|
||||
if (reason && opts.flags && !opts.flags.includes('reset')) opts.flags.push('reset');
|
||||
|
||||
let response = await this.offer(opts);
|
||||
if ('ok' !== response.result) {
|
||||
@@ -440,9 +495,12 @@ Duration=${payload.duration} `
|
||||
|
||||
/* if this is a re-invite from the FS to change media anchoring, avoid sending the reinvite out */
|
||||
let sdp;
|
||||
if (reason && dlg.type === 'uac' && ['release-media', 'anchor-media'].includes(reason)) {
|
||||
if (reason && dlg.type === 'uac' && ['release-media', 'anchor-media'].includes(reason) &&
|
||||
!this.callerIsUsingSrtp) {
|
||||
this.logger.info({response}, `got a reinvite from FS to ${reason}`);
|
||||
sdp = dlg.other.remote.sdp;
|
||||
answerMedia.flags = ['asymmetric', 'port latching'];
|
||||
this._mediaReleased = 'release-media' === reason;
|
||||
}
|
||||
else {
|
||||
sdp = await dlg.other.modify(response.sdp);
|
||||
@@ -468,6 +526,7 @@ Duration=${payload.duration} `
|
||||
async _onInfo(dlg, req, res) {
|
||||
const fromTag = dlg.type === 'uas' ? this.rtpEngineOpts.uas.tag : this.rtpEngineOpts.uac.tag;
|
||||
const toTag = dlg.type === 'uas' ? this.rtpEngineOpts.uac.tag : this.rtpEngineOpts.uas.tag;
|
||||
const contentType = req.get('Content-Type');
|
||||
try {
|
||||
if (dlg.type === 'uac' && req.has('X-Reason')) {
|
||||
const reason = req.get('X-Reason');
|
||||
@@ -514,6 +573,7 @@ Duration=${payload.duration} `
|
||||
}
|
||||
this.srsClient = new SrsClient(this.logger, {
|
||||
srf: dlg.srf,
|
||||
direction: 'inbound',
|
||||
originalInvite: this.req,
|
||||
callingNumber: this.req.callingNumber,
|
||||
calledNumber: this.req.calledNumber,
|
||||
@@ -572,6 +632,40 @@ Duration=${payload.duration} `
|
||||
res.send(succeeded ? 200 : 503);
|
||||
}
|
||||
}
|
||||
else if (dlg.type === 'uas' && ['application/dtmf-relay', 'application/dtmf'].includes(contentType)) {
|
||||
const arr = /Signal=\s*([1-9#*])/.exec(req.body);
|
||||
if (!arr) {
|
||||
this.logger.info({body: req.body}, '_onInfo: invalid INFO dtmf request');
|
||||
throw new Error(`_onInfo: no dtmf in body for ${contentType}`);
|
||||
}
|
||||
const code = arr[1];
|
||||
const arr2 = /Duration=\s*(\d+)/.exec(req.body);
|
||||
const duration = arr2 ? arr2[1] : 250;
|
||||
|
||||
if (this.isMediaReleased) {
|
||||
/* just relay on to the feature server */
|
||||
this.logger.info({code, duration}, 'got SIP INFO DTMF from caller, relaying to feature server');
|
||||
this._onDTMF(dlg.other, {event: code, duration})
|
||||
.catch((err) => this.logger.info({err}, 'Error relaying DTMF to feature server'));
|
||||
res.send(200);
|
||||
}
|
||||
else {
|
||||
/* else convert SIP INFO to RFC 2833 telephony events */
|
||||
this.logger.info({code, duration}, 'got SIP INFO DTMF from caller, converting to RFC 2833');
|
||||
const opts = {
|
||||
...this.rtpEngineOpts.common,
|
||||
'from-tag': this.rtpEngineOpts.uas.tag,
|
||||
code,
|
||||
duration
|
||||
};
|
||||
const response = await this.playDTMF(opts);
|
||||
if ('ok' !== response.result) {
|
||||
this.logger.info({response}, `rtpengine playDTMF failed with ${JSON.stringify(response)}`);
|
||||
throw new Error('rtpengine failed: answer');
|
||||
}
|
||||
res.send(200);
|
||||
}
|
||||
}
|
||||
else {
|
||||
const immutableHdrs = ['via', 'from', 'to', 'call-id', 'cseq', 'max-forwards', 'content-length'];
|
||||
const headers = {};
|
||||
@@ -626,11 +720,19 @@ Duration=${payload.duration} `
|
||||
if (e164 && !uri.user.startsWith('+')) {
|
||||
uri.user = `+${uri.user}`;
|
||||
}
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
const {via, from, to, 'call-id':callid, cseq, 'max-forwards':maxforwards,
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
'content-length':contentlength, 'refer-to':_referto, 'referred-by':_referredby,
|
||||
...customHeaders
|
||||
} = req.headers;
|
||||
|
||||
const response = await this.uas.request({
|
||||
method: 'REFER',
|
||||
headers: {
|
||||
'Refer-To': stringifyUri(uri),
|
||||
'Referred-By': stringifyUri(u)
|
||||
'Referred-By': stringifyUri(u),
|
||||
...customHeaders
|
||||
}
|
||||
});
|
||||
return res.send(response.status);
|
||||
|
||||
+38
-4
@@ -70,7 +70,8 @@ module.exports = function(srf, logger) {
|
||||
});
|
||||
|
||||
const initLocals = (req, res, next) => {
|
||||
req.locals = req.locals || {};
|
||||
const callId = req.get('Call-ID');
|
||||
req.locals = req.locals || {callId};
|
||||
|
||||
/* check if forwarded by a proxy that applied an X-Forwarded-For Header */
|
||||
if (req.has('X-Forwarded-For') || req.has('X-Subspace-Forwarded-For')) {
|
||||
@@ -83,7 +84,6 @@ module.exports = function(srf, logger) {
|
||||
req.source_address = original_source_address;
|
||||
}
|
||||
req.locals.cdr = initCdr(req);
|
||||
const callId = req.get('Call-ID');
|
||||
req.on('cancel', () => {
|
||||
logger.info({callId}, 'caller hungup before connecting to feature server');
|
||||
req.canceled = true;
|
||||
@@ -109,8 +109,31 @@ module.exports = function(srf, logger) {
|
||||
next();
|
||||
};
|
||||
|
||||
const handleSipRec = async(req, res, next) => {
|
||||
const {callId} = req.locals;
|
||||
if (Array.isArray(req.payload) && req.payload.length > 1) {
|
||||
const sdp = req.payload
|
||||
.find((p) => p.type === 'application/sdp')
|
||||
.content;
|
||||
if (!sdp) {
|
||||
logger.error({callId}, 'No SDP in multipart sdp');
|
||||
return res.send(503);
|
||||
}
|
||||
const xml = req.payload.find((p) => p.type !== 'application/sdp');
|
||||
const endPos = xml.content.indexOf('</recording>');
|
||||
xml.content = endPos !== -1 ?
|
||||
`${xml.content.substring(0, endPos + 12)}` :
|
||||
xml.content;
|
||||
logger.debug({callId, xml}, 'incoming call with SIPREC body');
|
||||
req.locals = {...req.locals, sdp, siprec: true, xml};
|
||||
}
|
||||
else req.locals = {...req.locals, sdp: req.body};
|
||||
next();
|
||||
};
|
||||
|
||||
const identifyAccount = async(req, res, next) => {
|
||||
try {
|
||||
const {siprec, callId} = req.locals;
|
||||
const {wasOriginatedFromCarrier, getApplicationForDidAndCarrier} = req.srf.locals;
|
||||
const {
|
||||
fromCarrier,
|
||||
@@ -132,8 +155,18 @@ module.exports = function(srf, logger) {
|
||||
}
|
||||
logger.debug({gateway}, 'identifyAccount: incoming call from gateway');
|
||||
|
||||
/* check for phone number level routing */
|
||||
const sid = application_sid || await getApplicationForDidAndCarrier(req, gateway.voip_carrier_sid);
|
||||
let sid;
|
||||
if (siprec) {
|
||||
if (!account.siprec_hook_sid) {
|
||||
logger.info({callId}, 'identifyAccount: rejecting call because SIPREC hook has not been provisioned');
|
||||
return res.send(404);
|
||||
}
|
||||
sid = account.siprec_hook_sid;
|
||||
}
|
||||
else {
|
||||
/* check for phone number level routing */
|
||||
sid = application_sid || await getApplicationForDidAndCarrier(req, gateway.voip_carrier_sid);
|
||||
}
|
||||
req.locals = {
|
||||
originator: 'trunk',
|
||||
carrier: gateway.name,
|
||||
@@ -296,6 +329,7 @@ module.exports = function(srf, logger) {
|
||||
|
||||
return {
|
||||
initLocals,
|
||||
handleSipRec,
|
||||
challengeDeviceCalls,
|
||||
identifyAccount,
|
||||
checkLimits
|
||||
|
||||
@@ -1,249 +0,0 @@
|
||||
const Emitter = require('events');
|
||||
const assert = require('assert');
|
||||
const transform = require('sdp-transform');
|
||||
const { v4: uuidv4 } = require('uuid');
|
||||
|
||||
const createMultipartSdp = (sdp, {
|
||||
originalInvite,
|
||||
srsRecordingId,
|
||||
callSid,
|
||||
accountSid,
|
||||
applicationSid,
|
||||
sipCallId,
|
||||
aorFrom,
|
||||
aorTo,
|
||||
callingNumber,
|
||||
calledNumber
|
||||
}) => {
|
||||
const sessionId = uuidv4();
|
||||
const uuidStream1 = uuidv4();
|
||||
const uuidStream2 = uuidv4();
|
||||
const participant1 = uuidv4();
|
||||
const participant2 = uuidv4();
|
||||
const sipSessionId = originalInvite.get('Call-ID');
|
||||
const {originator = 'unknown', carrier = 'unknown'} = originalInvite.locals;
|
||||
|
||||
const x = `--uniqueBoundary
|
||||
Content-Disposition: session;handling=required
|
||||
Content-Type: application/sdp
|
||||
|
||||
--sdp-placeholder--
|
||||
--uniqueBoundary
|
||||
Content-Disposition: recording-session
|
||||
Content-Type: application/rs-metadata+xml
|
||||
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<recording xmlns="urn:ietf:params:xml:ns:recording:1">
|
||||
<datamode>complete</datamode>
|
||||
<session session_id="${sessionId}">
|
||||
<sipSessionID>${sipSessionId}</sipSessionID>
|
||||
</session>
|
||||
<extensiondata xmlns:jb="http://jambonz.org/siprec">
|
||||
<jb:callsid>${callSid}</jb:callsid>
|
||||
<jb:accountsid>${accountSid}</jb:accountsid>
|
||||
<jb:applicationsid>${applicationSid}</jb:applicationsid>
|
||||
<jb:recordingid>${srsRecordingId}</jb:recordingid>
|
||||
<jb:originationsource>${originator}</jb:originationsource>
|
||||
<jb:carrier>${carrier}</jb:carrier>
|
||||
</extensiondata>
|
||||
<participant participant_id="${participant1}">
|
||||
<nameID aor="${aorFrom}">
|
||||
<name>${callingNumber}</name>
|
||||
</nameID>
|
||||
</participant>
|
||||
<participantsessionassoc participant_id="${participant1}" session_id="${sessionId}">
|
||||
</participantsessionassoc>
|
||||
<stream stream_id="${uuidStream1}" session_id="${sessionId}">
|
||||
<label>1</label>
|
||||
</stream>
|
||||
<participant participant_id="${participant2}">
|
||||
<nameID aor="${aorTo}">
|
||||
<name>${calledNumber}</name>
|
||||
</nameID>
|
||||
</participant>
|
||||
<participantsessionassoc participant_id="${participant2}" session_id="${sessionId}">
|
||||
</participantsessionassoc>
|
||||
<stream stream_id="${uuidStream2}" session_id="${sessionId}">
|
||||
<label>2</label>
|
||||
</stream>
|
||||
<participantstreamassoc participant_id="${participant1}">
|
||||
<send>${uuidStream1}</send>
|
||||
<recv>${uuidStream2}</recv>
|
||||
</participantstreamassoc>
|
||||
<participantstreamassoc participant_id="${participant2}">
|
||||
<send>${uuidStream2}</send>
|
||||
<recv>${uuidStream1}</recv>
|
||||
</participantstreamassoc>
|
||||
</recording>`
|
||||
.replace(/\n/g, '\r\n')
|
||||
.replace('--sdp-placeholder--', sdp);
|
||||
|
||||
return `${x}\r\n`;
|
||||
};
|
||||
|
||||
class SrsClient extends Emitter {
|
||||
constructor(logger, opts) {
|
||||
super();
|
||||
const {
|
||||
srf,
|
||||
originalInvite,
|
||||
calledNumber,
|
||||
callingNumber,
|
||||
srsUrl,
|
||||
srsRecordingId,
|
||||
callSid,
|
||||
accountSid,
|
||||
applicationSid,
|
||||
srsDestUserName,
|
||||
rtpEngineOpts,
|
||||
//fromTag,
|
||||
toTag,
|
||||
aorFrom,
|
||||
aorTo,
|
||||
subscribeRequest,
|
||||
subscribeAnswer,
|
||||
del,
|
||||
blockMedia,
|
||||
unblockMedia,
|
||||
unsubscribe
|
||||
} = opts;
|
||||
this.logger = logger;
|
||||
this.srf = srf;
|
||||
this.originalInvite = originalInvite;
|
||||
this.callingNumber = callingNumber;
|
||||
this.calledNumber = calledNumber;
|
||||
this.subscribeRequest = subscribeRequest;
|
||||
this.subscribeAnswer = subscribeAnswer;
|
||||
this.del = del;
|
||||
this.blockMedia = blockMedia;
|
||||
this.unblockMedia = unblockMedia;
|
||||
this.unsubscribe = unsubscribe;
|
||||
this.srsUrl = srsUrl;
|
||||
this.srsRecordingId = srsRecordingId;
|
||||
this.callSid = callSid;
|
||||
this.accountSid = accountSid;
|
||||
this.applicationSid = applicationSid;
|
||||
this.srsDestUserName = srsDestUserName;
|
||||
this.rtpEngineOpts = rtpEngineOpts;
|
||||
this.sipRecFromTag = toTag;
|
||||
this.aorFrom = aorFrom;
|
||||
this.aorTo = aorTo;
|
||||
|
||||
/* state */
|
||||
this.activated = false;
|
||||
this.paused = false;
|
||||
}
|
||||
|
||||
async start() {
|
||||
assert(!this.activated);
|
||||
|
||||
const opts = {
|
||||
'call-id': this.rtpEngineOpts.common['call-id'],
|
||||
'from-tag': this.sipRecFromTag
|
||||
};
|
||||
|
||||
let response = await this.subscribeRequest({...opts, label: '1', flags: ['all'], interface: 'public'});
|
||||
if (response.result !== 'ok') {
|
||||
this.logger.error({response}, 'SrsClient:start error calling subscribe request');
|
||||
throw new Error('error calling subscribe request');
|
||||
}
|
||||
this.siprecToTag = response['to-tag'];
|
||||
|
||||
const parsed = transform.parse(response.sdp);
|
||||
parsed.name = 'jambonz SRS';
|
||||
parsed.media[0].label = '1';
|
||||
parsed.media[1].label = '2';
|
||||
this.sdpOffer = transform.write(parsed);
|
||||
const sdp = createMultipartSdp(this.sdpOffer, {
|
||||
originalInvite: this.originalInvite,
|
||||
srsRecordingId: this.srsRecordingId,
|
||||
callSid: this.callSid,
|
||||
accountSid: this.accountSid,
|
||||
applicationSid: this.applicationSid,
|
||||
calledNumber: this.calledNumber,
|
||||
callingNumber: this.callingNumber,
|
||||
aorFrom: this.aorFrom,
|
||||
aorTo: this.aorTo
|
||||
});
|
||||
|
||||
this.logger.info({response}, `SrsClient: sending SDP ${sdp}`);
|
||||
|
||||
/* */
|
||||
try {
|
||||
this.uac = await this.srf.createUAC(this.srsUrl, {
|
||||
headers: {
|
||||
'Content-Type': 'multipart/mixed;boundary=uniqueBoundary',
|
||||
},
|
||||
localSdp: sdp
|
||||
});
|
||||
} catch (err) {
|
||||
this.logger.info({err}, `Error sending SIPREC INVITE to ${this.srsUrl}`);
|
||||
throw err;
|
||||
}
|
||||
|
||||
this.logger.info({sdp: this.uac.remote.sdp}, `SrsClient:start - successfully connected to SRS ${this.srsUrl}`);
|
||||
response = await this.subscribeAnswer({
|
||||
...opts,
|
||||
sdp: this.uac.remote.sdp,
|
||||
'to-tag': response['to-tag'],
|
||||
label: '2'
|
||||
});
|
||||
if (response.result !== 'ok') {
|
||||
this.logger.error({response}, 'SrsClient:start error calling subscribe answer');
|
||||
throw new Error('error calling subscribe answer');
|
||||
}
|
||||
|
||||
this.activated = true;
|
||||
this.logger.info('successfully established siprec connection');
|
||||
return true;
|
||||
}
|
||||
|
||||
async stop() {
|
||||
assert(this.activated);
|
||||
const opts = {
|
||||
'call-id': this.rtpEngineOpts.common['call-id'],
|
||||
'from-tag': this.sipRecFromTag
|
||||
};
|
||||
|
||||
this.del(opts)
|
||||
//.then((response) => this.logger.debug({response}, 'Successfully stopped siprec media'))
|
||||
.catch((err) => this.logger.info({err}, 'Error deleting siprec media session'));
|
||||
this.uac.destroy().catch(() => {});
|
||||
this.activated = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
async pause() {
|
||||
assert(!this.paused);
|
||||
const opts = {
|
||||
'call-id': this.rtpEngineOpts.common['call-id'],
|
||||
'from-tag': this.sipRecFromTag
|
||||
};
|
||||
try {
|
||||
await this.blockMedia(opts);
|
||||
await this.uac.modify(this.sdpOffer.replace(/sendonly/g, 'inactive'));
|
||||
this.paused = true;
|
||||
return true;
|
||||
} catch (err) {
|
||||
this.logger.info({err}, 'Error pausing siprec media session');
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
async resume() {
|
||||
assert(this.paused);
|
||||
const opts = {
|
||||
'call-id': this.rtpEngineOpts.common['call-id'],
|
||||
'from-tag': this.sipRecFromTag
|
||||
};
|
||||
try {
|
||||
await this.blockMedia(opts);
|
||||
await this.uac.modify(this.sdpOffer);
|
||||
} catch (err) {
|
||||
this.logger.info({err}, 'Error resuming siprec media session');
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = SrsClient;
|
||||
+8
-2
@@ -15,7 +15,13 @@ 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 srcOpts = srcIsUsingSrtp ? srtpOpts : rtpCharacteristics;
|
||||
|
||||
/* webrtc clients (e.g. sipjs) send DMTF via SIP INFO */
|
||||
if ((srcIsUsingSrtp || dstIsUsingSrtp) && !teams) {
|
||||
dstOpts.flags.push('inject DTMF');
|
||||
srcOpts.flags.push('inject DTMF');
|
||||
}
|
||||
const common = {
|
||||
'call-id': req.get('Call-ID'),
|
||||
'replace': ['origin', 'session-connection']
|
||||
@@ -24,7 +30,7 @@ function makeRtpEngineOpts(req, srcIsUsingSrtp, dstIsUsingSrtp, teams = false) {
|
||||
common,
|
||||
uas: {
|
||||
tag: from.params.tag,
|
||||
mediaOpts: srctOpts
|
||||
mediaOpts: srcOpts
|
||||
},
|
||||
uac: {
|
||||
tag: null,
|
||||
|
||||
Generated
+43
-24
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "sbc-inbound",
|
||||
"version": "v0.7.5",
|
||||
"version": "v0.7.6",
|
||||
"lockfileVersion": 2,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "sbc-inbound",
|
||||
"version": "v0.7.5",
|
||||
"version": "v0.7.6",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@jambonz/db-helpers": "^0.6.18",
|
||||
@@ -14,14 +14,15 @@
|
||||
"@jambonz/http-health-check": "^0.0.1",
|
||||
"@jambonz/realtimedb-helpers": "^0.4.29",
|
||||
"@jambonz/rtpengine-utils": "^0.3.1",
|
||||
"@jambonz/siprec-client-utils": "^0.1.4",
|
||||
"@jambonz/stats-collector": "^0.1.6",
|
||||
"@jambonz/time-series": "^0.1.9",
|
||||
"@jambonz/time-series": "^0.1.12",
|
||||
"aws-sdk": "^2.1152.0",
|
||||
"bent": "^7.3.12",
|
||||
"cidr-matcher": "^2.1.1",
|
||||
"debug": "^4.3.4",
|
||||
"drachtio-fn-b2b-sugar": "0.0.12",
|
||||
"drachtio-srf": "^4.5.0",
|
||||
"drachtio-srf": "^4.5.1",
|
||||
"express": "^4.18.1",
|
||||
"pino": "^7.11.0",
|
||||
"sdp-transform": "^2.14.1",
|
||||
@@ -690,6 +691,15 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"node_modules/@jambonz/siprec-client-utils": {
|
||||
"version": "0.1.4",
|
||||
"resolved": "https://registry.npmjs.org/@jambonz/siprec-client-utils/-/siprec-client-utils-0.1.4.tgz",
|
||||
"integrity": "sha512-5UZLjR9Qg06nOUQFkGw09wpc5fY7fF7Zws2poCt3ZWG2v2FXn61nXKT0DYVYsPpHIVOvPcPetxxeU/cJZtoTxw==",
|
||||
"dependencies": {
|
||||
"sdp-transform": "^2.14.1",
|
||||
"uuid": "^8.3.2"
|
||||
}
|
||||
},
|
||||
"node_modules/@jambonz/stats-collector": {
|
||||
"version": "0.1.6",
|
||||
"resolved": "https://registry.npmjs.org/@jambonz/stats-collector/-/stats-collector-0.1.6.tgz",
|
||||
@@ -700,12 +710,12 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@jambonz/time-series": {
|
||||
"version": "0.1.9",
|
||||
"resolved": "https://registry.npmjs.org/@jambonz/time-series/-/time-series-0.1.9.tgz",
|
||||
"integrity": "sha512-FLD7mLGEMToG7s6LGWr/GtNp61753RBxyYuKSxCVI6G14bm6ydgcBdG85h8EGTVQlIp9dnwbn5ebSVsGb8a46w==",
|
||||
"version": "0.1.12",
|
||||
"resolved": "https://registry.npmjs.org/@jambonz/time-series/-/time-series-0.1.12.tgz",
|
||||
"integrity": "sha512-TmCG4jcI8oK3NXOc4/PbdRhhMVLEr5FOyG4IIWpNlwB0vbjAGLY3K+O5PF4fXK+UcNYnIrUcrd2C0J9z3+YBxw==",
|
||||
"dependencies": {
|
||||
"debug": "^4.3.1",
|
||||
"influx": "^5.8.0"
|
||||
"influx": "^5.9.3"
|
||||
}
|
||||
},
|
||||
"node_modules/@protobufjs/aspromise": {
|
||||
@@ -1592,9 +1602,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/drachtio-srf": {
|
||||
"version": "4.5.0",
|
||||
"resolved": "https://registry.npmjs.org/drachtio-srf/-/drachtio-srf-4.5.0.tgz",
|
||||
"integrity": "sha512-3Y3H+HDvur5m8b8vChGFt0ywVETnhmKX6kUvpc7/k1cKIGBfoba2xluUsLcknS2p7yYu9TQWKGd5XZacPpU3Dg==",
|
||||
"version": "4.5.1",
|
||||
"resolved": "https://registry.npmjs.org/drachtio-srf/-/drachtio-srf-4.5.1.tgz",
|
||||
"integrity": "sha512-7U8hhMrVIc33ysSUcbg64fDcx2jvqY4h/NdzhYsiU6tQ2fbkd0jzNYR6KD3dqhEzGxRAeEgcaPuQEG0+K2qVIA==",
|
||||
"dependencies": {
|
||||
"debug": "^3.2.7",
|
||||
"delegates": "^0.1.0",
|
||||
@@ -2799,9 +2809,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/influx": {
|
||||
"version": "5.9.0",
|
||||
"resolved": "https://registry.npmjs.org/influx/-/influx-5.9.0.tgz",
|
||||
"integrity": "sha512-oAG5tpxzWep7cA+1ybEK0HIptuBGK+DwObeSmsIRr9VXBf4ggN/vqSUqlvgQpjEoeUNr2tphHZJWc9n33sle9A=="
|
||||
"version": "5.9.3",
|
||||
"resolved": "https://registry.npmjs.org/influx/-/influx-5.9.3.tgz",
|
||||
"integrity": "sha512-QQU9CgwnaEV6zMrK8+vhVItsdoKFqDioXJrjJhRQaff9utvT3N0jcrQJT9qnxFLktqgJ5ngbDY68Zh4eo4uD/w=="
|
||||
},
|
||||
"node_modules/inherits": {
|
||||
"version": "2.0.4",
|
||||
@@ -5852,6 +5862,15 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"@jambonz/siprec-client-utils": {
|
||||
"version": "0.1.4",
|
||||
"resolved": "https://registry.npmjs.org/@jambonz/siprec-client-utils/-/siprec-client-utils-0.1.4.tgz",
|
||||
"integrity": "sha512-5UZLjR9Qg06nOUQFkGw09wpc5fY7fF7Zws2poCt3ZWG2v2FXn61nXKT0DYVYsPpHIVOvPcPetxxeU/cJZtoTxw==",
|
||||
"requires": {
|
||||
"sdp-transform": "^2.14.1",
|
||||
"uuid": "^8.3.2"
|
||||
}
|
||||
},
|
||||
"@jambonz/stats-collector": {
|
||||
"version": "0.1.6",
|
||||
"resolved": "https://registry.npmjs.org/@jambonz/stats-collector/-/stats-collector-0.1.6.tgz",
|
||||
@@ -5862,12 +5881,12 @@
|
||||
}
|
||||
},
|
||||
"@jambonz/time-series": {
|
||||
"version": "0.1.9",
|
||||
"resolved": "https://registry.npmjs.org/@jambonz/time-series/-/time-series-0.1.9.tgz",
|
||||
"integrity": "sha512-FLD7mLGEMToG7s6LGWr/GtNp61753RBxyYuKSxCVI6G14bm6ydgcBdG85h8EGTVQlIp9dnwbn5ebSVsGb8a46w==",
|
||||
"version": "0.1.12",
|
||||
"resolved": "https://registry.npmjs.org/@jambonz/time-series/-/time-series-0.1.12.tgz",
|
||||
"integrity": "sha512-TmCG4jcI8oK3NXOc4/PbdRhhMVLEr5FOyG4IIWpNlwB0vbjAGLY3K+O5PF4fXK+UcNYnIrUcrd2C0J9z3+YBxw==",
|
||||
"requires": {
|
||||
"debug": "^4.3.1",
|
||||
"influx": "^5.8.0"
|
||||
"influx": "^5.9.3"
|
||||
}
|
||||
},
|
||||
"@protobufjs/aspromise": {
|
||||
@@ -6564,9 +6583,9 @@
|
||||
"requires": {}
|
||||
},
|
||||
"drachtio-srf": {
|
||||
"version": "4.5.0",
|
||||
"resolved": "https://registry.npmjs.org/drachtio-srf/-/drachtio-srf-4.5.0.tgz",
|
||||
"integrity": "sha512-3Y3H+HDvur5m8b8vChGFt0ywVETnhmKX6kUvpc7/k1cKIGBfoba2xluUsLcknS2p7yYu9TQWKGd5XZacPpU3Dg==",
|
||||
"version": "4.5.1",
|
||||
"resolved": "https://registry.npmjs.org/drachtio-srf/-/drachtio-srf-4.5.1.tgz",
|
||||
"integrity": "sha512-7U8hhMrVIc33ysSUcbg64fDcx2jvqY4h/NdzhYsiU6tQ2fbkd0jzNYR6KD3dqhEzGxRAeEgcaPuQEG0+K2qVIA==",
|
||||
"requires": {
|
||||
"debug": "^3.2.7",
|
||||
"delegates": "^0.1.0",
|
||||
@@ -7490,9 +7509,9 @@
|
||||
}
|
||||
},
|
||||
"influx": {
|
||||
"version": "5.9.0",
|
||||
"resolved": "https://registry.npmjs.org/influx/-/influx-5.9.0.tgz",
|
||||
"integrity": "sha512-oAG5tpxzWep7cA+1ybEK0HIptuBGK+DwObeSmsIRr9VXBf4ggN/vqSUqlvgQpjEoeUNr2tphHZJWc9n33sle9A=="
|
||||
"version": "5.9.3",
|
||||
"resolved": "https://registry.npmjs.org/influx/-/influx-5.9.3.tgz",
|
||||
"integrity": "sha512-QQU9CgwnaEV6zMrK8+vhVItsdoKFqDioXJrjJhRQaff9utvT3N0jcrQJT9qnxFLktqgJ5ngbDY68Zh4eo4uD/w=="
|
||||
},
|
||||
"inherits": {
|
||||
"version": "2.0.4",
|
||||
|
||||
+4
-3
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "sbc-inbound",
|
||||
"version": "v0.7.5",
|
||||
"version": "v0.7.6",
|
||||
"main": "app.js",
|
||||
"engines": {
|
||||
"node": ">= 12.0.0"
|
||||
@@ -30,14 +30,15 @@
|
||||
"@jambonz/http-health-check": "^0.0.1",
|
||||
"@jambonz/realtimedb-helpers": "^0.4.29",
|
||||
"@jambonz/rtpengine-utils": "^0.3.1",
|
||||
"@jambonz/siprec-client-utils": "^0.1.4",
|
||||
"@jambonz/stats-collector": "^0.1.6",
|
||||
"@jambonz/time-series": "^0.1.9",
|
||||
"@jambonz/time-series": "^0.1.12",
|
||||
"aws-sdk": "^2.1152.0",
|
||||
"bent": "^7.3.12",
|
||||
"cidr-matcher": "^2.1.1",
|
||||
"debug": "^4.3.4",
|
||||
"drachtio-fn-b2b-sugar": "0.0.12",
|
||||
"drachtio-srf": "^4.5.0",
|
||||
"drachtio-srf": "^4.5.1",
|
||||
"express": "^4.18.1",
|
||||
"pino": "^7.11.0",
|
||||
"sdp-transform": "^2.14.1",
|
||||
|
||||
Reference in New Issue
Block a user