mirror of
https://github.com/jambonz/jambonz-feature-server.git
synced 2025-12-20 16:50:39 +00:00
add pause command
This commit is contained in:
@@ -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
26
lib/tasks/pause.js
Normal 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;
|
||||||
@@ -108,6 +108,14 @@
|
|||||||
"url"
|
"url"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
"pause": {
|
||||||
|
"properties": {
|
||||||
|
"length": "number"
|
||||||
|
},
|
||||||
|
"required": [
|
||||||
|
"length"
|
||||||
|
]
|
||||||
|
},
|
||||||
"redirect": {
|
"redirect": {
|
||||||
"properties": {
|
"properties": {
|
||||||
"action": "string",
|
"action": "string",
|
||||||
|
|||||||
@@ -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",
|
||||||
|
|||||||
5
test/data/good/pause.json
Normal file
5
test/data/good/pause.json
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"pause": {
|
||||||
|
"length": 3
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user