From 93c316dfa6e66e41c83dbfcb30d47b7ac2f505b2 Mon Sep 17 00:00:00 2001 From: Errol Samuels Date: Wed, 20 Aug 2014 21:24:05 +0000 Subject: [PATCH] Improved group intercept to work with load balanced FusionPBX servers. --- resources/install/scripts/intercept_group.lua | 27 ++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/resources/install/scripts/intercept_group.lua b/resources/install/scripts/intercept_group.lua index 199d165a3e..b282e69e35 100644 --- a/resources/install/scripts/intercept_group.lua +++ b/resources/install/scripts/intercept_group.lua @@ -16,7 +16,7 @@ -- -- The Initial Developer of the Original Code is -- Mark J Crane --- Copyright (C) 2010 - 2013 +-- Copyright (C) 2010 - 2014 -- the Initial Developer. All Rights Reserved. -- -- Contributor(s): @@ -54,6 +54,13 @@ sounds_dir = session:getVariable("sounds_dir"); context = session:getVariable("context"); caller_id_number = session:getVariable("caller_id_number"); + sofia_profile_name = session:getVariable("sofia_profile_name"); + + if (domain_count > 1) then + if (context == "public") then + context = domain_name; + end + end --set the sounds path for the language, dialect and voice default_language = session:getVariable("default_language"); @@ -156,7 +163,7 @@ assert(dbh:connected()); --check the database to get the uuid of a ringing call - sql = "SELECT call_uuid AS uuid FROM channels "; + sql = "SELECT call_uuid AS uuid, hostname, ip_addr FROM channels "; sql = sql .. "WHERE callstate = 'RINGING' "; sql = sql .. "AND ("; x = 0; @@ -181,12 +188,26 @@ -- freeswitch.consoleLog("NOTICE", "row "..key.." "..val.."\n"); --end uuid = row.uuid; + call_hostname = row.hostname; + ip_addr = row.ip_addr; end); end + hostname = freeswitch.getGlobalVariable("hostname"); + freeswitch.consoleLog("NOTICE", "Hostname:"..hostname.." Call Hostname:"..call_hostname.."\n"); + --intercept a call that is ringing if (uuid) then - session:execute("intercept", uuid); + if (hostname == call_hostname) then + session:execute("intercept", uuid); + else + session:execute("export", "sip_h_X-intercept_uuid="..uuid); + session:execute("export", "sip_h_X-domain_uuid="..domain_uuid); + session:execute("export", "sip_h_X-domain_name="..domain_name); + port = freeswitch.getGlobalVariable(sofia_profile_name.."_sip_port"); + session:execute("bridge", "sofia/"..sofia_profile_name.."/*8@"..call_hostname..":"..port); + freeswitch.consoleLog("NOTICE", "Send call to other host.... \n"); + end end --notes