網(wǎng)站搭建官網(wǎng)個人怎么做網(wǎng)站
雖然知道FreeSWITCH很多年,但是實際學(xué)習(xí)這個軟件的時間很少。
作為語音網(wǎng)關(guān)的硬件廠家,總是以解決客戶實際問題為出發(fā)點,偶爾研究幾分鐘都是因為客戶遇到對接的問題。為了趕進度,不可能去仔細研究freeswitch的設(shè)置,每次都是通過SIP協(xié)議原理,對比FreeSWITCH調(diào)試日志消息,互相參照,排查出可能的原因,再去倒推可能是哪方面的設(shè)置有問題。
所以,這里介紹的是我如何快速入門學(xué)習(xí)FreeSWITCH的干貨,思路可能跟某些權(quán)威指南有所不同。
下面這個文檔,您可能要對照上一篇《使用IAD電話交換機(語音網(wǎng)關(guān))將電話外線對接到FreeSWITCH SIP服務(wù)器》一起看,更容易理解。
電話呼出的SIP協(xié)議和FreeSWITCH日志
SIP呼叫其實很簡單,我們以電話呼出為例。這里呼出例子是根據(jù)上一篇文章來的,就是1000分機通過電話外線呼叫10086號碼。SIP協(xié)議是這樣的:
從FreeSWITCH日志上這樣記錄:
2024-03-06 19:05:33.172906 [NOTICE] switch_channel.c:1104 New Channel
sofia/internal/1000@192.168.3.13
[1ea401e7-6c7b-481f-8752-45742a320922] 2024-03-06 19:05:33.202908
[INFO] mod_dialplan_xml.c:637 Processing 1000 <1000>->010086 in
context default 2024-03-06 19:05:33.202908 [NOTICE]
switch_channel.c:1104 New Channel sofia/external/10086
[901fb9b0-35c9-4ea6-a4a4-3407e2937483] 2024-03-06 19:05:52.623019
[NOTICE] sofia.c:7156 Ring-Ready sofia/external/10086! 2024-03-06
19:05:52.633019 [NOTICE] mod_sofia.c:2272 Ring-Ready
sofia/internal/1000@192.168.3.13! 2024-03-06 19:05:52.633019 [NOTICE]
switch_ivr_originate.c:525 Ring Ready
sofia/internal/1000@192.168.3.13! 2024-03-06 19:05:54.123105 [NOTICE]
sofia.c:8144 Channel [sofia/external/10086] has been answered
2024-03-06 19:05:54.133105 [NOTICE] switch_ivr.c:779 Channel
[sofia/internal/1000@192.168.3.13] has been answered 2024-03-06
19:07:03.243058 [NOTICE] sofia.c:1012 Hangup
sofia/internal/1000@192.168.3.13 [CS_HIBERNATE] [NORMAL_CLEARING]
2024-03-06 19:07:03.243058 [NOTICE] switch_ivr_bridge.c:1289 Hangup
sofia/external/10086 [CS_HIBERNATE] [NORMAL_CLEARING] 2024-03-06
19:07:03.243058 [NOTICE] switch_core_session.c:1682 Session 2
(sofia/external/10086) Ended 2024-03-06 19:07:03.243058 [NOTICE]
switch_core_session.c:1686 Close Channel sofia/external/10086
[CS_DESTROY] 2024-03-06 19:07:03.243058 [NOTICE]
switch_core_session.c:1682 Session 1
(sofia/internal/1000@192.168.3.13) Ended 2024-03-06 19:07:03.243058
[NOTICE] switch_core_session.c:1686 Close Channel
sofia/internal/1000@192.168.3.13 [CS_DESTROY]
電話呼入的SIP協(xié)議和FreeSWITCH調(diào)試
從SIP協(xié)議是這樣的,來看下:
對應(yīng)的日志信息可以看看:
2024-03-06 19:11:12.323305 [NOTICE] switch_channel.c:1104 New Channel sofia/external/18719289062@192.168.3.13:5080 [f4d89a91-9ffb-4db9-b960-fb4429f4c465]
2024-03-06 19:11:12.373308 [INFO] mod_dialplan_xml.c:637 Processing 18719289062 <18719289062>->5551212 in context public
2024-03-06 19:11:12.373308 [NOTICE] switch_ivr.c:2172 Transfer sofia/external/18719289062@192.168.3.13:5080 to XML[1000@default]
2024-03-06 19:11:12.373308 [INFO] mod_dialplan_xml.c:637 Processing 18719289062 <18719289062>->1000 in context default
2024-03-06 19:11:12.373308 [INFO] switch_ivr_async.c:4171 Bound B-Leg: *1 execute_extension::dx XML features
2024-03-06 19:11:12.383308 [INFO] switch_ivr_async.c:4171 Bound B-Leg: *2 record_session::C:/Program Files/FreeSWITCH/recordings/18719289062.2024-03-06-19-11-12.wav
2024-03-06 19:11:12.383308 [INFO] switch_ivr_async.c:4171 Bound B-Leg: *3 execute_extension::cf XML features
2024-03-06 19:11:12.383308 [INFO] switch_ivr_async.c:4171 Bound B-Leg: *4 execute_extension::att_xfer XML features
2024-03-06 19:11:12.383308 [INFO] switch_core_session.c:2648 Sending early media
2024-03-06 19:11:12.383308 [NOTICE] sofia_media.c:92 Pre-Answer sofia/external/18719289062@192.168.3.13:5080!
2024-03-06 19:11:12.433311 [NOTICE] switch_channel.c:1104 New Channel sofia/internal/1000@192.168.3.66:51142 [0d9f8f46-9394-4b60-978e-5f92bee992ca]
2024-03-06 19:11:12.433311 [NOTICE] switch_ivr_originate.c:2845 Cannot create outgoing channel of type [error] cause: [USER_NOT_REGISTERED]
2024-03-06 19:11:12.513316 [NOTICE] sofia.c:7156 Ring-Ready sofia/internal/1000@192.168.3.66:51142!
2024-03-06 19:11:24.342992 [NOTICE] sofia.c:8182 Channel [sofia/internal/1000@192.168.3.66:51142] has been answered
2024-03-06 19:11:24.362993 [NOTICE] switch_ivr_originate.c:3632 Channel [sofia/external/18719289062@192.168.3.13:5080] has been answered
2024-03-06 19:11:46.823278 [NOTICE] sofia.c:1012 Hangup sofia/internal/1000@192.168.3.66:51142 [CS_EXCHANGE_MEDIA] [NORMAL_CLEARING]
2024-03-06 19:11:46.843279 [NOTICE] switch_ivr_bridge.c:1751 Hangup sofia/external/18719289062@192.168.3.13:5080 [CS_EXECUTE] [NORMAL_CLEARING]
2024-03-06 19:11:46.843279 [NOTICE] switch_core_session.c:1682 Session 4 (sofia/internal/1000@192.168.3.66:51142) Ended
2024-03-06 19:11:46.843279 [NOTICE] switch_core_session.c:1686 Close Channel sofia/internal/1000@192.168.3.66:51142 [CS_DESTROY]
2024-03-06 19:11:46.843279 [NOTICE] switch_core_session.c:1682 Session 3 (sofia/external/18719289062@192.168.3.13:5080) Ended
2024-03-06 19:11:46.843279 [NOTICE] switch_core_session.c:1686 Close Channel sofia/external/18719289062@192.168.3.13:5080 [CS_DESTROY]
所以怎么對比SIP消息和FreeSWITCH日志呢?
我們可以從FreeSWITCH Console里面根據(jù)這些關(guān)鍵詞(比如Invite就是New Channel , 180 Ringing就是對應(yīng)Ring-Ready,200 OK就是對應(yīng)就是對應(yīng)has been answered)來看呼叫進展情況。
再配合dialplan信息,就可以理解到FreeSWITCH如何處理呼叫的了。 比如我們看下面這句日志:
2024-03-06 19:11:12.373308 [INFO] mod_dialplan_xml.c:637 Processing
18719289062 <18719289062>->5551212 in context public
mod_dialplan_xml 就是執(zhí)行dialplan,對應(yīng)的就是freeswitch/conf/dialplan下面的文件。根據(jù)主叫和被叫號碼來匹配業(yè)務(wù)流程,5551212這個被叫號碼(很多文檔里會把這個叫做DID)有一個默認流程,文件名是00_inbound_did.xml ,我們把這個xml文件內(nèi)容貼在下面:
<include><extension name="public_did"><condition field="destination_number" expression="^(5551212)$"><!--If you're hosting multiple domains you will want to set thetarget_domain on these calls so they hit the proper domain after youtransfer the caller into the default context. $${domain} is the default domain set from vars.xml but you can set itto any domain you have setup in your user directory.--> <action application="set" data="domain_name=$${domain}"/><!-- This example maps the DID 5551212 to ring 1000 in the default context --><action application="transfer" data="1000 XML default"/></condition></extension>
</include>
這個文檔,有助于您更快捷的了解呼叫信令流程、電話業(yè)務(wù)處理流程。對于想深入了解SIP信令的同學(xué)來說,也可以把SIP debug打開(sofia loglevel all 9),就能看到詳細的信令過程。