From fa243f49c53d05c8b5510cd6ba062517cbc952cf Mon Sep 17 00:00:00 2001 From: spag Date: Thu, 7 Feb 2013 15:11:53 +0100 Subject: dtmf handling class added --- misc/freeswitch/scripts/dialplan/dtmf.lua | 69 +++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 misc/freeswitch/scripts/dialplan/dtmf.lua (limited to 'misc/freeswitch/scripts/dialplan/dtmf.lua') 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 -- cgit v1.2.3 From 5aefe7bb21d7b18f5653db439c61f7540e04e4e5 Mon Sep 17 00:00:00 2001 From: spag Date: Thu, 7 Feb 2013 23:57:45 +0100 Subject: log level --- misc/freeswitch/scripts/dialplan/dtmf.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'misc/freeswitch/scripts/dialplan/dtmf.lua') diff --git a/misc/freeswitch/scripts/dialplan/dtmf.lua b/misc/freeswitch/scripts/dialplan/dtmf.lua index 0094d05..4dbd35f 100644 --- a/misc/freeswitch/scripts/dialplan/dtmf.lua +++ b/misc/freeswitch/scripts/dialplan/dtmf.lua @@ -33,9 +33,9 @@ function Dtmf.detect(self, caller, sequence, digit, duration, calee) caller.dtmf_digits = sequence.digits; if calee then - self.log:info('DTMF_RECEIVER callee - digit: [', digit, '][', duration, '], sequence: ', sequence.digits); + self.log:debug('DTMF_RECEIVER callee - digit: [', digit, '][', duration, '], sequence: ', sequence.digits); else - self.log:info('DTMF_RECEIVER caller - digit: [', digit, '][', duration, '], sequence: ', sequence.digits); + self.log:debug('DTMF_RECEIVER caller - digit: [', digit, '][', duration, '], sequence: ', sequence.digits); end local route = self.router:route_run('dtmf', true); -- cgit v1.2.3