打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
简单会议lua脚本 Simple conference.lua

DB schema

conferencing=> \d+ conferences                                  Table "public.conferences"   Column   |  Type   |                        Modifiers                         | Description------------+---------+----------------------------------------------------------+------------- id         | integer | not null default nextval('conferences_id_seq'::regclass) | conf_num   | integer | not null                                                 | conf_pin   | integer |                                                          | conf_owner | text    |                                                          | conf_email | text    |                                                          |
CREATE TABLE conferences(   id SERIAL NOT NULL,    conf_num INT NOT NULL,    conf_pin INT,    conf_owner TEXT,    conf_email TEXT);

Lua script for conferencing

require "luasql.postgres"attempt = 1max_attempts = 3function session_hangup_hook(status)  freeswitch.consoleLog("NOTICE", "Session hangup: " .. status .. "\n")  db_connection:close()  error()endfunction get_conference_num(min, max, attempts, timeout)  local conference_num  freeswitch.consoleLog("NOTICE", "Awaiting caller to enter a conference number phrase:conference_num\n")  conference_num = session:playAndGetDigits(min, max, attempts, timeout, '#', 'phrase:conference_num', '', '\\d+')  return(conference_num)endfunction get_conference_pin(min, max, attempts, timeout, pin_number)  local pin_attempt = 1  local pin_max_attempt = 3  while pin_attempt <= pin_max_attempt do    conference_pin = session:playAndGetDigits(min, max, attempts, timeout, '#', 'phrase:conference_pin', '', '\\d+')    if tonumber(conference_pin) == tonumber(pin_number) then      return true    else      session:execute("phrase", "conference_bad_pin")    end    pin_attempt = pin_attempt + 1  end  return falseendenv = assert(luasql.postgres())db_connection = assert(env:connect("dbname=conferencing user=conf password=conf"))session:answer();session:setHangupHook("session_hangup_hook")if session:ready() then  freeswitch.consoleLog("NOTICE", string.format("Caller has called conferencing server, Playing welcome message phrase:conference_welcome\n"))  session:execute("phrase", "conference_welcome")endwhile attempt <= max_attempts do  conf_num = get_conference_num(1, 4, 3, 4000)  db_cursor = assert(db_connection:execute(string.format("select conf_pin from conferences where conf_num = %d", tonumber(conf_num))))  row = db_cursor:fetch({}, "a")  --[[ do conference authentication ]]--  if row == nil then    --[[ if the conference number does not exist, playback message saying it is         and invalid conference number ]]--    session:execute("phrase", "conference_bad_num")  elseif row["conf_pin"] == nil or row["conf_pin"] == "" then    freeswitch.consoleLog("NOTICE", string.format("Conference %d has no PIN, Sending caller into conference\n", tonumber(conf_num)))    --[[ join the conference ]]--    session:execute("conference", string.format("%s@default", conf_num))  else    freeswitch.consoleLog("NOTICE", string.format("Conference %d has a PIN %d, Authenticating user\n", tonumber(conf_num), tonumber(row["conf_pin"])))    --[[ get the conference pin number ]]--    if ((get_conference_pin(1, 4, 3, 4000, row["conf_pin"])) == true) then      freeswitch.consoleLog("NOTICE", string.format("Conference %d correct PIN entered, Sending caller into conference\n", tonumber(conf_num)))      --[[ join the conference, if the correct pin was entered ]]--      session:execute("conference", string.format("%s@default", conf_num))    else      freeswitch.consoleLog("NOTICE", string.format("Conference %d invalid PIN entered, Looping again\n", tonumber(conf_num)))    end  end  attempt = attempt + 1endsession:execute("phrase", "conference_too_many_failures")session:hangup()

See Also: Mod_lua

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
FreeSWITCH: VoIP实战》: 一个在FreeSWITCH中外呼的Lua脚本
Asterisk电话会议功能主要应用介(1)
Daily snapshots from two sessions - March 4
【转】京东抢购服务高并发实践
极路由安全设计分析姐妹篇 | 渗透测试研究中心
Linux:支持高并发web服务器搭建
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服