FreeSWITCH与FreeSWITCH对接

背景

使用两台服务器,每台服务器上运行一个FreeSWITCH,我们要实现两台FreeSWITCH上的主机互拨

服务器A信息

服务器IP为192.168.0.38

sh 复制代码
freeswitch@debianh61> sofia status

                     Name	   Type	                                      Data	State
=================================================================================================
            external-ipv6	profile	  sip:mod_sofia@[2408:8214:2a1d:2db1:922b:34ff:feeb:9991]:5080	RUNNING (0)
             192.168.0.38	  alias	                                  internal	ALIASED
                 external	profile	           sip:mod_sofia@192.168.0.38:5080	RUNNING (0)
    external::example.com	gateway	                   sip:joeuser@example.com	NOREG
            internal-ipv6	profile	  sip:mod_sofia@[2408:8214:2a1d:2db1:922b:34ff:feeb:9991]:5060	RUNNING (0)
                 internal	profile	           sip:mod_sofia@192.168.0.38:5060	RUNNING (0)
=================================================================================================
4 profiles 1 alias

服务器B信息

服务器IP为192.168.0.53

sh 复制代码
freeswitch@debianb85> sofia status

                     Name	   Type	                                      Data	State
=================================================================================================
            external-ipv6	profile	  sip:mod_sofia@[2408:8214:2a1d:2db1:76d4:35ff:fed9:207d]:5080	RUNNING (0)
             192.168.0.53	  alias	                                  internal	ALIASED
                 external	profile	           sip:mod_sofia@192.168.0.53:5080	RUNNING (0)
    external::example.com	gateway	                   sip:joeuser@example.com	NOREG
            internal-ipv6	profile	  sip:mod_sofia@[2408:8214:2a1d:2db1:76d4:35ff:fed9:207d]:5060	RUNNING (0)
                 internal	profile	           sip:mod_sofia@192.168.0.53:5060	RUNNING (0)
=================================================================================================
4 profiles 1 alias

具体操作

服务器A

在服务器A上想要拨通B,B相对于A来说就是外地用户,因此我们需要在号码前加拨0加以区别。

修改Dialplan, 添加一个可以匹配分机以0开头的匹配项。我们修改conf/dialplan/default.xml,添加内容如下

xml 复制代码
<extension name="B">
  <condition field="destination_number" expression="^0(.*)$">
     <action application="bridge" data="sofia/external/sip:$1@192.168.0.53:5080"/>
  </condition>
</extension>

在服务器A修改完上述配置后,FreeSWITCH需要重新扫描一下配置,让配置生效.执行以下命令sofia profile internal rescan

sh 复制代码
freeswitch@debianh61> sofia profile internal rescan 
Reload XML [Success]
+OK scan complete

该xml匹配0开头的号码,当匹配后会从本机的external profile出去向B的5080端口发起呼叫。B在收到呼叫请求后会走public profile,根据被叫号码匹配进行transfer。

测试

注册分机

在服务器A上我们注册一个分机1001

在服务器B上我们注册一个分机1000

呼叫

1001上呼叫01000,这里对外呼叫我们加拨了一个0

可以看到呼叫能正常接听

同理要在B上呼通A上的分机的话也做类似的配置就可以。

查看

查看服务器A的日志,我们可以看到有通话往外送

查看服务器B的日志,我们看到收到来自A的通话

相关推荐
Lee川5 小时前
LangChain 加持:后端 AI 流式对话的优雅实现
后端
子兮曰7 小时前
Bun v1.3.14 深度解析:Image API、HTTP/3、全局虚拟存储与五十项变革
前端·后端·bun
ltl7 小时前
Self-Attention:让序列自己看自己
后端
楼兰公子7 小时前
buildroot 在编译rust时裁剪平台类型数量的方法
开发语言·后端·rust
吴声子夜歌7 小时前
Go——并发编程
开发语言·后端·golang
释怀°Believe7 小时前
Spring解析
java·后端·spring
Cosolar8 小时前
大模型应用开发面试 • 每日三题|Day 003|多Agent系统中的通信协议、冲突解决和一致性保障
人工智能·后端·面试
汪汪大队u8 小时前
续:从 Docker Compose 到 Kubernetes(2)—— 服务优化与排错
网络·后端·物联网·struts·容器
无风听海9 小时前
MapStaticAssets()深度解析:ASP.NET Core 静态资源交付的现代范式
后端·asp.net
geovindu10 小时前
go: Lock/Mutex Pattern
开发语言·后端·设计模式·golang·互斥锁模式