Prevent errors when someone abandons a call to conference center before providing a pin number.

This commit is contained in:
Mark Crane
2013-04-03 07:38:29 +00:00
parent 24199dcc6b
commit b3aded198b
@@ -147,152 +147,160 @@
dbh = freeswitch.Dbh(database["system"]); dbh = freeswitch.Dbh(database["system"]);
--get the conference sessions --get the conference sessions
sql = [[SELECT count(*) as num_rows if (conference_session_uuid) then
FROM v_conference_sessions sql = [[SELECT count(*) as num_rows
WHERE conference_session_uuid = ']] .. conference_session_uuid ..[[']]; FROM v_conference_sessions
status = dbh:query(sql, function(row) WHERE conference_session_uuid = ']] .. conference_session_uuid ..[[']];
num_rows = string.lower(row["num_rows"]); status = dbh:query(sql, function(row)
end); num_rows = string.lower(row["num_rows"]);
freeswitch.consoleLog("notice", "[conference] SQL: " .. sql .. " Rows:"..num_rows.."\n"); end);
if (tonumber(num_rows) == 0) then freeswitch.consoleLog("notice", "[conference] SQL: " .. sql .. " Rows:"..num_rows.."\n");
local sql = {} if (tonumber(num_rows) == 0) then
table.insert(sql, "INSERT INTO v_conference_sessions "); local sql = {}
table.insert(sql, "("); table.insert(sql, "INSERT INTO v_conference_sessions ");
table.insert(sql, "conference_session_uuid, "); table.insert(sql, "(");
table.insert(sql, "domain_uuid, "); table.insert(sql, "conference_session_uuid, ");
table.insert(sql, "meeting_uuid, "); table.insert(sql, "domain_uuid, ");
--if (conference_recording) then table.insert(sql, "meeting_uuid, ");
-- table.insert(sql, "recording, "); --if (conference_recording) then
--end -- table.insert(sql, "recording, ");
--if (wait_mod) then --end
-- table.insert(sql, "wait_mod, "); --if (wait_mod) then
--end -- table.insert(sql, "wait_mod, ");
--table.insert(sql, "start_epoch, "); --end
table.insert(sql, "profile "); --table.insert(sql, "start_epoch, ");
table.insert(sql, ") "); table.insert(sql, "profile ");
table.insert(sql, "VALUES "); table.insert(sql, ") ");
table.insert(sql, "( "); table.insert(sql, "VALUES ");
table.insert(sql, "'".. conference_session_uuid .."', "); table.insert(sql, "( ");
table.insert(sql, "'".. domain_uuid .."', "); table.insert(sql, "'".. conference_session_uuid .."', ");
table.insert(sql, "'".. meeting_uuid .."', "); table.insert(sql, "'".. domain_uuid .."', ");
--if (conference_recording) then table.insert(sql, "'".. meeting_uuid .."', ");
-- table.insert(sql, "'".. conference_recording .."', "); --if (conference_recording) then
--end -- table.insert(sql, "'".. conference_recording .."', ");
--if (wait_mod) then --end
-- table.insert(sql, "'".. wait_mod .."', "); --if (wait_mod) then
--end -- table.insert(sql, "'".. wait_mod .."', ");
--table.insert(sql, "'".. start_epoch .."', "); --end
table.insert(sql, "'".. profile .."' "); --table.insert(sql, "'".. start_epoch .."', ");
table.insert(sql, ") "); table.insert(sql, "'".. profile .."' ");
SQL_STRING = table.concat(sql, "\n"); table.insert(sql, ") ");
dbh:query(SQL_STRING); SQL_STRING = table.concat(sql, "\n");
freeswitch.consoleLog("notice", "[conference] SQL: " .. SQL_STRING .. "\n"); dbh:query(SQL_STRING);
freeswitch.consoleLog("notice", "[conference] SQL: " .. SQL_STRING .. "\n");
end
end end
--add the conference sessions details --add the conference sessions details
local sql = {} if (conference_session_uuid) then
table.insert(sql, "INSERT INTO v_conference_session_details "); local sql = {}
table.insert(sql, "("); table.insert(sql, "INSERT INTO v_conference_session_details ");
table.insert(sql, "conference_session_detail_uuid, "); table.insert(sql, "(");
table.insert(sql, "domain_uuid, "); table.insert(sql, "conference_session_detail_uuid, ");
table.insert(sql, "conference_session_uuid, "); table.insert(sql, "domain_uuid, ");
table.insert(sql, "meeting_uuid, "); table.insert(sql, "conference_session_uuid, ");
table.insert(sql, "username, "); table.insert(sql, "meeting_uuid, ");
table.insert(sql, "caller_id_name, "); table.insert(sql, "username, ");
table.insert(sql, "caller_id_number, "); table.insert(sql, "caller_id_name, ");
table.insert(sql, "network_addr, "); table.insert(sql, "caller_id_number, ");
table.insert(sql, "uuid, "); table.insert(sql, "network_addr, ");
if (conference_moderator) then table.insert(sql, "uuid, ");
table.insert(sql, "moderator, "); if (conference_moderator) then
table.insert(sql, "moderator, ");
end
table.insert(sql, "start_epoch, ");
table.insert(sql, "end_epoch ");
table.insert(sql, ") ");
table.insert(sql, "VALUES ");
table.insert(sql, "( ");
table.insert(sql, "'".. conference_session_detail_uuid .."', ");
table.insert(sql, "'".. domain_uuid .."', ");
table.insert(sql, "'".. conference_session_uuid .."', ");
table.insert(sql, "'".. meeting_uuid .."', ");
table.insert(sql, "'".. username .."', ");
table.insert(sql, "'".. caller_id_name .."', ");
table.insert(sql, "'".. caller_id_number .."', ");
table.insert(sql, "'".. network_addr .."', ");
table.insert(sql, "'".. uuid .."', ");
if (conference_moderator) then
table.insert(sql, "'".. conference_moderator .."', ");
end
table.insert(sql, "'".. start_epoch .."', ");
table.insert(sql, "'".. end_epoch .."' ");
table.insert(sql, ") ");
SQL_STRING = table.concat(sql, "\n");
dbh:query(SQL_STRING);
end end
table.insert(sql, "start_epoch, ");
table.insert(sql, "end_epoch ");
table.insert(sql, ") ");
table.insert(sql, "VALUES ");
table.insert(sql, "( ");
table.insert(sql, "'".. conference_session_detail_uuid .."', ");
table.insert(sql, "'".. domain_uuid .."', ");
table.insert(sql, "'".. conference_session_uuid .."', ");
table.insert(sql, "'".. meeting_uuid .."', ");
table.insert(sql, "'".. username .."', ");
table.insert(sql, "'".. caller_id_name .."', ");
table.insert(sql, "'".. caller_id_number .."', ");
table.insert(sql, "'".. network_addr .."', ");
table.insert(sql, "'".. uuid .."', ");
if (conference_moderator) then
table.insert(sql, "'".. conference_moderator .."', ");
end
table.insert(sql, "'".. start_epoch .."', ");
table.insert(sql, "'".. end_epoch .."' ");
table.insert(sql, ") ");
SQL_STRING = table.concat(sql, "\n");
dbh:query(SQL_STRING);
--if the conference is empty --if the conference is empty
cmd = "conference "..meeting_uuid.."-"..domain_name.." xml_list"; if (conference_session_uuid) then
result = trim(api:executeString(cmd)); cmd = "conference "..meeting_uuid.."-"..domain_name.." xml_list";
if (string.sub(result, -9) == "not found") then result = trim(api:executeString(cmd));
--get the conference start_epoch if (string.sub(result, -9) == "not found") then
sql = [[SELECT start_epoch --get the conference start_epoch
FROM v_conference_session_details sql = [[SELECT start_epoch
WHERE conference_session_uuid = ']] .. conference_session_uuid ..[[' FROM v_conference_session_details
ORDER BY start_epoch ASC WHERE conference_session_uuid = ']] .. conference_session_uuid ..[['
LIMIT 1]]; ORDER BY start_epoch ASC
status = dbh:query(sql, function(row) LIMIT 1]];
start_epoch = string.lower(row["start_epoch"]); status = dbh:query(sql, function(row)
end); start_epoch = string.lower(row["start_epoch"]);
freeswitch.consoleLog("notice", "[conference] <conference_start_epoch> sql: " .. sql .. "\n"); end);
freeswitch.consoleLog("notice", "[conference] <conference_start_epoch> sql: " .. sql .. "\n");
--set the conference_recording --set the conference_recording
conference_recording = recordings_dir.."/archive/"..os.date("%Y", start_epoch).."/"..os.date("%b", start_epoch).."/"..os.date("%d", start_epoch) .."/"..conference_session_uuid; conference_recording = recordings_dir.."/archive/"..os.date("%Y", start_epoch).."/"..os.date("%b", start_epoch).."/"..os.date("%d", start_epoch) .."/"..conference_session_uuid;
--conference has ended set the end_epoch --conference has ended set the end_epoch
local sql = {} local sql = {}
table.insert(sql, "update v_conference_sessions set "); table.insert(sql, "update v_conference_sessions set ");
table.insert(sql, "recording = '".. conference_recording .."', "); table.insert(sql, "recording = '".. conference_recording .."', ");
table.insert(sql, "start_epoch = '".. start_epoch .."', "); table.insert(sql, "start_epoch = '".. start_epoch .."', ");
table.insert(sql, "end_epoch = '".. end_epoch .."' "); table.insert(sql, "end_epoch = '".. end_epoch .."' ");
table.insert(sql, "where conference_session_uuid = '"..conference_session_uuid.."' "); table.insert(sql, "where conference_session_uuid = '"..conference_session_uuid.."' ");
SQL_STRING = table.concat(sql, "\n"); SQL_STRING = table.concat(sql, "\n");
freeswitch.consoleLog("notice", "[conference] SQL: " .. SQL_STRING .. "\n"); freeswitch.consoleLog("notice", "[conference] SQL: " .. SQL_STRING .. "\n");
dbh:query(SQL_STRING); dbh:query(SQL_STRING);
--convert the wav to an mp3 --convert the wav to an mp3
if (record == "true") then if (record == "true") then
--cmd = "sox "..conference_recording..".wav -r 16000 -c 1 "..conference_recording..".mp3"; --cmd = "sox "..conference_recording..".wav -r 16000 -c 1 "..conference_recording..".mp3";
cmd = "/usr/bin/lame -b 32 --resample 8 -a "..conference_recording..".wav "..conference_recording..".mp3"; cmd = "/usr/bin/lame -b 32 --resample 8 -a "..conference_recording..".wav "..conference_recording..".mp3";
freeswitch.consoleLog("notice", "[conference] cmd: " .. cmd .. "\n"); freeswitch.consoleLog("notice", "[conference] cmd: " .. cmd .. "\n");
os.execute(cmd); os.execute(cmd);
--if (file_exists(conference_recording..".mp3")) then --if (file_exists(conference_recording..".mp3")) then
-- cmd = "rm "..conference_recording..".wav"; -- cmd = "rm "..conference_recording..".wav";
-- os.execute(cmd); -- os.execute(cmd);
--end --end
end end
--send the email addresses --send the email addresses
sql = [[SELECT c.contact_email FROM v_users as u, v_meeting_users as m, v_contacts as c sql = [[SELECT c.contact_email FROM v_users as u, v_meeting_users as m, v_contacts as c
WHERE m.domain_uuid = ']] .. domain_uuid ..[[' WHERE m.domain_uuid = ']] .. domain_uuid ..[['
AND u.user_uuid = m.user_uuid AND u.user_uuid = m.user_uuid
AND m.meeting_uuid = ']] .. meeting_uuid ..[[' AND m.meeting_uuid = ']] .. meeting_uuid ..[['
and u.contact_uuid = c.contact_uuid]]; and u.contact_uuid = c.contact_uuid]];
if (debug["sql"]) then if (debug["sql"]) then
freeswitch.consoleLog("notice", "[conference] <email> SQL: " .. sql .. "\n"); freeswitch.consoleLog("notice", "[conference] <email> SQL: " .. sql .. "\n");
end end
status = dbh:query(sql, function(row) status = dbh:query(sql, function(row)
if (row["contact_email"] ~= nil) then if (row["contact_email"] ~= nil) then
contact_email = string.lower(row["contact_email"]); contact_email = string.lower(row["contact_email"]);
if (string.len(contact_email) > 3) then if (string.len(contact_email) > 3) then
freeswitch.consoleLog("notice", "[conference] contact_email: " .. contact_email .. "\n"); freeswitch.consoleLog("notice", "[conference] contact_email: " .. contact_email .. "\n");
if (record == "true") then if (record == "true") then
if (file_exists(conference_recording..".wav")) then if (file_exists(conference_recording..".wav")) then
send_email(contact_email, "", default_language, default_dialect); send_email(contact_email, "", default_language, default_dialect);
end
end end
end end
end end
end end);
end); end
end end
--close the database connection --close the database connection
dbh:release(); if (conference_session_uuid) then
dbh:release();
end
end end
--make sure the session is ready --make sure the session is ready
@@ -433,7 +441,9 @@
dbh:release(); dbh:release();
--set the meeting uuid --set the meeting uuid
session:setVariable("meeting_uuid", meeting_uuid); if (meeting_uuid) then
session:setVariable("meeting_uuid", meeting_uuid);
end
if (conference_center_uuid == nil) then if (conference_center_uuid == nil) then
--invalid pin number --invalid pin number