Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
srf.subscribe((req, res) => {
this.logger.info(`UAC subscribing: ${req.protocol}/${req.source_address}:${req.source_port}`) ;
// only registered users are allowed to subscribe
const from = req.getParsedHeader('from') ;
const fromUser = parseUri(from.uri).user ;
const callid = req.get('Call-Id');
if (!registrar.hasUser(fromUser)) {
this.logger.fino(`invalid/unknown user ${fromUser} attempting to subscribe`) ;
return res.send(503);
}
// check if we have a call-id / cseq that we used previously on a 401-challenged SUBSCRIBE
const headers = {} ;
const obj = registrar.getNextCallIdAndCSeq(callid) ;
if (obj) {
Object.assign(headers, obj) ;
registrar.removeTransaction(callid) ;
}
else {
Object.assign(headers, {'CSeq': '1 INVITE'}) ;
if (arr) {
const uri = parseUri(arr[1]);
const user = uri.user || 'anonymous';
opts.caller.aor = `sip:${user}@${uri.host}`;
}
const dname = r1[1].trim();
const arr2 = /"(.*)"/.exec(dname);
if (arr2) opts.caller.name = arr2[1];
else opts.caller.name = dname;
}
// callee
r1 = /^(.*)(/.exec(r1[2]);
if (arr) {
const uri = parseUri(arr[1]);
opts.callee.aor = `sip:${uri.user}@${uri.host}`;
}
const dname = r1[1].trim();
const arr2 = /"(.*)"/.exec(dname);
if (arr2) opts.callee.name = arr2[1];
else opts.callee.name = dname;
}
debug(`opts.caller from callData: ${JSON.stringify(opts.caller)}`);
debug(`opts.callee from callData: ${JSON.stringify(opts.callee)}`);
}
if (opts.caller.aor && 0 !== opts.caller.aor.indexOf('sip:')) {
opts.caller.aor = 'sip:' + opts.caller.aor;
}
if (opts.callee.aor && 0 !== opts.callee.aor.indexOf('sip:')) {
opts.callee.aor = 'sip:' + opts.callee.aor;
srf.register(mw, (req, res) => {
const callid = req.get('Call-Id');
debug(`UAC registering: ${req.protocol}/${req.source_address}:${req.source_port} with uri ${req.uri}`) ;
if (!isValidRegister(req)) {
this.logger.info(`invalid register request: ${req.get('Call-Id')} ${req.get('CSeq')}`) ;
return res.send(503);
}
const instanceId = req.registration.contact[0].params['+sip.instance'] ;
const regId = req.registration.contact[0].params['reg-id'] ;
const uri = parseUri(req.uri) ;
const headers = {} ;
// check if we have a call-id / cseq that we are using for this transaction
const obj = registrar.getNextCallIdAndCSeq(callid) ;
if (obj) {
Object.assign(headers, obj) ;
}
else {
Object.assign(headers, {'CSeq': '1 REGISTER'}) ;
}
['from', 'to', 'authorization', 'supported', 'allow', 'user-agent'].forEach((hdr) => {
if (req.has(hdr)) headers[hdr] = req.get(hdr) ;
}) ;
const uacContact = req.getParsedHeader('Contact') ;
// check if we have a call-id / cseq that we are using for this transaction
const obj = registrar.getNextCallIdAndCSeq(callid) ;
if (obj) {
Object.assign(headers, obj) ;
}
else {
Object.assign(headers, {'CSeq': '1 REGISTER'}) ;
}
['from', 'to', 'authorization', 'supported', 'allow', 'user-agent'].forEach((hdr) => {
if (req.has(hdr)) headers[hdr] = req.get(hdr) ;
}) ;
const uacContact = req.getParsedHeader('Contact') ;
const from = req.getParsedHeader('From') ;
const user = parseUri(from.uri).user ;
// NB: drachtio server will replace 'localhost' appropriately
headers.contact = `;expires=${req.registration.expires}` ;
srf.request({
uri: req.uri,
method: req.method,
headers
}, (err, request) => {
if (err) {
return this.logger.info(`Error forwarding register to ${uri.host}: ${err}`);
}
request.on('response', (response) => {
const headers = {} ;
['www-authenticate'].forEach((hdr) => {
if (response.has(hdr)) headers[hdr] = response.get(hdr);
srf.invite((req, res) => {
this.logger.info(
`received invite from ${req.protocol}/${req.source_address}:${req.uri} with request uri ${req.uri}`);
// determine whether this is a call from or to a webrtc client
const callid = req.get('Call-Id');
const from = req.getParsedHeader('From');
let remoteUri = req.uri ;
let direction = 'outbound' ;
const parsedUri = parseUri(req.uri);
const user = parsedUri.user ;
const trunk = parsedUri.host;
const rtpEngineIdentifyingDetails = {
'call-id': callid,
'from-tag': from.params.tag,
} ;
const voipProviderFacingProxyCharacteristics = {
'transport protocol': 'RTP/AVP',
'DTLS': 'off',
'SDES': 'off',
'ICE': 'remove',
'rtcp-mux': ['demux']
};
const webrtcFacingProxyCharacteristics = {
'ICE': 'force',
const parseUri = require('drachtio-srf').parseUri ;
const SipError = require('drachtio-srf').SipError;
const config = require('config');
const debug = require('debug')('drachtio-rtpengine-webrtcproxy') ;
class CallProcessor {
/**
* creates an instance of the call processor. this is intended to be a singleton instance.
* you call the 'start' method to kick it off
*/
constructor(logger) {
this._logger = logger;
// we need to track these only so we can fixup REFER messages for attended transfer
this.calls = new Map() ;
}
if (opts.caller.aor) {
let user;
const uri = parseUri(opts.caller.aor);
if (uri) user = uri.user;
else {
const arr = /sip:(.*)@/.exec(opts.caller.aor);
if (arr) {
user = arr[1];
}
}
debug(`parsed user ${user} from caller aor ${opts.caller.aor}`);
opts.caller.number = user;
}
if (opts.callee.aor) {
let user;
const uri = parseUri(opts.callee.aor);
if (uri) user = uri.user;
else {
const arr = /sip:(.*)@/.exec(opts.callee.aor);
if (arr) {
user = arr[1];
}
}
debug(`parsed user ${user} from callee aor ${opts.callee.aor}`);
opts.callee.number = user;
}
opts.recordingSessionId = opts.recordingData[`${prefix}recording`][`${prefix}session`][0].$.session_id;
}
}
catch (err) {
console.log(`Error parsing ${err}`);
reject(err);
const parseUri = require('drachtio-srf').parseUri ;
const SipError = require('drachtio-srf').SipError;
class Subscriber {
constructor(logger) {
this._logger = logger;
}
get logger() {
return this._logger;
}
start(srf, registrar) {
srf.subscribe((req, res) => {
this.logger.info(`UAC subscribing: ${req.protocol}/${req.source_address}:${req.source_port}`) ;