add pause command

This commit is contained in:
Dave Horton
2020-02-03 20:51:50 -05:00
parent 348a820044
commit 2811e35c6b
6 changed files with 46 additions and 0 deletions
+3
View File
@@ -30,6 +30,9 @@ function makeTask(logger, obj) {
case TaskName.Play:
const TaskPlay = require('./play');
return new TaskPlay(logger, data);
case TaskName.Pause:
const TaskPause = require('./pause');
return new TaskPause(logger, data);
case TaskName.Gather:
const TaskGather = require('./gather');
return new TaskGather(logger, data);
+26
View File
@@ -0,0 +1,26 @@
const Task = require('./task');
const {TaskName} = require('../utils/constants');
class TaskPause extends Task {
constructor(logger, opts, parentTask) {
super(logger, opts);
this.length = this.data.length;
}
get name() { return TaskName.Pause; }
async exec(cs, ep) {
super.exec(cs);
this.timer = setTimeout(this.notifyTaskDone.bind(this), this.length * 1000);
await this.awaitTaskDone();
}
async kill() {
super.kill();
clearTimeout(this.timer);
this.notifyTaskDone();
}
}
module.exports = TaskPause;
+8
View File
@@ -108,6 +108,14 @@
"url"
]
},
"pause": {
"properties": {
"length": "number"
},
"required": [
"length"
]
},
"redirect": {
"properties": {
"action": "string",
+1
View File
@@ -4,6 +4,7 @@
"Gather": "gather",
"Hangup": "hangup",
"Listen": "listen",
"Pause": "pause",
"Play": "play",
"Redirect": "redirect",
"RestDial": "rest:dial",
+5
View File
@@ -0,0 +1,5 @@
{
"pause": {
"length": 3
}
}
+3
View File
@@ -36,6 +36,9 @@ test('app payload parsing tests', (t) => {
task = makeTask(logger, require('./data/good/dial-listen'));
t.ok(task.name === 'dial', 'parsed dial w/ listen');
task = makeTask(logger, require('./data/good/pause'));
t.ok(task.name === 'pause', 'parsed pause');
const alt = require('./data/good/alternate-syntax');
const normalize = require('../lib/utils/normalize-jamones');
normalize(logger, alt).forEach((t) => {