diff --git a/lib/middleware.js b/lib/middleware.js index 9c123260..72820b77 100644 --- a/lib/middleware.js +++ b/lib/middleware.js @@ -59,7 +59,7 @@ module.exports = function(srf, logger) { } // check for call to application - if (uri.user?.startsWith('app-') && req.locals.originatingUser && clientDb.allow_direct_app_calling) { + if (uri.user?.startsWith('app-') && req.locals.originatingUser && clientDb?.allow_direct_app_calling) { const application_sid = uri.user.match(/app-(.*)/)[1]; logger.debug(`got application from Request URI header: ${application_sid}`); req.locals.application_sid = application_sid; @@ -69,13 +69,13 @@ module.exports = function(srf, logger) { req.locals.application_sid = application_sid; } // check for call to queue - if (uri.user?.startsWith('queue-') && req.locals.originatingUser && clientDb.allow_direct_queue_calling) { + if (uri.user?.startsWith('queue-') && req.locals.originatingUser && clientDb?.allow_direct_queue_calling) { const queue_name = uri.user.match(/queue-(.*)/)[1]; logger.debug(`got Queue from Request URI header: ${queue_name}`); req.locals.queue_name = queue_name; } // check for call to registered user - if (!JAMBONES_DISABLE_DIRECT_P2P_CALL && req.locals.originatingUser && clientDb.allow_direct_user_calling) { + if (!JAMBONES_DISABLE_DIRECT_P2P_CALL && req.locals.originatingUser && clientDb?.allow_direct_user_calling) { const arr = /^(.*)@(.*)/.exec(req.locals.originatingUser); if (arr) { const sipRealm = arr[2]; diff --git a/lib/session/adulting-call-session.js b/lib/session/adulting-call-session.js index db004107..6237b791 100644 --- a/lib/session/adulting-call-session.js +++ b/lib/session/adulting-call-session.js @@ -19,6 +19,7 @@ class AdultingCallSession extends CallSession { rootSpan }); this.sd = singleDialer; + this.req = callInfo.req; this.sd.dlg.on('destroy', () => { this.logger.info('AdultingCallSession: called party hung up'); diff --git a/lib/tasks/transcribe.js b/lib/tasks/transcribe.js index 3ad38a57..4f2de6ef 100644 --- a/lib/tasks/transcribe.js +++ b/lib/tasks/transcribe.js @@ -219,10 +219,6 @@ class TaskTranscribe extends SttTask { this.bugname = 'nuance_transcribe'; ep.addCustomEventListener(NuanceTranscriptionEvents.Transcription, this._onTranscription.bind(this, cs, ep, channel)); - ep.addCustomEventListener(NuanceTranscriptionEvents.StartOfSpeech, - this._onStartOfSpeech.bind(this, cs, ep, channel)); - ep.addCustomEventListener(NuanceTranscriptionEvents.TranscriptionComplete, - this._onTranscriptionComplete.bind(this, cs, ep, channel)); break; case 'deepgram': this.bugname = 'deepgram_transcribe'; @@ -286,12 +282,6 @@ class TaskTranscribe extends SttTask { this.bugname = 'nvidia_transcribe'; ep.addCustomEventListener(NvidiaTranscriptionEvents.Transcription, this._onTranscription.bind(this, cs, ep)); - ep.addCustomEventListener(NvidiaTranscriptionEvents.StartOfSpeech, - this._onStartOfSpeech.bind(this, cs, ep)); - ep.addCustomEventListener(NvidiaTranscriptionEvents.TranscriptionComplete, - this._onTranscriptionComplete.bind(this, cs, ep)); - ep.addCustomEventListener(NvidiaTranscriptionEvents.VadDetected, - this._onVadDetected.bind(this, cs, ep)); break; case 'assemblyai': @@ -309,9 +299,9 @@ class TaskTranscribe extends SttTask { this.bugname = `${this.vendor}_transcribe`; ep.addCustomEventListener(JambonzTranscriptionEvents.Transcription, this._onTranscription.bind(this, cs, ep, channel)); - ep.addCustomEventListener(JambonzTranscriptionEvents.Connect, this._onJambonzConnect.bind(this, cs, ep)); + ep.addCustomEventListener(JambonzTranscriptionEvents.Connect, this._onVendorConnect.bind(this, cs, ep)); ep.addCustomEventListener(JambonzTranscriptionEvents.ConnectFailure, - this._onJambonzConnectFailure.bind(this, cs, ep)); + this._onVendorConnectFailure.bind(this, cs, ep)); break; } else { diff --git a/lib/utils/place-outdial.js b/lib/utils/place-outdial.js index ecdc127b..28e1eac5 100644 --- a/lib/utils/place-outdial.js +++ b/lib/utils/place-outdial.js @@ -13,6 +13,8 @@ const moment = require('moment'); const stripCodecs = require('./strip-ancillary-codecs'); const RootSpan = require('./call-tracer'); const uuidv4 = require('uuid-random'); +const HttpRequestor = require('./http-requestor'); +const WsRequestor = require('./ws-requestor'); class SingleDialer extends Emitter { constructor({logger, sbcAddress, target, opts, application, callInfo, accountInfo, rootSpan, startSpan, dialTask}) { @@ -177,6 +179,7 @@ class SingleDialer extends Emitter { * (a) create a logger for this call */ req.srf = srf; + this.req = req; this.callInfo = new CallInfo({ direction: CallDirection.Outbound, parentCallInfo: this.parentCallInfo, @@ -383,15 +386,35 @@ class SingleDialer extends Emitter { this.dlg.linkedSpanId = this.rootSpan.traceId; const rootSpan = new RootSpan('outbound-call', this.dlg); const newLogger = logger.child({traceId: rootSpan.traceId}); + //clone application from parent call with new requestor + //parrent application will be closed in case the parent hangup + const app = {...application}; + if ('WS' === app.call_hook?.method || + app.call_hook?.url.startsWith('ws://') || app.call_hook?.url.startsWith('wss://')) { + const requestor = new WsRequestor(logger, this.accountInfo.account.account_sid, + app.call_hook, this.accountInfo.account.webhook_secret); + app.requestor = requestor; + app.notifier = requestor; + app.call_hook.method = 'WS'; + } + else { + app.requestor = new HttpRequestor(logger, this.accountInfo.account.account_sid, + app.call_hook, this.accountInfo.account.webhook_secret); + if (app.call_status_hook) app.notifier = new HttpRequestor(logger, + this.accountInfo.account.account_sid, app.call_status_hook, + this.accountInfo.account.webhook_secret); + else app.notifier = {request: () => {}, close: () => {}}; + } const cs = new AdultingCallSession({ logger: newLogger, singleDialer: this, - application, + application: app, callInfo: this.callInfo, accountInfo: this.accountInfo, tasks, rootSpan }); + cs.req = this.req; cs.exec().catch((err) => newLogger.error({err}, 'doAdulting: error executing session')); return cs; }