From e4d13ea2a83dbfdbf7939be556196343af335bdb Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Tue, 12 Mar 2013 09:23:55 -0400 Subject: trigger rails on presence changes --- misc/freeswitch/scripts/event/presence_update.lua | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) (limited to 'misc/freeswitch/scripts/event') diff --git a/misc/freeswitch/scripts/event/presence_update.lua b/misc/freeswitch/scripts/event/presence_update.lua index 4d0cb94..7e9ea77 100644 --- a/misc/freeswitch/scripts/event/presence_update.lua +++ b/misc/freeswitch/scripts/event/presence_update.lua @@ -196,8 +196,8 @@ function PresenceUpdate.sip_account(self, inbound, account, domain, status, uuid self.account_record[account] = { id = sip_account.id, class = sip_account.class, phone_numbers = phone_numbers, created_at = os.time() } end - require 'dialplan.presence' - local result = dialplan.presence.Presence:new{ + require 'dialplan.presence'; + dialplan.presence.Presence:new{ log = self.log, database = self.database, inbound = inbound, @@ -205,12 +205,14 @@ function PresenceUpdate.sip_account(self, inbound, account, domain, status, uuid accounts = self.account_record[account].phone_numbers, uuid = uuid }:set(status_map[status] or 'terminated', caller_id); + + self:trigger_rails(self.account_record[account], status_map[status] or 'terminated', uuid); end function PresenceUpdate.conference(self, inbound, account, domain, status, uuid) - require 'dialplan.presence' - local result = dialplan.presence.Presence:new{ + require 'dialplan.presence'; + dialplan.presence.Presence:new{ log = self.log, database = self.database, inbound = inbound, @@ -219,3 +221,13 @@ function PresenceUpdate.conference(self, inbound, account, domain, status, uuid) uuid = uuid }:set(status or 'terminated'); end + + +function PresenceUpdate.trigger_rails(self, account, status, uuid) + if account.class == 'sipaccount' then + local command = 'http_request.lua ' .. uuid .. ' http://127.0.0.1/trigger/sip_account_update/' .. tostring(account.id .. '?status=' .. tostring(status)); + + require 'common.fapi' + common.fapi.FApi:new():execute('luarun', command); + end +end -- cgit v1.2.3