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:
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
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"
]
},
"pause": {
"properties": {
"length": "number"
},
"required": [
"length"
]
},
"redirect": {
"properties": {
"action": "string",

View File

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