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

FreeSWITCH Dialplan of conference join user

时间:2015-05-20 14:58:57      阅读:448      评论:0      收藏:0      [点我收藏+]

标签:freeswitch lua

#!/usr/bin/env lua

--Author:jncheng

--Email:burtte@sina.com

--Version:20150520


--[[

1.If you want use the lua file,you must modify the conference.conf.xml:

<control action="execute_application" digits="*" data="lua /${FreeSWITCH_base_dir}/scripts/add_user_to_conference.lua"/>

<control action="events" digits="#"/>

]]


--Set some varvabile

--local cai_lin = "/opt/freeswitch/sounds/ring.wav"

--session:setVariable("ringback",cai_lin)

local src_exten = session:getVariable("caller_id_number")

local dest_exten = session:getVariable("destination_number")

local domain = session:getVariable("domain_name")

local confer_uid = session:getVariable("conference_uuid")

local fs_dir = "/usr/local/freeswitch/"

local playSound = fs_dir.."sounds/add_user_to_conference.wav"

local errSound = fs_dir.."sounds/input_error.wav"

local dialed_number = session:playAndGetDigits(4,4,3,7000,‘#‘,playSound,errSound,"\\d+")

----------------------------min_digits,max_digits,max_attempts,timeout,terminators

----------------------------prompt_audio_file,input_error_audio file,digits_regex


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

assert(dbh:connected())

--Get the conference number

dbh:query("select dest as data from channels where (application=‘lua‘ or application=‘conference‘) and cid_num="..src_exten,function(row) 

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

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

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

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

end);


--Get conference data of src exten host data

dbh:query("select presence_id as data from channels where (application=‘conference‘ or application=‘lua‘) and cid_num="..src_exten,function(row) 

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

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

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

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

end);

--Define the split function and get the host IP

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 invite user‘s(Fist) register host 

local originate_host = Split(originate_data,"@")[2]

--freeswitch.consoleLog("ERR","the originate_host is:"..originate_host.."\n")

--Get the dest_exten host

dbh:query("select sub_to_host as host from sip_subscriptions where sip_user="..dialed_number,function(row) 

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

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

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

        dest_host = string.format("%s",row.host)

end);

--freeswitch.consoleLog("ERR","the dialed_number is:"..dialed_number.."\n")

--freeswitch.consoleLog("ERR","the dest_host is:"..dest_host.."\n")

api = freeswitch.API()

if originate_host == dest_host then 

  --local dial_str = "originate {origination_caller_id_number=7777,execute_on_originate=‘playback::welcome.wav‘}user/1003 3001"

  local dial_str = "originate {origination_caller_id_number="..src_exten.."}user/"..dialed_number.." "..confer_num

  api:executeString(dial_str)

  --freeswitch.consoleLog("ERR","the hangupCause is:"..fail_cause.."\n")

else

  --freeswitch.consoleLog("ERR","the dest_host is:"..dest_host.."\n")

  local dial_str = "originate {origination_caller_id_number="..src_exten.."}sofia/external/"..dialed_number.."@"..dest_host..":5080 "..confer_num

  api:executeString(dial_str)

  --freeswitch.consoleLog("ERR","the dest_host is:"..dial_str.."\n")

end


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

FreeSWITCH Dialplan of conference join user

标签:freeswitch lua

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

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