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

View File

@@ -30,6 +30,9 @@ function makeTask(logger, obj) {
case TaskName.Play: case TaskName.Play:
const TaskPlay = require('./play'); const TaskPlay = require('./play');
return new TaskPlay(logger, data); return new TaskPlay(logger, data);
case TaskName.Pause:
const TaskPause = require('./pause');
return new TaskPause(logger, data);
case TaskName.Gather: case TaskName.Gather:
const TaskGather = require('./gather'); const TaskGather = require('./gather');
return new TaskGather(logger, data); return new TaskGather(logger, data);

26
lib/tasks/pause.js Normal file
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;

View File

@@ -108,6 +108,14 @@
"url" "url"
] ]
}, },
"pause": {
"properties": {
"length": "number"
},
"required": [
"length"
]
},
"redirect": { "redirect": {
"properties": { "properties": {
"action": "string", "action": "string",

View File

@@ -4,6 +4,7 @@
"Gather": "gather", "Gather": "gather",
"Hangup": "hangup", "Hangup": "hangup",
"Listen": "listen", "Listen": "listen",
"Pause": "pause",
"Play": "play", "Play": "play",
"Redirect": "redirect", "Redirect": "redirect",
"RestDial": "rest:dial", "RestDial": "rest:dial",

View File

@@ -0,0 +1,5 @@
{
"pause": {
"length": 3
}
}

View File

@@ -36,6 +36,9 @@ test('app payload parsing tests', (t) => {
task = makeTask(logger, require('./data/good/dial-listen')); task = makeTask(logger, require('./data/good/dial-listen'));
t.ok(task.name === 'dial', 'parsed dial w/ 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 alt = require('./data/good/alternate-syntax');
const normalize = require('../lib/utils/normalize-jamones'); const normalize = require('../lib/utils/normalize-jamones');
normalize(logger, alt).forEach((t) => { normalize(logger, alt).forEach((t) => {