initial checkin

This commit is contained in:
Dave Horton
2020-01-07 10:34:03 -05:00
commit 523e2a308b
61 changed files with 7876 additions and 0 deletions

22
lib/tasks/make_task.js Normal file
View 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;