add support for queueing commands sent over ws

This commit is contained in:
Dave Horton
2022-02-24 09:49:49 -05:00
parent 27293288d7
commit 12f0e9348e
2 changed files with 16 additions and 9 deletions

View File

@@ -619,15 +619,22 @@ class CallSession extends Emitter {
this.taskIdx = 0; this.taskIdx = 0;
} }
_onCommand({msgid, command, call_sid, data}) { _onCommand({msgid, command, queueCommand, data}) {
this.logger.info({msgid, command, call_sid, data}, 'CallSession:_onCommand - received command'); this.logger.info({msgid, command, data}, 'CallSession:_onCommand - received command');
switch (command) { switch (command) {
case 'redirect': case 'redirect':
if (Array.isArray(data)) { if (Array.isArray(data)) {
const t = normalizeJambones(this.logger, data).map((tdata) => makeTask(this.logger, tdata)); const t = normalizeJambones(this.logger, data).map((tdata) => makeTask(this.logger, tdata));
if (!queueCommand) {
this.logger.info({tasks: listTaskNames(t)}, 'CallSession:_onCommand new task list'); this.logger.info({tasks: listTaskNames(t)}, 'CallSession:_onCommand new task list');
this.replaceApplication(t); 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); else this._lccCallHook(data);
break; break;

View File

@@ -204,7 +204,7 @@ class WsRequestor extends BaseRequestor {
/* messages must be JSON format */ /* messages must be JSON format */
try { 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'); assert.ok(type, 'type property not supplied');
switch (type) { switch (type) {
@@ -216,7 +216,7 @@ class WsRequestor extends BaseRequestor {
case 'command': case 'command':
assert.ok(command, 'command property not supplied'); assert.ok(command, 'command property not supplied');
assert.ok(data, 'data property not supplied'); assert.ok(data, 'data property not supplied');
this._recvCommand(msgid, command, data); this._recvCommand(msgid, command, queueCommand, data);
break; break;
default: default:
@@ -239,10 +239,10 @@ class WsRequestor extends BaseRequestor {
success && success(data); success && success(data);
} }
_recvCommand(msgid, command, data) { _recvCommand(msgid, command, queueCommand, data) {
// TODO: validate command // TODO: validate command
this.logger.info({msgid, command, data}, 'received command'); this.logger.info({msgid, command, queueCommand, data}, 'received command');
this.emit('command', {msgid, command, data}); this.emit('command', {msgid, command, queueCommand, data});
} }
} }