1、返回480
Reason: Q.850;cause=96;text="MANDATORY_IE_MISSING"
我这里遇到原因是:fs外呼时, 对端的ip端口写错了。freeswitch internal端口是5060,external端口是5080
<extension name="Output fs">
<condition field="destination_number" expression="^0(10[01][0-9])$">
<action application="bridge" data="sofia/external/sip:$1@10.10.10.10:5080"/>
</condition>
</extension>
2、返回503
3、获取b-leg uuid
思路:1)创建一个uuid保存到临时变量中 2)设置sip response header 3)呼叫时指定uuid
<action application="set" data="my_bleg_uuid=${create_uuid()}"/>
<action application="set" data="sip_rh_X-BLEG-UUID=${my_bleg_uuid}"/>
<action application="bridge" data="{origination_uuid=${my_bleg_uuid}}sofia/gateway/iot_didi_sbc_srv/$1"/>
4、设置SSRC
有的webrtc要求SSRC必须统一,因此我们需要能够设置FreeSwitch的本端的SSRC,可以通过如下配置
<!-- 生成随机数 -->
<action application="set" data="my_ssrc_random=${expr(randomize(&x);ceil(random(10000,20000,&x)))}" inline=true/>
<!-- //获取对端的SSRC, 正则的意思是匹配成功返回数字,用%1接收,匹配失败返回原数据,b参数如果配失败则强制返回false -->
<action application="set" data="my_ssrc_from_uac=${regex(${switch_r_sdp}|ssrc:(\d+) cname.*$|%1|b)}" />
<!-- 设置通道变量 -->
<action application="set" data="rtp_use_ssrc=${cond(${regex(${switch_r_sdp}|ssrc:(\d+) cname.*$)} == true ? ${my_ssrc_from_uac} : ${my_ssrc_random} )}" />
5、显示来电号码相关参数设置
effective_caller_id_number:用于设置在a-leg上,但是会影响b-leg的主叫号码显示(来电显示)
origination_caller_id_number:可以设置a-leg,也可以设置b-leg上,它将影响本leg的来电显示
6、将自定义sip header透传到对端
<action application="set" data="sip_copy_custom_headers=true"/>
7、网关设置参数
<param name="caller-id-in-from" value="true"/>
false(默认)
From: "13812344321" <sip:FreeSWITCH@10.40.185.192>;tag=yvUHm3Qm5pypg
true:
From: "13812344321" <sip:13812344321@10.40.185.192>;tag=v1H19H7Bm3rZB
8. RTP 开启调试 SWITCH_RTP_FLAG_DEBUG_RTP_READ
uuid_debug_media <
uuid
> <
read
|write|both|vread|vwrite|vboth> <
on|off>
R sofia/internal/1003@192.168.65.3 b= 172 192.168.65.3:17668 192.168.65.114:16072 192.168.65.114:16072 pt=0 ts=2981605109 m=0
W sofia/internal/1003@192.168.65.3 b= 172 192.168.65.3:17668 192.168.65.114:16072 192.168.65.114:16072 pt=0 ts=12212960 m=0
R sofia/internal/1003@192.168.65.3 b= 172 192.168.65.3:17668 192.168.65.114:16072 192.168.65.114:16072 pt=0 ts=2981605269 m=0
W sofia/internal/1003@192.168.65.3 b= 172 192.168.65.3:17668 192.168.65.114:16072 192.168.65.114:16072 pt=0 ts=12213120 m=0
9. 随机选择网关
9.1 dialplan方式
<extension name="DE">
<condition field="destination_number" expression="^([B-Z].*[13579])$">
<action application="bridge" data="sofia/gateway/sip:$1@110.110.110.11:5080|sofia/gateway/sip:$1@110.110.110.12:5080/>
</condition>
</extension>
<extension name="ED">
<condition field="destination_number" expression="^([B-Z].*[13579])$">
<action application="bridge" data="sofia/gateway/sip:$1@110.110.110.12:5080|sofia/gateway/sip:$1@110.110.110.11:5080/>
</condition>
</extension>
9.2 随机数方式
<action application="set" data="gw1=gw${expr(randomize(&x);ceil(random(30,39,&x)))}"/>
<action application="set" data="gw2=gw${expr(randomize(&x);ceil(random(30,39,&x)))}"/>
<action application="bridge" data="sofia/gateway/${gw1}/$1|sofia/gateway/${gw2}/$1"/>
9.3 mod_distrbuite
该模块是需要手动安装,
修改代码根目录中 modules.conf,将applications/mod_distributor注释打开,然后执行mod_distributor && make mod_distributor-install,最后生成mod_distributor.so
conf/autoload_configs/distributor.conf.xml中进行如下设置:
<list name="dist1" total-weight="10">
<node name="30" weight="1"/>
<node name="31" weight="1"/>
<node name="32" weight="1"/>
<node name="33" weight="1"/>
<node name="34" weight="1"/>
<node name="35" weight="1"/>
<node name="36" weight="1"/>
<node name="37" weight="1"/>
<node name="38" weight="1"/>
<node name="39" weight="1"/>
</list>
freeswitch> distributor dist1
32
freeswitch> distributor dist1
37
通过distributor进行选择同时忽略掉状态为down的gateway,loop代表最多尝试2次
<extension name="gw">
<condition field="destination_number" expression="^(01[358].*)$">
<action application="bridge" data="sofia/gateway/gw${distributor(dist1 ${sofia(profile internal gwlist down)})}/$1" loop="2"/>
</condition>
</extension>
关于regex命令使用可参考如下链接
https://freeswitch.org/confluence/display/FREESWITCH/mod_commands
10. 录音相关
freeswitch录音默认开启了缓存,即RTP流大小到达65536字节写一次wav文件。
可以通过下面参数进行关闭缓存功能,以便达到实时录音效果
<action application="set" data="enable_file_write_buffering=false"/>
循环播放
<action application="endless_playback" data="temp/test.wav"/>
freeswitch开启录音,如果文件后缀是wav,那么文件比较大(未压缩),可以写成.PCMU格式(raw文件格式),然后通过sox命令进行转码:
sox -t raw -c 2 -e signed-integer -b 16 -r 48000 old.PCMU new.wav
11、sip只监听tcp端口
修改internal.xml文件中
<!-- if you want to send any special bind params of your own -->
<param name="bind-params" value="transport=tcp"/>