FreeSWITCH Dialplan of conference

#!/usr/bin/lua

--Author:jncheng

--Version:20150520

--Email:[email protected]


--[[

1.In FreeSWITCH dial plan public.xml  and default.xml,you must add follow:

   <extension name="nb_conferences">

      <condition field="destination_number" expression="^(30\d{2})$">

        <action application="lua" data="conference.lua"/>

      </condition>

    </extension>

2.If you want new user join the conference,you can use:

fs_cli -x "bgapi originate {origination_caller_id_number=7777}sofia/external/[email protected]:5080  3001"



7777  is echo number

3001  the conference number

1003  the will join user(register on another host)

]]


--Get the some variable

local domain = session:getVariable("domain_name")

local dest_exten = session:getVariable("destination_number")


--Connect the FreeSWITCH Core database

local dbh = freeswitch.Dbh("odbc://fs:fs:123qwe")

--freeswitch.consoleLog("NOTICE","start connect DB...\r\n")

assert(dbh:connected())

dbh:query("select presence_id as data from channels where application='conference' or application='lua'",function(row) 

        --freeswitch.consoleLog("NOTICE","------------------------------------------")

        --freeswitch.consoleLog("NOTICE",string.format("%s\n",row.data))

        --freeswitch.consoleLog("NOTICE","------------------------------------------")

        conference_data = string.format("%s",row.data)

end);

--Start handle the conference

if conference_data == nil then

    --If the conference_data is nil,Create the new conference on the some host

    session:execute("conference",dest_exten.."-"..domain.."@default")

else

  --defile splist string func

  function Split(szFullString, szSeparator)  

    local nFindStartIndex = 1  

    local nSplitIndex = 1  

    local nSplitArray = {}  

    while true do  

    local nFindLastIndex = string.find(szFullString, szSeparator, nFindStartIndex)  

    if not nFindLastIndex then  

      nSplitArray[nSplitIndex] = string.sub(szFullString, nFindStartIndex, string.len(szFullString))  

      break  

    end  

    nSplitArray[nSplitIndex] = string.sub(szFullString, nFindStartIndex, nFindLastIndex - 1)  

    nFindStartIndex = nFindLastIndex + string.len(szSeparator)  

    nSplitIndex = nSplitIndex + 1  

    end  

    return nSplitArray  

  end

  

  --Get the confer_host value

  local confer_host = Split(conference_data,"@")[2]

  --local confer_host = Split(confer_name,"-")[2]

  --freeswitch.consoleLog("INFO","the conference_host is:"..confer_host.."\n")

  if confer_host == domain then

    --If the confer_host  == originate_host,it will be on some host

session:execute("conference",dest_exten.."-"..domain.."@default")

  else

    dbh:query("select dest as data from channels where application='conference' or application='lua'",function(row) 

        --freeswitch.consoleLog("NOTICE","------------------------------------------")

        --freeswitch.consoleLog("NOTICE",string.format("%s\n",row.data))

        --freeswitch.consoleLog("NOTICE","------------------------------------------")

        dest_data = string.format("%s",row.data)

    end);

--If the dialed conference number in the db,coming the first originate_host

if dest_exten == dest_data then

      local confer_dest_str = "sofia/external/"..dest_exten.."@"..confer_host..":5080"

      session:execute("bridge",confer_dest_str)

else

 --This is create new conference in the originate host

 session:execute("conference",dest_exten.."-"..domain.."@default")

 --freeswitch.consoleLog("INFO","the domain is:"..confer_dest_str.."\n")

end

  end

end


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章