mirror of
https://github.com/jambonz/jambonz-feature-server.git
synced 2025-12-20 08:40:38 +00:00
initial checkin
This commit is contained in:
22
lib/tasks/make_task.js
Normal file
22
lib/tasks/make_task.js
Normal file
@@ -0,0 +1,22 @@
|
||||
const Task = require('./task');
|
||||
const TaskSipDecline = require('./sip_decline');
|
||||
const TaskDial = require('./dial');
|
||||
const errBadInstruction = new Error('invalid instruction payload');
|
||||
|
||||
function makeTask(logger, opts) {
|
||||
if (typeof opts !== 'object' || Array.isArray(opts)) throw errBadInstruction;
|
||||
const keys = Object.keys(opts);
|
||||
if (keys.length !== 1) throw errBadInstruction;
|
||||
const name = keys[0];
|
||||
const data = opts[name];
|
||||
Task.validate(name, data);
|
||||
switch (name) {
|
||||
case TaskSipDecline.name: return new TaskSipDecline(logger, data);
|
||||
case TaskDial.name: return new TaskDial(logger, data);
|
||||
}
|
||||
|
||||
// should never reach
|
||||
throw new Error(`invalid task ${name} (please update specs.json and make_task.js)`);
|
||||
}
|
||||
|
||||
module.exports = makeTask;
|
||||
Reference in New Issue
Block a user