码迷,mamicode.com
首页 > 其他好文 > 详细

FreeSWITCH Dialplan of conference

时间:2015-05-18 21:03:54      阅读:300      评论:0      收藏:0      [点我收藏+]

标签:lua

#!/usr/bin/lua

--Author:jncheng

--Version:20150518


--Get the some variable

domain = session:getVariable("domain_name")

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 application_data as data from channels where application=‘conference‘",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_name = Split(conference_data,"@")[1]

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

  

  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‘",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


本文出自 “什么也没有留下” 博客,请务必保留此出处http://3357278.blog.51cto.com/3347278/1652418

FreeSWITCH Dialplan of conference

标签:lua

原文地址:http://3357278.blog.51cto.com/3347278/1652418

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!