--[[
--会议lua模块 lua
]]
-- //===========func start================
-- Function :: Determine how many other participants are already in the conference
function Get_Participant_Count(confroom)
local total = 2;
api = freeswitch.API();
local output = api:executeString("conference "..confroom.." list");
debug.info("output.."..output);
if (string.find(output,"not"))==nil then
total = 0;
else
total = string.sub(output,1,2);
end
debug.info("Get_Participant_Count.."..total);
return total;
end
-- Function :: Voices the count of other participants in the conference
function Say_Other_Participant_Count(participant_count)
if(participant_count == 0) then
debug.info("This is the first person in the conference");
session:streamFile("conference/conf-alone.wav");
else
session:streamFile("conference/conf-has_joined.wav");
session:execute("say","en number pronounced ".. participant_count);
session.streamFile("conference/conf-otherinparty.wav");
end
end
-- Function :: Database lookup to check conference rooms
function DB_Check_Conference_Room(confroom)
debug.info("check..confroom."..confroom);
if(confroom) then
-- 此处可以连接数据库
return string.find(confroom, "3[012][0-9][0-9]");
else
return false;
end
end
-- Function :: Database lookup to check conference rooms password
function DB_Check_Moderator_Password(confroom, password)
debug.info("check..pwd."..confroom..password);
-- 此处可以连接数据库
return string.find(password, "1234");
end
-- //===========func end================
-- //===========debug start================
debug = {}
function debug.var(k, v)
v = v or 'nil'
freeswitch.consoleLog("notice", "==DebugVar== " .. k .. ": " .. v .. "\n")
end
function debug.info(s)
freeswitch.consoleLog("info", s .. "\n")
end
function debug.notice(s)
freeswitch.consoleLog("notice", s .. "\n")
end
-- //============debug end ===============
-- //============main ===============
session:answer();
debug.info("========answer============");
-- //============vars ===============
confroom_prompt_count = 0;
confroom_prompt_limit = 3;
password_prompt_count = 0;
password_prompt_limit = 3;
while(session:ready()) do
confroom_prompt_count = confroom_prompt_count+1;
if(confroom_prompt_count <= confroom_prompt_limit) then
debug.info("Prompting for Conference Room...");
session:flushDigits();
local room_digits = session:playAndGetDigits(2, 5, 3, 3000, "#", "conference/conf-enter_conf_number.wav", "", "\\d+|\\*");
debug.info("room_digits...."..room_digits);
session:say(room_digits, "en", "name_spelled", "iterated");
local confroom_result = DB_Check_Conference_Room(room_digits);
-- check confroom
if(confroom_result) then
session:streamFile("conference/conf-members_in_conference.wav");
while (session:ready()) do
password_prompt_count = password_prompt_count+1;
if(password_prompt_count <= password_prompt_limit) then
debug.info("Prompting for Conference Password...");
session:flushDigits();
local pwd_digits = session:playAndGetDigits(2, 5, 3, 3000, "#", "conference/conf-enter_conf_pin.wav", "", "\\d+|\\*");
debug.info("pwd_digits...."..pwd_digits);
session:say(pwd_digits, "en", "name_spelled", "iterated");
local pwd_result = DB_Check_Moderator_Password(room_digits,pwd_digits);
if(pwd_result) then
local participant_count = Get_Participant_Count(room_digits.."-10.0.10.146");
Say_Other_Participant_Count(participant_count);
session:flushDigits();
session:execute("conference", room_digits.."-10.0.10.146@default+flags{moderator}");
else
-- User entered a bad moderator password
session:streamFile("conference/conf-bad-pin.wav");
-- end pwd_result if
end
else
-- User exceeded the password prompt limit, say bye-bye
session:streamFile("conference/conf-goodbye.wav");
session:hangup();
-- end password_prompt_count if
end
-- end while
end
-- else confroom_result
else
-- User entered a bad conference room number
session:streamFile("conference/dir-no_matching_results.wav");
session:streamFile("conference/dir-please_try_again.wav");
-- end confroom_result if
end
-- else confroom_prompt_count
else
-- User exceeded the confroom prompt limit, say bye-bye
session:streamFile("conference/conf-goodbye.wav");
session:hangup();
-- end confroom_prompt_count if
end
-- end while
end