Improve conference_center.lua add better logging, caller announce, and wait for moderator.

This commit is contained in:
Mark Crane 2012-10-16 01:42:44 +00:00
parent 9e10564cd1
commit 84c1cc6a61
1 changed files with 309 additions and 229 deletions

View File

@ -47,40 +47,24 @@
--prepare the api object
api = freeswitch.API();
--define the trim function
function trim(s)
return s:gsub("^%s+", ""):gsub("%s+$", "")
end
--define the session hangup
function session_hangup_hook()
--get the uuid
--get the session variables
conference_session_detail_uuid = api:executeString("create_uuid");
conference_name = session:getVariable("conference_name");
--conference_name = session:getVariable("conference_name");
conference_session_uuid = session:getVariable("conference_uuid");
conference_recording = session:getVariable("conference_recording");
conference_moderator = session:getVariable("conference_moderator");
--start_epoch = session:getVariable("start_epoch");
end_epoch = os.time();
freeswitch.consoleLog("NOTICE", "Conference Center: \n");
freeswitch.consoleLog("NOTICE", "Conference Center: domain_uuid: " .. domain_uuid .. "\n");
--freeswitch.consoleLog("NOTICE", "Conference Center: domain_name: " .. domain_name .. "\n");
freeswitch.consoleLog("NOTICE", "Conference Center: meeting_uuid: " .. meeting_uuid .. "\n");
freeswitch.consoleLog("NOTICE", "Conference Center: conference_name: " .. conference_name .. "\n");
freeswitch.consoleLog("NOTICE", "Conference Center: conference_uuid: " .. conference_session_uuid .. "\n");
if (conference_recording) then
freeswitch.consoleLog("NOTICE", "Conference Center: conference_recording: " .. conference_recording .. "\n");
end
freeswitch.consoleLog("NOTICE", "Conference Center: username: " .. username .. "\n");
freeswitch.consoleLog("NOTICE", "Conference Center: caller_id_name: " .. caller_id_name .. "\n");
freeswitch.consoleLog("NOTICE", "Conference Center: caller_id_number: " .. caller_id_number .. "\n");
--freeswitch.consoleLog("NOTICE", "Conference Center: callee_id_name: " .. callee_id_name .. "\n");
--freeswitch.consoleLog("NOTICE", "Conference Center: callee_id_number: " .. callee_id_number .. "\n");
--freeswitch.consoleLog("NOTICE", "Conference Center: dialplan: " .. dialplan .. "\n");
freeswitch.consoleLog("NOTICE", "Conference Center: network_addr: " .. network_addr .. "\n");
freeswitch.consoleLog("NOTICE", "Conference Center: uuid: " .. uuid .. "\n");
--freeswitch.consoleLog("NOTICE", "Conference Center: context: " .. context .. "\n");
--freeswitch.consoleLog("NOTICE", "Conference Center: chan_name: " .. chan_name .. "\n");
freeswitch.consoleLog("NOTICE", "Conference Center: start_epoch: " .. start_epoch .. "\n");
freeswitch.consoleLog("NOTICE", "Conference Center: end_epoch: " .. end_epoch .. "\n");
--set the epoch
end_epoch = os.time();
--get the conference sessions
sql = [[SELECT count(*) as num_rows
@ -97,6 +81,7 @@
table.insert(sql, "conference_session_uuid, ");
table.insert(sql, "domain_uuid, ");
table.insert(sql, "meeting_uuid, ");
table.insert(sql, "profile, ");
if (conference_recording) then
table.insert(sql, "recording, ");
end
@ -111,6 +96,7 @@
table.insert(sql, "'".. conference_session_uuid .."', ");
table.insert(sql, "'".. domain_uuid .."', ");
table.insert(sql, "'".. meeting_uuid .."', ");
table.insert(sql, "'".. profile .."', ");
if (conference_recording) then
table.insert(sql, "'".. conference_recording .."', ");
end
@ -171,6 +157,7 @@ if (session:ready()) then
session:answer();
session:setHangupHook("session_hangup_hook");
sounds_dir = session:getVariable("sounds_dir");
hold_music = session:getVariable("hold_music");
domain_name = session:getVariable("domain_name");
pin_number = session:getVariable("pin_number");
@ -226,6 +213,8 @@ if (session:ready()) then
conference_room_uuid = string.lower(row["conference_room_uuid"]);
conference_center_uuid = string.lower(row["conference_center_uuid"]);
meeting_uuid = string.lower(row["meeting_uuid"]);
record = string.lower(row["record"]);
profile = string.lower(row["profile"]);
max_members = row["max_members"];
wait_mod = row["wait_mod"];
member_type = row["member_type"];
@ -241,37 +230,112 @@ if (session:ready()) then
--set the meeting uuid
session:setVariable("meeting_uuid", meeting_uuid);
if (conference_center_uuid ~= nil) then
--set a conference parameter
--conference <confname> set <parameter_name> <value>
if (conference_center_uuid == nil) then
--invalid pin number
session:streamFile("phrase:voicemail_fail_auth:#");
session:hangup("NORMAL_CLEARING");
else
--check if the conference exists
cmd = "conference "..meeting_uuid.."-"..domain_name.." xml_list";
result = trim(api:executeString(cmd));
if (string.sub(result, -9) == "not found") then
conference_exists = false;
else
conference_exists = true;
end
--set a conference parameter
if (max_members ~= nil) then
--max members must be 2 or more
session:execute("set","conference_max_members="..max_members);
if (conference_exists) then
cmd = "conference "..meeting_uuid.."-"..domain_name.." get count";
count = trim(api:executeString(cmd));
if (count ~= nil) then
if (tonumber(count) >= tonumber(max_members)) then
session:execute("playback", sounds_dir.."/"..default_language.."/"..default_dialect.."/"..default_voice.."/conference/conf-locked.wav");
session:hangup("CALL_REJECTED");
end
if (mute == "true") then
flags = flags .. "mute";
end
if (enter_sound ~= nil) then
session:execute("set","conference_enter_sound="..enter_sound);
end
end
--announce the caller
if (announce == "true") then
--prompt for the name of the caller
session:execute("playback", sounds_dir.."/"..default_language.."/"..default_dialect.."/"..default_voice.."/ivr/ivr-say_name.wav");
session:execute("playback", "tone_stream://v=-7;%%(500,0,500.0)");
--record the response
max_len_seconds = 5;
silence_threshold = "500";
silence_secs = "2";
session:recordFile("/tmp/conference-"..uuid..".wav", max_len_seconds, silence_threshold, silence_secs);
end
--wait for moderator
if (wait_mod == "true") then
if (conference_exists) then
--continue
else
session:execute("set","conference_enter_sound=");
if (member_type == "participant") then
--set music on hold variable
cmd = "uuid_setvar "..uuid.." hold_music "..hold_music;
result = api:executeString(cmd);
--put the call on hold
--cmd = "uuid_hold "..uuid;
--result = api:executeString(cmd);
--loop until the conference exists
x = 0;
y = 0;
while true do
--sleep a moment to prevent using unecessary resources
session:sleep(3000);
--play a tone
if (x > 2) then
session:execute("playback", "tone_stream://L=2;%(25,200,440,40);");
--session:execute("playback", "ivr/ivr-stay_on_line_call_answered_momentarily.wav");
x = 1;
end
--check if the conference exists
cmd = "conference "..meeting_uuid.."-"..domain_name.." xml_list";
result = trim(api:executeString(cmd));
if (string.sub(result, -9) == "not found") then
--continue the loop
else
--set hold to off
--cmd = "uuid_hold off "..uuid;
--result = api:executeString(cmd);
--exit the loop;
break;
end
--end the conference when the limit is reached
park_timeout_seconds = 1200;
if (y > tonumber(park_timeout_seconds)) then
break;
end
--increment the value of x and y
x = x + 1;
y = y + 1;
end
end
end
end
--set the exit sound
if (exit_sound ~= nil) then
session:execute("set","conference_exit_sound="..exit_sound);
end
--else
-- session:execute("set","conference_exit_sound=");
--end
--working
--get number of people in the conference
--conference Conference-Center-voip.fusionpbx.com get count
--get number of seconds since the conference started
--conference Conference-Center-voip.fusionpbx.com get run_time
if (wait_mod == "true") then
--flags = flags .. "|wait_mod"; --not working
--session:execute("conference","Conference-Center-voip.fusionpbx.com(set conference-flags=wait-mod)"); --not working
conference_profile = "wideband-wait-mod";
else
conference_profile = "default";
--set flags and moderator controls
if (mute == "true") then
flags = flags .. "mute";
end
if (member_type == "moderator") then
--set as the moderator
@ -285,28 +349,44 @@ if (session:ready()) then
--set the start epoch
start_epoch = os.time();
--send the call to the conference
--session:execute("conference","confname@profilename+[conference pin number]+flags{moderator}");
cmd = meeting_uuid.."-"..domain_name.."@"..conference_profile.."+flags{".. flags .."}";
--get the session uuid
if (record == "true") then
--get the conference xml_list
cmd = "conference "..meeting_uuid.."-"..domain_name.." xml_list";
result = trim(api:executeString(cmd));
if (conference_exists) then
--get the content to the <conference> tag
result = string.match(result,[[<conference (.-)>]],1);
--get the uuid out of the xml tag contents
conference_session_uuid = string.match(result,[[uuid="(.-)"]],1);
--log entry
freeswitch.consoleLog("INFO","conference_session_uuid: " .. conference_session_uuid .. "\n");
--record the conference
cmd = "conference "..meeting_uuid.."-"..domain_name.." record /tmp/"..conference_session_uuid..".wav";
response = api:executeString(cmd);
end
end
--announce the caller
if (announce == "true") then
--announce the caller - play the recording
cmd = "conference "..meeting_uuid.."-"..domain_name.." play /tmp/conference-"..uuid..".wav";
freeswitch.consoleLog("notice", "[conference] ".. cmd .."\n");
session:execute("conference",cmd);
--alternative
--uuid_transfer <uuid> conference:3000@default inline
--get the conference variables
conference_name = session:getVariable("conference_name");
conference_uuid = session:getVariable("conference_uuid");
conference_recording = session:getVariable("conference_recording");
freeswitch.consoleLog("NOTICE", "Conference Center: conference_name: 2 " .. conference_name .. "\n");
freeswitch.consoleLog("NOTICE", "Conference Center: conference_uuid: 2 " .. conference_uuid .. "\n");
if (conference_recording) then
freeswitch.consoleLog("NOTICE", "Conference Center: conference_recording: " .. conference_recording .. "\n");
end
--freeswitch.consoleLog("notice", "[conference] line: 147\n");
response = api:executeString(cmd);
--play has entered the conference
cmd = "conference "..meeting_uuid.."-"..domain_name.." play "..sounds_dir.."/"..default_language.."/"..default_dialect.."/"..default_voice.."/conference/conf-has_joined.wav";
freeswitch.consoleLog("notice", "[conference] ".. cmd .."\n");
response = api:executeString(cmd);
else
session:streamFile("phrase:voicemail_fail_auth:#");
session:hangup("NORMAL_CLEARING");
if (enter_sound ~= nil) then
cmd = "conference "..meeting_uuid.."-"..domain_name.." play "..enter_sound;
response = api:executeString(cmd);
end
end
--send the call to the conference
cmd = meeting_uuid.."-"..domain_name.."@"..profile.."+flags{".. flags .."}";
session:execute("conference", cmd);
end
end