Commit 9d48a279 authored by antirek's avatar antirek

add options

parent d859b7d1
......@@ -3,11 +3,12 @@ var AGIServer = require('./lib/index');
var handler = function (context) {
context.onEvent('variables')
.then(function (vars) {
return context.streamFile('beep');
return context.streamFile('beep');
})
.then(function (result) {
return context.end();
});
};
var agi = new AGIServer(handler);
agi.start(3000);
//ding.createServer(handler).listen(3000);
agi.start(3000);
\ No newline at end of file
......@@ -3,8 +3,9 @@ var EventEmitter = require('events').EventEmitter;
var state = require('./state');
var Q = require('q');
var Context = function (stream) {
var Context = function (stream, debug) {
EventEmitter.call(this);
this.debug = debug;
this.stream = new Readable();
this.stream.wrap(stream);
this.state = state.init;
......@@ -97,7 +98,10 @@ Context.prototype.end = function () {
Context.prototype.sendCommand = function (command) {
var defer = new Q.defer();
this.send(command + '\n', function (err, result){
if (this.debug) console.log('command', command);
var self = this;
this.send(command + '\n', function (err, result) {
if (self.debug) console.log('err:', err, 'result:', result);
if (err) {
defer.reject(err);
} else {
......
var Context = require('./context');
var agi = function (handler) {
var agi = function (handler, optionsIn) {
var server;
var options = optionsIn || {};
var settings = {
port: options.port || 3000,
debug: options.debug || false
};
var handle = function (stream) {
var context = new Context(stream);
var context = new Context(stream, settings.debug);
handler(context);
};
var start = function (port) {
var start = function (portIn) {
var port = portIn || settings.port;
return require('net').createServer(handle).listen(port);
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment