Compare commits

..

2 Commits

Author SHA1 Message Date
Quan HL
3aff0b4486 fs only stop one of bugname when transcribe is used for dual legs 2024-01-06 14:58:48 +07:00
Quan HL
faeaf2daae feat override synthesizer options from config 2024-01-05 21:23:11 +07:00
10 changed files with 46 additions and 90 deletions

View File

@@ -120,7 +120,6 @@ const HTTP_TIMEOUT = 10000;
const HTTP_PROXY_IP = process.env.JAMBONES_HTTP_PROXY_IP; const HTTP_PROXY_IP = process.env.JAMBONES_HTTP_PROXY_IP;
const HTTP_PROXY_PORT = process.env.JAMBONES_HTTP_PROXY_PORT; const HTTP_PROXY_PORT = process.env.JAMBONES_HTTP_PROXY_PORT;
const HTTP_PROXY_PROTOCOL = process.env.JAMBONES_HTTP_PROXY_PROTOCOL || 'http'; const HTTP_PROXY_PROTOCOL = process.env.JAMBONES_HTTP_PROXY_PROTOCOL || 'http';
const HTTP_USER_AGENT_HEADER = process.env.JAMBONES_HTTP_USER_AGENT_HEADER || 'jambonz';
const OPTIONS_PING_INTERVAL = parseInt(process.env.OPTIONS_PING_INTERVAL, 10) || 30000; const OPTIONS_PING_INTERVAL = parseInt(process.env.OPTIONS_PING_INTERVAL, 10) || 30000;
@@ -130,8 +129,6 @@ const JAMBONZ_RECORD_WS_PASSWORD = process.env.JAMBONZ_RECORD_WS_PASSWORD || pro
const JAMBONZ_DISABLE_DIAL_PAI_HEADER = process.env.JAMBONZ_DISABLE_DIAL_PAI_HEADER || false; const JAMBONZ_DISABLE_DIAL_PAI_HEADER = process.env.JAMBONZ_DISABLE_DIAL_PAI_HEADER || false;
const JAMBONES_DISABLE_DIRECT_P2P_CALL = process.env.JAMBONES_DISABLE_DIRECT_P2P_CALL || false; const JAMBONES_DISABLE_DIRECT_P2P_CALL = process.env.JAMBONES_DISABLE_DIRECT_P2P_CALL || false;
const JAMBONES_EAGERLY_PRE_CACHE_AUDIO = process.env.JAMBONES_EAGERLY_PRE_CACHE_AUDIO;
module.exports = { module.exports = {
JAMBONES_MYSQL_HOST, JAMBONES_MYSQL_HOST,
JAMBONES_MYSQL_USER, JAMBONES_MYSQL_USER,
@@ -154,7 +151,6 @@ module.exports = {
JAMBONES_API_BASE_URL, JAMBONES_API_BASE_URL,
JAMBONES_TIME_SERIES_HOST, JAMBONES_TIME_SERIES_HOST,
JAMBONES_INJECT_CONTENT, JAMBONES_INJECT_CONTENT,
JAMBONES_EAGERLY_PRE_CACHE_AUDIO,
JAMBONES_ESL_LISTEN_ADDRESS, JAMBONES_ESL_LISTEN_ADDRESS,
JAMBONES_SBCS, JAMBONES_SBCS,
JAMBONES_OTEL_ENABLED, JAMBONES_OTEL_ENABLED,
@@ -197,7 +193,6 @@ module.exports = {
HTTP_PROXY_IP, HTTP_PROXY_IP,
HTTP_PROXY_PORT, HTTP_PROXY_PORT,
HTTP_PROXY_PROTOCOL, HTTP_PROXY_PROTOCOL,
HTTP_USER_AGENT_HEADER,
OPTIONS_PING_INTERVAL, OPTIONS_PING_INTERVAL,
RESPONSE_TIMEOUT_MS, RESPONSE_TIMEOUT_MS,
JAMBONES_WS_HANDSHAKE_TIMEOUT_MS, JAMBONES_WS_HANDSHAKE_TIMEOUT_MS,

View File

@@ -382,7 +382,7 @@ module.exports = function(srf, logger) {
}, },
recognizer: { recognizer: {
vendor: app.speech_recognizer_vendor, vendor: app.speech_recognizer_vendor,
...(app.speech_recognizer_label && {label: app.speech_recognizer_label}), ...(app.speech_synthesis_label && {label: app.speech_synthesis_label}),
language: app.speech_recognizer_language, language: app.speech_recognizer_language,
...(app.fallback_speech_recognizer_vendor && {fallback_vendor: app.fallback_speech_recognizer_vendor}), ...(app.fallback_speech_recognizer_vendor && {fallback_vendor: app.fallback_speech_recognizer_vendor}),
...(app.fallback_speech_recognizer_label && {fallback_label: app.fallback_speech_recognizer_label}), ...(app.fallback_speech_recognizer_label && {fallback_label: app.fallback_speech_recognizer_label}),

View File

@@ -19,7 +19,6 @@ const HttpRequestor = require('../utils/http-requestor');
const WsRequestor = require('../utils/ws-requestor'); const WsRequestor = require('../utils/ws-requestor');
const { const {
JAMBONES_INJECT_CONTENT, JAMBONES_INJECT_CONTENT,
JAMBONES_EAGERLY_PRE_CACHE_AUDIO,
AWS_REGION, AWS_REGION,
} = require('../config'); } = require('../config');
const BackgroundTaskManager = require('../utils/background-task-manager'); const BackgroundTaskManager = require('../utils/background-task-manager');
@@ -1331,35 +1330,6 @@ Duration=${duration} `
this.taskIdx = 0; this.taskIdx = 0;
} }
_preCacheAudio(newTasks) {
for (const task of newTasks) {
if (task.name === TaskName.Config && task.hasSynthesizer) {
/* if they change synthesizer settings don't try to precache */
break;
}
if (task.name === TaskName.Say) {
/* identify vendor language, voice, and label */
const vendor = task.synthesizer.vendor && task.synthesizer.vendor !== 'default' ?
task.synthesizer.vendor :
this.speechSynthesisVendor;
const language = task.synthesizer.language && task.synthesizer.language !== 'default' ?
task.synthesizer.language :
this.speechSynthesisLanguage ;
const voice = task.synthesizer.voice && task.synthesizer.voice !== 'default' ?
task.synthesizer.voice :
this.speechSynthesisVoice;
const label = task.synthesizer.label && task.synthesizer.label !== 'default' ?
task.synthesizer.label :
this.speechSynthesisLabel;
this.logger.info({vendor, language, voice, label},
'CallSession:_preCacheAudio - precaching audio for future prompt');
task._synthesizeWithSpecificVendor(this, this.ep, {vendor, language, voice, label, preCache: true})
.catch((err) => this.logger.error(err, 'CallSession:_preCacheAudio - error precaching audio'));
}
}
}
/** /**
* Append tasks to the current execution stack UNLESS there is a gather in the stack. * Append tasks to the current execution stack UNLESS there is a gather in the stack.
* in that case, insert the tasks before the gather AND if the tasks include * in that case, insert the tasks before the gather AND if the tasks include
@@ -1417,12 +1387,10 @@ Duration=${duration} `
this.replaceApplication(t); this.replaceApplication(t);
} }
else if (JAMBONES_INJECT_CONTENT) { else if (JAMBONES_INJECT_CONTENT) {
if (JAMBONES_EAGERLY_PRE_CACHE_AUDIO) this._preCacheAudio(t);
this._injectTasks(t); this._injectTasks(t);
this.logger.info({tasks: listTaskNames(this.tasks)}, 'CallSession:_onCommand - updated task list'); this.logger.info({tasks: listTaskNames(this.tasks)}, 'CallSession:_onCommand - updated task list');
} }
else { else {
if (JAMBONES_EAGERLY_PRE_CACHE_AUDIO) this._preCacheAudio(t);
this.tasks.push(...t); this.tasks.push(...t);
this.logger.info({tasks: listTaskNames(this.tasks)}, 'CallSession:_onCommand - updated task list'); this.logger.info({tasks: listTaskNames(this.tasks)}, 'CallSession:_onCommand - updated task list');
} }

View File

@@ -323,7 +323,7 @@ class TaskDial extends Task {
const by = parseUri(req.getParsedHeader('Referred-By').uri); const by = parseUri(req.getParsedHeader('Referred-By').uri);
this.logger.info({to}, 'refer to parsed'); this.logger.info({to}, 'refer to parsed');
const json = await cs.requestor.request('verb:hook', this.referHook, { const json = await cs.requestor.request('verb:hook', this.referHook, {
...(callInfo.toJSON()), ...callInfo,
refer_details: { refer_details: {
sip_refer_to: req.get('Refer-To'), sip_refer_to: req.get('Refer-To'),
sip_referred_by: req.get('Referred-By'), sip_referred_by: req.get('Referred-By'),

View File

@@ -59,7 +59,7 @@ class TaskSay extends Task {
} }
} }
async _synthesizeWithSpecificVendor(cs, ep, {vendor, language, voice, label, preCache = false}) { async _synthesizeWithSpecificVendor(cs, ep, {vendor, language, voice, label}) {
const {srf} = cs; const {srf} = cs;
const {updateSpeechCredentialLastUsed} = require('../utils/db-utils')(this.logger, srf); const {updateSpeechCredentialLastUsed} = require('../utils/db-utils')(this.logger, srf);
const {writeAlerts, AlertType, stats} = srf.locals; const {writeAlerts, AlertType, stats} = srf.locals;
@@ -68,6 +68,12 @@ class TaskSay extends Task {
const salt = cs.callSid; const salt = cs.callSid;
let credentials = cs.getSpeechCredentials(vendor, 'tts', label); let credentials = cs.getSpeechCredentials(vendor, 'tts', label);
// override Synthesizer options from config verb
if (cs.synthesizer && cs.synthesizer.options) {
this.options = cs.synthesizer.options;
}
/* parse Nuance voices into name and model */ /* parse Nuance voices into name and model */
let model; let model;
if (vendor === 'nuance' && voice) { if (vendor === 'nuance' && voice) {
@@ -97,7 +103,7 @@ class TaskSay extends Task {
voice = this.options.voice_id || voice; voice = this.options.voice_id || voice;
} }
if (!preCache) this.logger.info({vendor, language, voice, model}, 'TaskSay:exec'); this.logger.info({vendor, language, voice, model}, 'TaskSay:exec');
try { try {
if (!credentials) { if (!credentials) {
writeAlerts({ writeAlerts({
@@ -120,15 +126,11 @@ class TaskSay extends Task {
if (text.startsWith('silence_stream://')) return text; if (text.startsWith('silence_stream://')) return text;
/* otel: trace time for tts */ /* otel: trace time for tts */
let otelSpan; const {span} = this.startChildSpan('tts-generation', {
if (!preCache) { 'tts.vendor': vendor,
const {span} = this.startChildSpan('tts-generation', { 'tts.language': language,
'tts.vendor': vendor, 'tts.voice': voice
'tts.language': language, });
'tts.voice': voice
});
otelSpan = span;
}
try { try {
const {filePath, servedFromCache, rtt} = await synthAudio(stats, { const {filePath, servedFromCache, rtt} = await synthAudio(stats, {
account_sid: cs.accountSid, account_sid: cs.accountSid,
@@ -150,9 +152,9 @@ class TaskSay extends Task {
updateSpeechCredentialLastUsed(credentials.speech_credential_sid) updateSpeechCredentialLastUsed(credentials.speech_credential_sid)
.catch(() => {/*already logged error */}); .catch(() => {/*already logged error */});
} }
if (otelSpan) otelSpan.setAttributes({'tts.cached': servedFromCache}); span.setAttributes({'tts.cached': servedFromCache});
if (otelSpan) otelSpan.end(); span.end();
if (!servedFromCache && rtt && !preCache) { if (!servedFromCache && rtt) {
this.notifyStatus({ this.notifyStatus({
event: 'synthesized-audio', event: 'synthesized-audio',
vendor, vendor,
@@ -164,7 +166,7 @@ class TaskSay extends Task {
return filePath; return filePath;
} catch (err) { } catch (err) {
this.logger.info({err}, 'Error synthesizing tts'); this.logger.info({err}, 'Error synthesizing tts');
if (otelSpan) otelSpan.end(); span.end();
writeAlerts({ writeAlerts({
account_sid: cs.accountSid, account_sid: cs.accountSid,
alert_type: AlertType.TTS_FAILURE, alert_type: AlertType.TTS_FAILURE,

View File

@@ -89,13 +89,13 @@ class TaskTranscribe extends SttTask {
stopTranscription = true; stopTranscription = true;
this.ep.stopTranscription({ this.ep.stopTranscription({
vendor: this.vendor, vendor: this.vendor,
bugname: this.bugname bugname: this.ep.transcribe_bugname
}) })
.catch((err) => this.logger.info(err, 'Error TaskTranscribe:kill')); .catch((err) => this.logger.info(err, 'Error TaskTranscribe:kill'));
} }
if (this.separateRecognitionPerChannel && this.ep2 && this.ep2.connected) { if (this.separateRecognitionPerChannel && this.ep2 && this.ep2.connected) {
stopTranscription = true; stopTranscription = true;
this.ep2.stopTranscription({vendor: this.vendor}) this.ep2.stopTranscription({vendor: this.vendor, bugname: this.ep2.transcribe_bugname})
.catch((err) => this.logger.info(err, 'Error TaskTranscribe:kill')); .catch((err) => this.logger.info(err, 'Error TaskTranscribe:kill'));
} }
@@ -132,6 +132,7 @@ class TaskTranscribe extends SttTask {
async _setSpeechHandlers(cs, ep, channel) { async _setSpeechHandlers(cs, ep, channel) {
if (this[`_speechHandlersSet_${channel}`]) return; if (this[`_speechHandlersSet_${channel}`]) return;
this[`_speechHandlersSet_${channel}`] = true; this[`_speechHandlersSet_${channel}`] = true;
let bugname;
/* some special deepgram logic */ /* some special deepgram logic */
if (this.vendor === 'deepgram') { if (this.vendor === 'deepgram') {
@@ -141,7 +142,7 @@ class TaskTranscribe extends SttTask {
const opts = this.setChannelVarsForStt(this, this.sttCredentials, this.data.recognizer); const opts = this.setChannelVarsForStt(this, this.sttCredentials, this.data.recognizer);
switch (this.vendor) { switch (this.vendor) {
case 'google': case 'google':
this.bugname = `${this.bugname_prefix}google_transcribe`; bugname = `${this.bugname_prefix}google_transcribe_${channel}`;
this.addCustomEventListener(ep, GoogleTranscriptionEvents.Transcription, this.addCustomEventListener(ep, GoogleTranscriptionEvents.Transcription,
this._onTranscription.bind(this, cs, ep, channel)); this._onTranscription.bind(this, cs, ep, channel));
this.addCustomEventListener(ep, GoogleTranscriptionEvents.NoAudioDetected, this.addCustomEventListener(ep, GoogleTranscriptionEvents.NoAudioDetected,
@@ -152,7 +153,7 @@ class TaskTranscribe extends SttTask {
case 'aws': case 'aws':
case 'polly': case 'polly':
this.bugname = `${this.bugname_prefix}aws_transcribe`; bugname = `${this.bugname_prefix}aws_transcribe_${channel}`;
this.addCustomEventListener(ep, AwsTranscriptionEvents.Transcription, this.addCustomEventListener(ep, AwsTranscriptionEvents.Transcription,
this._onTranscription.bind(this, cs, ep, channel)); this._onTranscription.bind(this, cs, ep, channel));
this.addCustomEventListener(ep, AwsTranscriptionEvents.NoAudioDetected, this.addCustomEventListener(ep, AwsTranscriptionEvents.NoAudioDetected,
@@ -161,19 +162,19 @@ class TaskTranscribe extends SttTask {
this._onMaxDurationExceeded.bind(this, cs, ep, channel)); this._onMaxDurationExceeded.bind(this, cs, ep, channel));
break; break;
case 'microsoft': case 'microsoft':
this.bugname = `${this.bugname_prefix}azure_transcribe`; bugname = `${this.bugname_prefix}azure_transcribe_${channel}`;
this.addCustomEventListener(ep, AzureTranscriptionEvents.Transcription, this.addCustomEventListener(ep, AzureTranscriptionEvents.Transcription,
this._onTranscription.bind(this, cs, ep, channel)); this._onTranscription.bind(this, cs, ep, channel));
this.addCustomEventListener(ep, AzureTranscriptionEvents.NoSpeechDetected, this.addCustomEventListener(ep, AzureTranscriptionEvents.NoSpeechDetected,
this._onNoAudio.bind(this, cs, ep, channel)); this._onNoAudio.bind(this, cs, ep, channel));
break; break;
case 'nuance': case 'nuance':
this.bugname = `${this.bugname_prefix}nuance_transcribe`; bugname = `${this.bugname_prefix}nuance_transcribe_${channel}`;
this.addCustomEventListener(ep, NuanceTranscriptionEvents.Transcription, this.addCustomEventListener(ep, NuanceTranscriptionEvents.Transcription,
this._onTranscription.bind(this, cs, ep, channel)); this._onTranscription.bind(this, cs, ep, channel));
break; break;
case 'deepgram': case 'deepgram':
this.bugname = `${this.bugname_prefix}deepgram_transcribe`; bugname = `${this.bugname_prefix}deepgram_transcribe_${channel}`;
this.addCustomEventListener(ep, DeepgramTranscriptionEvents.Transcription, this.addCustomEventListener(ep, DeepgramTranscriptionEvents.Transcription,
this._onTranscription.bind(this, cs, ep, channel)); this._onTranscription.bind(this, cs, ep, channel));
this.addCustomEventListener(ep, DeepgramTranscriptionEvents.Connect, this.addCustomEventListener(ep, DeepgramTranscriptionEvents.Connect,
@@ -186,12 +187,12 @@ class TaskTranscribe extends SttTask {
break; break;
case 'soniox': case 'soniox':
this.bugname = `${this.bugname_prefix}soniox_transcribe`; bugname = `${this.bugname_prefix}soniox_transcribe_${channel}`;
this.addCustomEventListener(ep, SonioxTranscriptionEvents.Transcription, this.addCustomEventListener(ep, SonioxTranscriptionEvents.Transcription,
this._onTranscription.bind(this, cs, ep, channel)); this._onTranscription.bind(this, cs, ep, channel));
break; break;
case 'cobalt': case 'cobalt':
this.bugname = `${this.bugname_prefix}cobalt_transcribe`; bugname = `${this.bugname_prefix}cobalt_transcribe_${channel}`;
this.addCustomEventListener(ep, CobaltTranscriptionEvents.Transcription, this.addCustomEventListener(ep, CobaltTranscriptionEvents.Transcription,
this._onTranscription.bind(this, cs, ep, channel)); this._onTranscription.bind(this, cs, ep, channel));
@@ -221,7 +222,7 @@ class TaskTranscribe extends SttTask {
break; break;
case 'ibm': case 'ibm':
this.bugname = `${this.bugname_prefix}ibm_transcribe`; bugname = `${this.bugname_prefix}ibm_transcribe_${channel}`;
this.addCustomEventListener(ep, IbmTranscriptionEvents.Transcription, this.addCustomEventListener(ep, IbmTranscriptionEvents.Transcription,
this._onTranscription.bind(this, cs, ep, channel)); this._onTranscription.bind(this, cs, ep, channel));
this.addCustomEventListener(ep, IbmTranscriptionEvents.Connect, this.addCustomEventListener(ep, IbmTranscriptionEvents.Connect,
@@ -231,13 +232,13 @@ class TaskTranscribe extends SttTask {
break; break;
case 'nvidia': case 'nvidia':
this.bugname = `${this.bugname_prefix}nvidia_transcribe`; bugname = `${this.bugname_prefix}nvidia_transcribe_${channel}`;
this.addCustomEventListener(ep, NvidiaTranscriptionEvents.Transcription, this.addCustomEventListener(ep, NvidiaTranscriptionEvents.Transcription,
this._onTranscription.bind(this, cs, ep, channel)); this._onTranscription.bind(this, cs, ep, channel));
break; break;
case 'assemblyai': case 'assemblyai':
this.bugname = `${this.bugname_prefix}assemblyai_transcribe`; bugname = `${this.bugname_prefix}assemblyai_transcribe_${channel}`;
this.addCustomEventListener(ep, AssemblyAiTranscriptionEvents.Transcription, this.addCustomEventListener(ep, AssemblyAiTranscriptionEvents.Transcription,
this._onTranscription.bind(this, cs, ep, channel)); this._onTranscription.bind(this, cs, ep, channel));
this.addCustomEventListener(ep, this.addCustomEventListener(ep,
@@ -249,7 +250,7 @@ class TaskTranscribe extends SttTask {
default: default:
if (this.vendor.startsWith('custom:')) { if (this.vendor.startsWith('custom:')) {
this.bugname = `${this.bugname_prefix}${this.vendor}_transcribe`; bugname = `${this.bugname_prefix}${this.vendor}_transcribe_${channel}`;
this.addCustomEventListener(ep, JambonzTranscriptionEvents.Transcription, this.addCustomEventListener(ep, JambonzTranscriptionEvents.Transcription,
this._onTranscription.bind(this, cs, ep, channel)); this._onTranscription.bind(this, cs, ep, channel));
this.addCustomEventListener(ep, JambonzTranscriptionEvents.Connect, this._onVendorConnect.bind(this, cs, ep)); this.addCustomEventListener(ep, JambonzTranscriptionEvents.Connect, this._onVendorConnect.bind(this, cs, ep));
@@ -263,7 +264,8 @@ class TaskTranscribe extends SttTask {
throw new Error(`Invalid vendor ${this.vendor}`); throw new Error(`Invalid vendor ${this.vendor}`);
} }
} }
// save dedicated bugname for each endpoint
ep.transcribe_bugname = bugname;
/* common handler for all stt engine errors */ /* common handler for all stt engine errors */
this.addCustomEventListener(ep, JambonzTranscriptionEvents.Error, this._onJambonzError.bind(this, cs, ep)); this.addCustomEventListener(ep, JambonzTranscriptionEvents.Error, this._onJambonzError.bind(this, cs, ep));
await ep.set(opts) await ep.set(opts)
@@ -281,13 +283,13 @@ class TaskTranscribe extends SttTask {
async _transcribe(ep) { async _transcribe(ep) {
this.logger.debug( this.logger.debug(
`TaskTranscribe:_transcribe - starting transcription vendor ${this.vendor} bugname ${this.bugname}`); `TaskTranscribe:_transcribe - starting transcription vendor ${this.vendor} bugname ${ep.transcribe_bugname}`);
await ep.startTranscription({ await ep.startTranscription({
vendor: this.vendor, vendor: this.vendor,
interim: this.interim ? true : false, interim: this.interim ? true : false,
locale: this.language, locale: this.language,
channels: /*this.separateRecognitionPerChannel ? 2 : */ 1, channels: /*this.separateRecognitionPerChannel ? 2 : */ 1,
bugname: this.bugname, bugname: ep.transcribe_bugname,
hostport: this.hostport hostport: this.hostport
}); });
} }
@@ -295,7 +297,7 @@ class TaskTranscribe extends SttTask {
async _onTranscription(cs, ep, channel, evt, fsEvent) { async _onTranscription(cs, ep, channel, evt, fsEvent) {
// make sure this is not a transcript from answering machine detection // make sure this is not a transcript from answering machine detection
const bugname = fsEvent.getHeader('media-bugname'); const bugname = fsEvent.getHeader('media-bugname');
if (bugname && this.bugname !== bugname) return; if (bugname && ep.transcribe_bugname !== bugname) return;
if (this.vendor === 'ibm' && evt?.state === 'listening') return; if (this.vendor === 'ibm' && evt?.state === 'listening') return;
@@ -443,7 +445,7 @@ class TaskTranscribe extends SttTask {
if (this.isHandledByPrimaryProvider && this.fallbackVendor) { if (this.isHandledByPrimaryProvider && this.fallbackVendor) {
_ep.stopTranscription({ _ep.stopTranscription({
vendor: this.vendor, vendor: this.vendor,
bugname: this.bugname bugname: _ep.transcribe_bugname
}) })
.catch((err) => this.logger.error({err}, `Error stopping transcription for primary vendor ${this.vendor}`)); .catch((err) => this.logger.error({err}, `Error stopping transcription for primary vendor ${this.vendor}`));
const {updateSpeechCredentialLastUsed} = require('../utils/db-utils')(this.logger, cs.srf); const {updateSpeechCredentialLastUsed} = require('../utils/db-utils')(this.logger, cs.srf);

View File

@@ -14,7 +14,6 @@ const {
HTTP_PROXY_PORT, HTTP_PROXY_PORT,
HTTP_PROXY_PROTOCOL, HTTP_PROXY_PROTOCOL,
NODE_ENV, NODE_ENV,
HTTP_USER_AGENT_HEADER,
} = require('../config'); } = require('../config');
const toBase64 = (str) => Buffer.from(str || '', 'utf8').toString('base64'); const toBase64 = (str) => Buffer.from(str || '', 'utf8').toString('base64');
@@ -117,10 +116,6 @@ class HttpRequestor extends BaseRequestor {
const url = hook.url || hook; const url = hook.url || hook;
const method = hook.method || 'POST'; const method = hook.method || 'POST';
let buf = ''; let buf = '';
httpHeaders = {
...httpHeaders,
...(HTTP_USER_AGENT_HEADER && {'user-agent' : HTTP_USER_AGENT_HEADER})
};
assert.ok(url, 'HttpRequestor:request url was not provided'); assert.ok(url, 'HttpRequestor:request url was not provided');
assert.ok, (['GET', 'POST'].includes(method), `HttpRequestor:request method must be 'GET' or 'POST' not ${method}`); assert.ok, (['GET', 'POST'].includes(method), `HttpRequestor:request method must be 'GET' or 'POST' not ${method}`);

View File

@@ -9,8 +9,7 @@ const {
JAMBONES_WS_PING_INTERVAL_MS, JAMBONES_WS_PING_INTERVAL_MS,
MAX_RECONNECTS, MAX_RECONNECTS,
JAMBONES_WS_HANDSHAKE_TIMEOUT_MS, JAMBONES_WS_HANDSHAKE_TIMEOUT_MS,
JAMBONES_WS_MAX_PAYLOAD, JAMBONES_WS_MAX_PAYLOAD
HTTP_USER_AGENT_HEADER
} = require('../config'); } = require('../config');
class WsRequestor extends BaseRequestor { class WsRequestor extends BaseRequestor {
@@ -229,9 +228,6 @@ class WsRequestor extends BaseRequestor {
maxRedirects: 2, maxRedirects: 2,
handshakeTimeout, handshakeTimeout,
maxPayload: JAMBONES_WS_MAX_PAYLOAD ? parseInt(JAMBONES_WS_MAX_PAYLOAD) : 24 * 1024, maxPayload: JAMBONES_WS_MAX_PAYLOAD ? parseInt(JAMBONES_WS_MAX_PAYLOAD) : 24 * 1024,
headers: {
...(HTTP_USER_AGENT_HEADER && {'user-agent' : HTTP_USER_AGENT_HEADER})
}
}; };
if (this.username && this.password) opts = {...opts, auth: `${this.username}:${this.password}`}; if (this.username && this.password) opts = {...opts, auth: `${this.username}:${this.password}`};

12
package-lock.json generated
View File

@@ -7530,9 +7530,9 @@
"dev": true "dev": true
}, },
"node_modules/follow-redirects": { "node_modules/follow-redirects": {
"version": "1.15.4", "version": "1.15.2",
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.4.tgz", "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.2.tgz",
"integrity": "sha512-Cr4D/5wlrb0z9dgERpUL3LrmPKVDsETIJhaCMeDfuFYcqa5bldGV6wBsAN6X/vxlXQtFBMrXdXxdL8CbDTGniw==", "integrity": "sha512-VQLG33o04KaQ8uYi2tVNbdrWp1QWxNNea+nmIB4EVM28v0hmP17z7aG1+wAkNzVq4KeXTq3221ye5qTJP91JwA==",
"funding": [ "funding": [
{ {
"type": "individual", "type": "individual",
@@ -18056,9 +18056,9 @@
"dev": true "dev": true
}, },
"follow-redirects": { "follow-redirects": {
"version": "1.15.4", "version": "1.15.2",
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.4.tgz", "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.2.tgz",
"integrity": "sha512-Cr4D/5wlrb0z9dgERpUL3LrmPKVDsETIJhaCMeDfuFYcqa5bldGV6wBsAN6X/vxlXQtFBMrXdXxdL8CbDTGniw==" "integrity": "sha512-VQLG33o04KaQ8uYi2tVNbdrWp1QWxNNea+nmIB4EVM28v0hmP17z7aG1+wAkNzVq4KeXTq3221ye5qTJP91JwA=="
}, },
"for-each": { "for-each": {
"version": "0.3.3", "version": "0.3.3",

View File

@@ -99,8 +99,6 @@ test('test create-call call-hook basic authentication', async(t) => {
let obj = await getJSON(`http:127.0.0.1:3100/lastRequest/${from}`) let obj = await getJSON(`http:127.0.0.1:3100/lastRequest/${from}`)
t.ok(obj.headers.Authorization = 'Basic dXNlcm5hbWU6cGFzc3dvcmQ=', t.ok(obj.headers.Authorization = 'Basic dXNlcm5hbWU6cGFzc3dvcmQ=',
'create-call: call-hook contains basic authentication header'); 'create-call: call-hook contains basic authentication header');
t.ok(obj.headers['user-agent'] = 'jambonz',
'create-call: call-hook contains user-agent header');
disconnect(); disconnect();
} catch (err) { } catch (err) {
console.log(`error received: ${err}`); console.log(`error received: ${err}`);