From b5df8e80d5b10ae7a71e9945ab9246141c7339af Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Tue, 4 Jun 2013 11:21:40 +0200 Subject: pager class added --- misc/freeswitch/scripts/common/pager.lua | 71 ++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 misc/freeswitch/scripts/common/pager.lua (limited to 'misc/freeswitch/scripts/common/pager.lua') diff --git a/misc/freeswitch/scripts/common/pager.lua b/misc/freeswitch/scripts/common/pager.lua new file mode 100644 index 0000000..2f60d14 --- /dev/null +++ b/misc/freeswitch/scripts/common/pager.lua @@ -0,0 +1,71 @@ +-- Gemeinschaft 5 module: pager class +-- (c) AMOOMA GmbH 2013 +-- + +module(...,package.seeall) + +Pager = {} + +function Pager.new(self, arg) + arg = arg or {} + pager = arg.pager or {} + setmetatable(pager, self); + self.__index = self; + self.class = 'pager'; + self.log = arg.log; + self.database = arg.database; + self.caller = arg.caller; + + return pager; +end + + +function Pager.find_by_id(self, id) + local sql_query = 'SELECT * FROM `pager_groups` WHERE `id`= '.. tonumber(id) .. ' LIMIT 1'; + local pager = nil; + + self.database:query(sql_query, function(entry) + pager = Pager:new(self); + pager.record = entry; + pager.id = tonumber(entry.id); + pager.uuid = entry.uuid; + pager.identifier = 'pager' .. entry.id; + end) + + return pager; +end + + +function Pager.enter(self, originator) + local flags = 'mute'; + if originator then + flags = 'moderator'; + end + + self:callback(); + + local result = self.caller:execute('conference', self.identifier .. "@profile_" .. self.identifier .. "++flags{" .. flags .. "}"); + + self:callback(); +end + + +function Pager.callback(self) + local destination = { + pager_group_id = self.id, + state = 'terminated', + } + + if self.caller.account and self.caller.account.class:lower() == 'sipaccount' then + destination.sip_account_id = self.caller.account.id; + end + + if self.caller and self.caller:ready() then + destination.state = 'active'; + end + + local command = 'http_request.lua ' .. self.caller.uuid .. ' ' .. common.array.expand_variables(self.record.callback_url, destination, self.caller); + + require 'common.fapi'; + return common.fapi.FApi:new():execute('luarun', command); +end -- cgit v1.2.3 From eda886ce7ca310beb844d3e56fd1cc7179ae9d9a Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Tue, 4 Jun 2013 11:31:01 +0200 Subject: set moderator flag --- misc/freeswitch/scripts/common/pager.lua | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'misc/freeswitch/scripts/common/pager.lua') diff --git a/misc/freeswitch/scripts/common/pager.lua b/misc/freeswitch/scripts/common/pager.lua index 2f60d14..bf19ba6 100644 --- a/misc/freeswitch/scripts/common/pager.lua +++ b/misc/freeswitch/scripts/common/pager.lua @@ -36,9 +36,14 @@ function Pager.find_by_id(self, id) end -function Pager.enter(self, originator) +function Pager.enter(self) local flags = 'mute'; - if originator then + + if not self.caller.account or self.caller.account.class ~= 'sipaccount' then + return false; + end + + if tonumber(self.record.sip_account_id) == tonumber(self.caller.account.id) then flags = 'moderator'; end @@ -56,7 +61,7 @@ function Pager.callback(self) state = 'terminated', } - if self.caller.account and self.caller.account.class:lower() == 'sipaccount' then + if self.caller.account and self.caller.account.class == 'sipaccount' then destination.sip_account_id = self.caller.account.id; end -- cgit v1.2.3 From 63f253ee3786fdf2970a64b2bbfea5c2ee89b09f Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Tue, 4 Jun 2013 13:08:58 +0200 Subject: hangup added --- misc/freeswitch/scripts/common/pager.lua | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'misc/freeswitch/scripts/common/pager.lua') diff --git a/misc/freeswitch/scripts/common/pager.lua b/misc/freeswitch/scripts/common/pager.lua index bf19ba6..6896e4c 100644 --- a/misc/freeswitch/scripts/common/pager.lua +++ b/misc/freeswitch/scripts/common/pager.lua @@ -50,7 +50,7 @@ function Pager.enter(self) self:callback(); local result = self.caller:execute('conference', self.identifier .. "@profile_" .. self.identifier .. "++flags{" .. flags .. "}"); - + self.caller:hangup('NORMAL_CLEARING'); self:callback(); end @@ -70,7 +70,6 @@ function Pager.callback(self) end local command = 'http_request.lua ' .. self.caller.uuid .. ' ' .. common.array.expand_variables(self.record.callback_url, destination, self.caller); - require 'common.fapi'; return common.fapi.FApi:new():execute('luarun', command); end -- cgit v1.2.3 From b3a9f757bf86533c64f6ced8cae5901e2d1aec96 Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Fri, 7 Jun 2013 10:16:25 +0200 Subject: endconf flag added --- misc/freeswitch/scripts/common/pager.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'misc/freeswitch/scripts/common/pager.lua') diff --git a/misc/freeswitch/scripts/common/pager.lua b/misc/freeswitch/scripts/common/pager.lua index 6896e4c..d9440f4 100644 --- a/misc/freeswitch/scripts/common/pager.lua +++ b/misc/freeswitch/scripts/common/pager.lua @@ -44,7 +44,7 @@ function Pager.enter(self) end if tonumber(self.record.sip_account_id) == tonumber(self.caller.account.id) then - flags = 'moderator'; + flags = 'moderator|endconf'; end self:callback(); -- cgit v1.2.3