feat Audult call session should have its own requestor (#535)

* feat Audult call session should have its own requestor

* fix eslint

* fix eslint

* if user authenticate from http server instead of databse

* wip

* fix custom STT

* fix custom STT

* fix custom STT
This commit is contained in:
Hoan Luu Huu
2023-11-16 20:22:35 +07:00
committed by GitHub
parent 9ae4b04fc5
commit 1cdd0cf611
4 changed files with 30 additions and 16 deletions

View File

@@ -59,7 +59,7 @@ module.exports = function(srf, logger) {
} }
// check for call to application // 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]; const application_sid = uri.user.match(/app-(.*)/)[1];
logger.debug(`got application from Request URI header: ${application_sid}`); logger.debug(`got application from Request URI header: ${application_sid}`);
req.locals.application_sid = application_sid; req.locals.application_sid = application_sid;
@@ -69,13 +69,13 @@ module.exports = function(srf, logger) {
req.locals.application_sid = application_sid; req.locals.application_sid = application_sid;
} }
// check for call to queue // 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]; const queue_name = uri.user.match(/queue-(.*)/)[1];
logger.debug(`got Queue from Request URI header: ${queue_name}`); logger.debug(`got Queue from Request URI header: ${queue_name}`);
req.locals.queue_name = queue_name; req.locals.queue_name = queue_name;
} }
// check for call to registered user // 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); const arr = /^(.*)@(.*)/.exec(req.locals.originatingUser);
if (arr) { if (arr) {
const sipRealm = arr[2]; const sipRealm = arr[2];

View File

@@ -19,6 +19,7 @@ class AdultingCallSession extends CallSession {
rootSpan rootSpan
}); });
this.sd = singleDialer; this.sd = singleDialer;
this.req = callInfo.req;
this.sd.dlg.on('destroy', () => { this.sd.dlg.on('destroy', () => {
this.logger.info('AdultingCallSession: called party hung up'); this.logger.info('AdultingCallSession: called party hung up');

View File

@@ -219,10 +219,6 @@ class TaskTranscribe extends SttTask {
this.bugname = 'nuance_transcribe'; this.bugname = 'nuance_transcribe';
ep.addCustomEventListener(NuanceTranscriptionEvents.Transcription, ep.addCustomEventListener(NuanceTranscriptionEvents.Transcription,
this._onTranscription.bind(this, cs, ep, channel)); 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; break;
case 'deepgram': case 'deepgram':
this.bugname = 'deepgram_transcribe'; this.bugname = 'deepgram_transcribe';
@@ -286,12 +282,6 @@ class TaskTranscribe extends SttTask {
this.bugname = 'nvidia_transcribe'; this.bugname = 'nvidia_transcribe';
ep.addCustomEventListener(NvidiaTranscriptionEvents.Transcription, ep.addCustomEventListener(NvidiaTranscriptionEvents.Transcription,
this._onTranscription.bind(this, cs, ep)); 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; break;
case 'assemblyai': case 'assemblyai':
@@ -309,9 +299,9 @@ class TaskTranscribe extends SttTask {
this.bugname = `${this.vendor}_transcribe`; this.bugname = `${this.vendor}_transcribe`;
ep.addCustomEventListener(JambonzTranscriptionEvents.Transcription, ep.addCustomEventListener(JambonzTranscriptionEvents.Transcription,
this._onTranscription.bind(this, cs, ep, channel)); 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, ep.addCustomEventListener(JambonzTranscriptionEvents.ConnectFailure,
this._onJambonzConnectFailure.bind(this, cs, ep)); this._onVendorConnectFailure.bind(this, cs, ep));
break; break;
} }
else { else {

View File

@@ -13,6 +13,8 @@ const moment = require('moment');
const stripCodecs = require('./strip-ancillary-codecs'); const stripCodecs = require('./strip-ancillary-codecs');
const RootSpan = require('./call-tracer'); const RootSpan = require('./call-tracer');
const uuidv4 = require('uuid-random'); const uuidv4 = require('uuid-random');
const HttpRequestor = require('./http-requestor');
const WsRequestor = require('./ws-requestor');
class SingleDialer extends Emitter { class SingleDialer extends Emitter {
constructor({logger, sbcAddress, target, opts, application, callInfo, accountInfo, rootSpan, startSpan, dialTask}) { 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 * (a) create a logger for this call
*/ */
req.srf = srf; req.srf = srf;
this.req = req;
this.callInfo = new CallInfo({ this.callInfo = new CallInfo({
direction: CallDirection.Outbound, direction: CallDirection.Outbound,
parentCallInfo: this.parentCallInfo, parentCallInfo: this.parentCallInfo,
@@ -383,15 +386,35 @@ class SingleDialer extends Emitter {
this.dlg.linkedSpanId = this.rootSpan.traceId; this.dlg.linkedSpanId = this.rootSpan.traceId;
const rootSpan = new RootSpan('outbound-call', this.dlg); const rootSpan = new RootSpan('outbound-call', this.dlg);
const newLogger = logger.child({traceId: rootSpan.traceId}); 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({ const cs = new AdultingCallSession({
logger: newLogger, logger: newLogger,
singleDialer: this, singleDialer: this,
application, application: app,
callInfo: this.callInfo, callInfo: this.callInfo,
accountInfo: this.accountInfo, accountInfo: this.accountInfo,
tasks, tasks,
rootSpan rootSpan
}); });
cs.req = this.req;
cs.exec().catch((err) => newLogger.error({err}, 'doAdulting: error executing session')); cs.exec().catch((err) => newLogger.error({err}, 'doAdulting: error executing session'));
return cs; return cs;
} }