From 12f0e9348ed7ed072c6560566a4a504347d1caef Mon Sep 17 00:00:00 2001 From: Dave Horton Date: Thu, 24 Feb 2022 09:49:49 -0500 Subject: [PATCH] add support for queueing commands sent over ws --- lib/session/call-session.js | 15 +++++++++++---- lib/utils/ws-requestor.js | 10 +++++----- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/lib/session/call-session.js b/lib/session/call-session.js index 4bcf7e0a..c62d32cb 100644 --- a/lib/session/call-session.js +++ b/lib/session/call-session.js @@ -619,14 +619,21 @@ class CallSession extends Emitter { this.taskIdx = 0; } - _onCommand({msgid, command, call_sid, data}) { - this.logger.info({msgid, command, call_sid, data}, 'CallSession:_onCommand - received command'); + _onCommand({msgid, command, queueCommand, data}) { + this.logger.info({msgid, command, data}, 'CallSession:_onCommand - received command'); switch (command) { case 'redirect': if (Array.isArray(data)) { const t = normalizeJambones(this.logger, data).map((tdata) => makeTask(this.logger, tdata)); - this.logger.info({tasks: listTaskNames(t)}, 'CallSession:_onCommand new task list'); - this.replaceApplication(t); + if (!queueCommand) { + this.logger.info({tasks: listTaskNames(t)}, 'CallSession:_onCommand new task list'); + this.replaceApplication(t); + } + else { + this.logger.info({t, tasks: this.tasks}, 'CallSession:_onCommand - about to queue tasks'); + this.tasks.push(...t); + this.logger.debug({tasks: this.tasks}, 'CallSession:_onCommand - tasks have been queued'); + } } else this._lccCallHook(data); break; diff --git a/lib/utils/ws-requestor.js b/lib/utils/ws-requestor.js index f1af61dd..297b069a 100644 --- a/lib/utils/ws-requestor.js +++ b/lib/utils/ws-requestor.js @@ -204,7 +204,7 @@ class WsRequestor extends BaseRequestor { /* messages must be JSON format */ try { - const {type, msgid, command, data} = JSON.parse(content); + const {type, msgid, command, queueCommand = false, data} = JSON.parse(content); assert.ok(type, 'type property not supplied'); switch (type) { @@ -216,7 +216,7 @@ class WsRequestor extends BaseRequestor { case 'command': assert.ok(command, 'command property not supplied'); assert.ok(data, 'data property not supplied'); - this._recvCommand(msgid, command, data); + this._recvCommand(msgid, command, queueCommand, data); break; default: @@ -239,10 +239,10 @@ class WsRequestor extends BaseRequestor { success && success(data); } - _recvCommand(msgid, command, data) { + _recvCommand(msgid, command, queueCommand, data) { // TODO: validate command - this.logger.info({msgid, command, data}, 'received command'); - this.emit('command', {msgid, command, data}); + this.logger.info({msgid, command, queueCommand, data}, 'received command'); + this.emit('command', {msgid, command, queueCommand, data}); } }