summaryrefslogtreecommitdiff
path: root/misc/freeswitch
diff options
context:
space:
mode:
authorspag <spag@golwen.net>2013-02-07 15:11:53 +0100
committerspag <spag@golwen.net>2013-02-07 15:11:53 +0100
commitfa243f49c53d05c8b5510cd6ba062517cbc952cf (patch)
tree4951a7a64b46f7b9018bca8e66253d64af2836ec /misc/freeswitch
parent55e89ec3146e9a910b8001fd586fd46103709f68 (diff)
dtmf handling class added
Diffstat (limited to 'misc/freeswitch')
-rw-r--r--misc/freeswitch/scripts/dialplan/dtmf.lua69
1 files changed, 69 insertions, 0 deletions
diff --git a/misc/freeswitch/scripts/dialplan/dtmf.lua b/misc/freeswitch/scripts/dialplan/dtmf.lua
new file mode 100644
index 0000000..0094d05
--- /dev/null
+++ b/misc/freeswitch/scripts/dialplan/dtmf.lua
@@ -0,0 +1,69 @@
+-- Gemeinschaft 5 module: dtmf class
+-- (c) AMOOMA GmbH 2013
+--
+
+module(...,package.seeall)
+
+Dtmf = {}
+
+-- create dtmf object
+function Dtmf.new(self, arg)
+ arg = arg or {}
+ object = arg.object or {}
+ setmetatable(object, self);
+ self.__index = self;
+ self.class = 'Dtmf';
+ self.log = arg.log;
+ self.bleg = arg.bleg
+ self.digit_timeout = arg.digit_timeout or 5;
+ self.router = arg.router;
+
+ return object;
+end
+
+
+function Dtmf.detect(self, caller, sequence, digit, duration, calee)
+ local timestamp = os.time();
+ if timestamp - sequence.updated > self.digit_timeout then
+ sequence.digits = digit;
+ else
+ sequence.digits = sequence.digits .. digit;
+ end
+
+ caller.dtmf_digits = sequence.digits;
+
+ if calee then
+ self.log:info('DTMF_RECEIVER callee - digit: [', digit, '][', duration, '], sequence: ', sequence.digits);
+ else
+ self.log:info('DTMF_RECEIVER caller - digit: [', digit, '][', duration, '], sequence: ', sequence.digits);
+ end
+
+ local route = self.router:route_run('dtmf', true);
+ sequence.updated = timestamp;
+
+ if not route then
+ return;
+ end
+
+ if route.type == 'dialplanfunction' or route.type == 'phonenumber' or route.type == 'unknown' then
+ self:transfer(caller, route.destination_number, calee)
+ else
+ self.log:notice('DTMF_RECEIVER - unhandled destination: ', route.type, '=', route.id);
+ end
+end
+
+
+function Dtmf.transfer(self, caller, destination, calee)
+ require 'common.fapi'
+ local fapi = common.fapi.FApi:new{ log = log };
+ local callee_uuid = caller:to_s('bridge_to');
+
+ self.log:notice('DTMF_RECEIVER_TRANSFER - destination: ', destination, ', uuid: ', caller.uuid, ', callee_uuid: ', callee_uuid, ', callee_initiated: ', calee);
+ if calee then
+ caller:execute('transfer', destination);
+ fapi:execute('uuid_kill', callee_uuid);
+ else
+ fapi:execute('uuid_transfer', callee_uuid .. ' ' .. destination);
+ caller.session:hangup();
+ end
+end