diff options
author | Stefan Wintermeyer <stefan.wintermeyer@amooma.de> | 2013-06-20 19:06:19 +0200 |
---|---|---|
committer | Stefan Wintermeyer <stefan.wintermeyer@amooma.de> | 2013-06-20 19:06:19 +0200 |
commit | eb0e1cc5c26275ff3e5c341404e8bc558f8312b8 (patch) | |
tree | 71f449ccd6f15422717de3ac24f87d5e888ddd79 /misc/freeswitch/scripts/common/pager.lua | |
parent | df6e17e48995f25e72509986f30700d778b179b6 (diff) | |
parent | 3b27a5d45b12f6bac65da2a8e17387bfda42a2f1 (diff) |
Merge branch 'develop'
Diffstat (limited to 'misc/freeswitch/scripts/common/pager.lua')
-rw-r--r-- | misc/freeswitch/scripts/common/pager.lua | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/misc/freeswitch/scripts/common/pager.lua b/misc/freeswitch/scripts/common/pager.lua new file mode 100644 index 0000000..d9440f4 --- /dev/null +++ b/misc/freeswitch/scripts/common/pager.lua @@ -0,0 +1,75 @@ +-- 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) + local flags = 'mute'; + + 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|endconf'; + end + + self:callback(); + + local result = self.caller:execute('conference', self.identifier .. "@profile_" .. self.identifier .. "++flags{" .. flags .. "}"); + self.caller:hangup('NORMAL_CLEARING'); + 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 == '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 |