目录
1. 安装freeswitch
├── 1.1 相关地址
├── 1.2 安装基础包
├── 1.3 安装依赖包
├── 1.4 代码依赖包
├── 1.5 编译
├── 1.6 安装声音文件
├── 1.7 新版本安装 上面的安装依赖包不用git到工程文件夹
├── 1.8 设置链接符号,便于使用
├── 1.9 部署成服务
├── 1.10 配置文件
│ ├── 1.10.1 添加H263
~H264
1.7版本
│ └── 1.10.2 添加授权注册 需要编译mod_xml_curl
└── 1.11 相关命令
2. 错误解决
├── 2.1 freeswitch.service start request repeated too quickly, refusing to start
├── 2.2 fs_cli
连接不上
├── 2.3 mod_xml_curl.c:459 Binding has no url!
├──2.4. 呼叫慢
└──2.5. 重启后出错
3. 拨号计划
├── 3.1 相关文档
├── 3.2 安装mod_curl
和mod_flite
│ ├──3.2.1 配置modules.conf
│ ├──3.2.2 安装libflite-devel
│ ├──3.2.3 重新编译
│ └──3.2.4 配置modules.conf.xml
├── 3.3 构建拨号计划00_fsm.xml
│ └──3.3.1 MSB
配置
├── 3.4 拨号计划参数
├── 3.5 拨号记录CDR
│ └──3.5.1 采用mod_odbc_cdr
模块
│ │ ├──3.5.1.1 配置modules.conf
│ │ ├──3.5.1.2 编译安装
│ │ ├──3.5.1.3 配置modules.conf.xml
│ │ ├──3.5.1.4 配置odbc_cdr.conf.xml
│ │ └──3.5.1.5 生成表
└── 3.4 拨号计划参数
5. freeswitch
端口
├── 5.1 基本端口
└── 5.2 rtp
端口范围
1. 安装freeswitch
1.1 相关地址
1.2 安装基础包
$ sudo yum install epel-release vim -y
$ curl -O http://files.freeswitch.org/freeswitch-releases/freeswitch-1.6.6.tar.bz2
$ sudo yum install bzip2 -y
$ tar xvjf freeswitch-1.6.6.tar.bz2
1.3 安装依赖包
$ sudo yum install gcc-c++ sqlite-devel zlib-devel libcurl-devel pcre-devel speex-devel ldns-devel libedit-devel openssl-devel -y
$ sudo yum install libjpeg-devel lua-devel libsndfile-devel libyuv-devel git libtool -y
1.4 代码依赖包
$ cd freeswitch-1.6.6
$ cd libs/
$ git clone https://freeswitch.org/stash/scm/sd/libyuv.git
$ cd libyuv/
$ make -f linux.mk CXXFLAGS="-fPIC -O2 -fomit-frame-pointer -Iinclude/"
$ sudo make install
$ sudo cp /usr/lib/pkgconfig/libyuv.pc /usr/lib64/pkgconfig/
$ cd ..
$ git clone https://freeswitch.org/stash/scm/sd/libvpx.git
$ cd libvpx/
$ sudo yum install yasm -y
$ ./configure --enable-pic --disable-static --enable-shared
$ make
$ sudo make install
$ sudo cp /usr/local/lib/pkgconfig/vpx.pc /usr/lib64/pkgconfig/
$ cd ..
$ git clone https://freeswitch.org/stash/scm/sd/opus.git
$ cd opus/
$ ./autogen.sh
$ ./configure
$ make
$ sudo make install
$ sudo cp /usr/local/lib/pkgconfig/opus.pc /usr/lib64/pkgconfig
$ cd ..
$ git clone https://freeswitch.org/stash/scm/sd/libpng.git
$ cd libpng/
$ ./configure
$ make
$ sudo make install
$ sudo cp /usr/local/lib/pkgconfig/libpng* /usr/lib64/pkgconfig/
1.5 编译
$ cd freeswitch-1.6.6
$ ./configure
$ make
$ sudo make install
1.6 安装声音文件
$ sudo make cd-sounds-install
$ sudo make cd-moh-install
1.7 新版本安装 上面的安装依赖包不用git到工程文件夹
$ git clone https://freeswitch.org/stash/scm/fs/freeswitch.git
$ cd freeswitch
$ sh support-d/prereq.sh
$ sh bootstrap.sh
$ ./configure --prefix=/usr/local/freeswitch
$ make
$ sudo make install
1.8 设置链接符号,便于使用
$ sudo ln -sf /usr/local/freeswitch/bin/freeswitch /usr/local/bin/
$ sudo ln -sf /usr/local/freeswitch/bin/fs_cli /usr/local/bin/
1.9 部署成服务
sudo vim /usr/lib/systemd/system/freeswitch.service
[Unit]
Description=freeswitch
After=syslog.target
After=network.target
[Service]
Type=simple
User=root
Group=root
WorkingDirectory=/home/mintcode
ExecStart=/usr/local/freeswitch/bin/freeswitch
ExecStop=/usr/local/freeswitch/bin/freeswitch -stop
Restart=always
[Install]
WantedBy=multi-user.target
1.10 配置文件
-
conf\sip_profiles\internal.xml
配置sip信息
1.10.1 添加H263
~H264
1.7版本
-
$ sudo vim /usr/local/freeswitch/etc/freeswitch/autoload_configs/modules.conf.xml
的<load module="mod_h26x"/>
去掉注释 $ sudo vim /usr/local/freeswitch/etc/freeswitch/vars.xml
<X-PRE-PROCESS cmd="set" data="global_codec_prefs=OPUS,G722,PCMU,PCMA,VP8,VP9,H263,H263-1998,H263-2000,H264"/>
<X-PRE-PROCESS cmd="set" data="outbound_codec_prefs=OPUS,G722,PCMU,PCMA,VP8,VP9,H263,H263-1998,H263-2000,H264"/>
1.10.2 添加授权注册 需要编译mod_xml_curl
-
$ sudo vim /usr/local/freeswitch/etc/freeswitch/autoload_configs/modules.conf.xml
的<load module="mod_xml_curl"/>
去掉注释 $ sudo vim /usr/local/freeswitch/etc/freeswitch/autoload_configs/xml_curl.conf.xml
<binding name="directory">
<param name="gateway-url" value="http://192.168.1.173:20501/freeswitch/dicectory" bindings="directory"/>
</binding>
-
MSB
配置
<?xml version="1.0" encoding="UTF-8" ?>
<routes xmlns="http://camel.apache.org/schema/spring">
<route>
<from uri="netty4-http:http://{{msb.hostName}}:20501/freeswitch/dicectory"
/>
<setHeader headerName="dial-string">
<constant>
{presence_id=${dialed_user}@${dialed_domain}}${sofia_contact(${dialed_user}@${dialed_domain})}
</constant>
</setHeader>
<setHeader headerName="user">
<javaScript>
decodeURIComponent(request.headers.get('user'))
</javaScript>
</setHeader>
<transform>
<simple>
<![CDATA[ <document type="freeswitch/xml">
<section name="${header.section}">
<domain name="${header.domain}">
<params>
<param name="dial-string" value="${header.dial-string}"/></params>
<groups>
<group name="default">
<users>
<user id="${header.user}">
<params><param name="password" value="1234"/></params>
</user>
</users>
</group>
</groups>
</domain></section></document>
]]>
</simple>
</transform>
<removeHeaders pattern="*" />
<setHeader headerName="Content-Type">
<simple>
text/xml
</simple>
</setHeader>
</route>
</routes>
1.11 相关命令
- 显示哪些用户已注册
sofia status profile internal reg
- 控制台显示
info
级别日志fs_cli -l info
2. 错误解决
2.1 freeswitch.service start request repeated too quickly, refusing to start
#去掉下面的配置项
WorkingDirectory=/home/mintcode
2.2 fs_cli
连接不上
sudo vim /usr/local/freeswitch/etc/freeswitch/autoload_configs/event_socket.conf.xml
<configuration name="event_socket.conf" description="Socket Client">
<settings>
<!-- Allow socket connections from any host -->
<param name="listen-ip" value="127.0.0.1"/>
<param name="listen-port" value="8021"/>
<param name="password" value="ClueCon"/>
</settings>
</configuration>
2.3 2016-03-08 14:29:50.925294 [ERR] mod_xml_curl.c:459 Binding has no url!
sudo vim /usr/local/freeswitch/etc/freeswitch/autoload_configs/xml_curl.conf.xml
<configuration name="xml_curl.conf" description="cURL XML Gateway">
<bindings>
<binding name="example">
<!-- Allow to bind on a particular IP for requests sent -->
<!--<param name="bind-local" value="$${local_ip_v4}" />-->
<!-- The url to a gateway cgi that can generate xml similar to
what's in this file only on-the-fly (leave it commented if you dont
need it) -->
<!-- one or more |-delim of configuration|directory|dialplan -->
<!-- <param name="gateway-url" value="http://www.freeswitch.org/gateway.xml" bindings="dialplan"/> -->
<!-- set this to provide authentication credentials to the server -->
<!--<param name="gateway-credentials" value="muser:mypass"/>-->
<!--<param name="auth-scheme" value="basic"/>-->
<!-- optional: this will enable the CA root certificate check by libcurl to
verify that the certificate was issued by a major Certificate Authority.
note: default value is disabled. only enable if you want this! -->
<!--<param name="enable-cacert-check" value="true"/>-->
<!-- optional: verify that the server is actually the one listed in the cert -->
<!-- <param name="enable-ssl-verifyhost" value="true"/> -->
<!-- optional: these options can be used to specify custom SSL certificates
to use for HTTPS communications. Either use both options or neither.
Specify your public key with 'ssl-cert-path' and the private key with
'ssl-key-path'. If your private key has a password, specify it with
'ssl-key-password'. -->
<!-- <param name="ssl-cert-path" value="$${certs_dir}/public_key.pem"/> -->
<!-- <param name="ssl-key-path" value="$${certs_dir}/private_key.pem"/> -->
<!-- <param name="ssl-key-password" value="MyPrivateKeyPassword"/> -->
<!-- optional timeout -->
<!-- <param name="timeout" value="10"/> -->
<!-- optional: use a custom CA certificate in PEM format to verify the peer
with. This is useful if you are acting as your own certificate authority.
note: only makes sense if used in combination with "enable-cacert-check." -->
<!-- <param name="ssl-cacert-file" value="$${certs_dir}/cacert.pem"/> -->
<!-- optional: specify the SSL version to force HTTPS to use. Valid options are
"SSLv3" and "TLSv1". Otherwise libcurl will auto-negotiate the version. -->
<!-- <param name="ssl-version" value="TLSv1"/> -->
<!-- optional: enables cookies and stores them in the specified file. -->
<!-- <param name="cookie-file" value="$${temp_dir}/cookie-mod_xml_curl.txt"/> -->
<!-- one or more of these imply you want to pick the exact variables that are transmitted -->
<!--<param name="enable-post-var" value="Unique-ID"/>-->
</binding>
<binding name="directory">
<param name="gateway-url" value="http://192.168.1.173:20501/freeswitch/dicectory" bindings="directory"/>
</binding>
</bindings>
</configuration>
2.4. 呼叫慢
sudo vim /usr/local/freeswitch/etc/freeswitch/dialplan/default.xml
<condition field="${default_password}" expression="^1234$" break="never">
<action application="log" data="CRIT WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING "/>
<action application="log" data="CRIT Open $${conf_dir}/vars.xml and change the default_password."/>
<action application="log" data="CRIT Once changed type 'reloadxml' at the console."/>
<action application="log" data="CRIT WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING "/>
<action application="sleep" data="3000"/>
</condition>
2.5 重启后 failure to connect to CORE_DB
答案地址:http://comments.gmane.org/gmane.comp.telephony.freeswitch.user/72474
rm /usr/local/freeswitch/var/lib/freeswitch/db/core.db
3. 拨号计划
3.1 相关文档
- XML Dialplan
- 认识拨号计划 - Dialplan
- FreeSWITCH中的XML拨号计划
- 拨号计划
curl
- 通话记录地址
/usr/local/freeswitch/var/log/freeswitch/cdr-csv/Master.csv
3.2 安装mod_curl
和mod_flite
3.2.1 配置modules.conf
sudo vim /home/mintcode/freeswitch/modules.conf
applications/mod_curl
asr_tts/mod_flite
3.2.2 安装libflite-devel
$ cd libs/
$ git clone https://freeswitch.org/stash/scm/sd/libflite.git
$ cd libflite/
$ ./configure --enable-pic --disable-static --enable-shared && make
$ sudo make install
$ sudo cp /usr/local/lib/pkgconfig/flite.pc /usr/lib64/pkgconfig
3.2.3 重新编译
$ cd /home/mintcode/freeswitch
$ ./configure --prefix=/usr/local/freeswitch
$ make
$ sudo make install
3.2.4 配置modules.conf.xml
sudo vim /usr/local/freeswitch/etc/freeswitch/autoload_configs/modules.conf.xml
<load module="mod_curl"/>
<load module="mod_flite"/>
3.3 构建拨号计划00_fsm.xml
sudo vim /usr/local/freeswitch/etc/freeswitch/dialplan/public/00_fsm.xml
-
continue
默认把它设置为false,设为true表示FS在当前分机号的所有action都解析成功是否继续。 -
break
表示判断后的行为,有以下值:
On-true:第一次匹配后停止查找 <br />
On-false:默认值,第一次失败后停止查找 <br />
Always:不管匹配与否都停止 <br />
Never: 无论匹配与否都继续查找 <br />
<include>
<extension name="public_fsm">
<condition field="${channel_name}" expression="@([^@]*)$" break="never" >
<action application="set" data="domain_name=$1"/>
</condition>
<condition field="destination_number" expression="^fsm" break="never">
<action application="set" data="continue_on_fail=true"/>
<action application="curl" data="http://192.168.1.173:20500/savefsinfo/test post caller_id_name=${caller_id_name}&destination_number=${destination_number}"/>
<action application="log" data="${curl_response_data}" />
<action application="sleep" data="3000"/>
<action application="bridge" data="user/${destination_number}@${domain_name}"/>
<!--
<action application="answer"/>
<action application="sleep" data="1000"/>
-->
<!-- speak words -->
<!--
<action application="set" data="tts_engine=flite"/>
<action application="set" data="tts_voice=slt"/>
<action application="speak" data="Jingle bells Jingle bells jingle all the way"/>
-->
<!-- call api http://192.168.1.173:2015/ -->
<!--
<action application="curl" data="http://192.168.1.173:20500/savefsinfo/test post caller_id_name=${caller_id_name}&destination_number=${destination_number}&case=${last_bridge_hangup_cause}"/>
<action application="log" data="${curl_response_data}" />
-->
</condition>
<condition field="${default_password}" expression="^1234$" break="never">
<action application="sleep" data="1000"/> -->
<action application="bridge" data="user/${destination_number}@${domain_name}"/>
</condition>
</extension>
</include>
3.3.1 MSB
配置
<?xml version="1.0" encoding="UTF-8" ?>
<routes xmlns="http://camel.apache.org/schema/spring">
<route>
<from uri="netty4-http:http://{{msb.hostName}}:{{restful.port}}/savefsinfo/{routerId}?httpMethodRestrict=POST"
/>
<convertBodyTo type="java.lang.String" />
<setHeader headerName="CamelRedis.Key">
<simple>
fs:${header.routerId}
</simple>
</setHeader>
<setHeader headerName="CamelRedis.Value">
<javaScript>
var result={ 'appName': 'launchr', 'appToken':'verify-code' }; request.body.split('&').forEach(function(a){var
key=a.split('=');result[key[0]]=key[1]}); result.case=result.case||'USER_NOT_REGISTERED';
result.userName=result.caller_id_name; result.to=[result.destination_number];
request.body=JSON.stringify(result);
</javaScript>
</setHeader>
<to uri="spring-redis://{{redis.hostName}}:{{redis.port}}?command=SET&serializer=#redisSerializer"
/>
<removeHeaders pattern="*" />
<setHeader headerName="Content-Type">
<constant>
application/json
</constant>
</setHeader>
<setHeader headerName="CamelHttpMethod">
<constant>
POST
</constant>
</setHeader>
<to uri="netty4-http:http://192.168.1.251:20001/launchr/chat/voip" />
</route>
</routes>
3.4 拨号计划参数
变量名称 | 描述 |
---|---|
caller_id_name | 呼叫方的名称 |
destination_number | 呼叫方所拨打的号码 |
direction | 当前呼叫段是入站inbound 或出站outbound
|
channel_name | 此调用的入站通道的名称,例如:sofia/sales/John_Smith@192.168.1.1
|
state | 状态,例如CS_EXECUTE 或CS_HANGUP
|
bridge_hangup_cause | 呼叫结束原因,例如NO_ANSWER 或NORMAL_CLEARING 、USER_BUSY
|
last_bridge_hangup_cause | 最后呼叫结束的原因 |
动作 | 描述 |
---|---|
answer | 应答呼叫 |
bridge | 桥叫到另一会话 |
log | 日志文件中写入一条消息 |
hangup | 断开呼叫 |
playback | 播放音频文件或音流 |
set | 通道设置变量 |
transfer | 转移呼叫到另一个会话 |
3.5 拨号记录CDR
3.5.1 采用mod_odbc_cdr
模块
3.5.1.1 配置modules.conf
sudo vim /home/mintcode/freeswitch/modules.conf
event_handlers/mod_cdr_sql
event_handlers/mod_json_cdr
3.5.1.2 编译安装
$ sudo yum install unixODBC mysql-connector-odbc -y
$ sudo make mod_odbc_cdr
$ sudo make mod_odbc_cdr-install
$ sudo cp /home/mintcode/freeswitch/src/mod/event_handlers/mod_odbc_cdr/conf/autoload_configs/odbc_cdr.conf.xml /usr/local/freeswitch/etc/freeswitch/autoload_configs/.
$ sudo make mod_json_cdr
$ sudo make mod_json_cdr-install
$ sudo cp /home/mintcode/freeswitch/src/mod/event_handlers/mod_json_cdr/conf/autoload_configs/json_cdr.conf.xml /usr/local/freeswitch/etc/freeswitch/autoload_configs/.
3.5.1.3 配置modules.conf.xml
sudo vim /usr/local/freeswitch/etc/freeswitch/autoload_configs/modules.conf.xml
<load module="mod_odbc_cdr"/>
<load module="mod_json_cdr"/>
3.5.1.4 配置odbc_cdr.conf.xml
sudo vim /usr/local/freeswitch/etc/freeswitch/autoload_configs/odbc_cdr.conf.xml
<param name="odbc-dsn" value="odbc://DRIVER=mysql;SERVER=192.168.1.249;UID=root;PWD=p@ssw0rd;DATABASE=fs"/>
sudo vim /usr/local/freeswitch/etc/freeswitch/autoload_configs/json_cdr.conf.xml
<param name="url" value="http://192.168.2.92:20001/launchr/chat/voipcdr"/>
3.5.1.5 生成表
CREATE TABLE cdr_table_a_leg (
CallId varchar(50) DEFAULT NULL,
orig_id varchar(50) DEFAULT NULL,
term_id varchar(50) DEFAULT NULL,
ClientId varchar(50) DEFAULT NULL,
IP varchar(50) DEFAULT NULL,
IPInternal varchar(50) DEFAULT NULL,
CODEC varchar(50) DEFAULT NULL,
directGateway varchar(50) DEFAULT NULL,
redirectGateway varchar(50) DEFAULT NULL,
CallerID varchar(50) DEFAULT NULL,
TelNumber varchar(50) DEFAULT NULL,
TelNumberFull varchar(50) DEFAULT NULL,
sip_endpoint_disposition varchar(50) DEFAULT NULL,
sip_current_application varchar(50) DEFAULT NULL
);
CREATE TABLE cdr_table_b_leg (
CallId varchar(50) DEFAULT NULL,
orig_id varchar(50) DEFAULT NULL,
term_id varchar(50) DEFAULT NULL,
ClientId varchar(50) DEFAULT NULL,
IP varchar(50) DEFAULT NULL,
IPInternal varchar(50) DEFAULT NULL,
CODEC varchar(50) DEFAULT NULL,
directGateway varchar(50) DEFAULT NULL,
redirectGateway varchar(50) DEFAULT NULL,
CallerID varchar(50) DEFAULT NULL,
TelNumber varchar(50) DEFAULT NULL,
TelNumberFull varchar(50) DEFAULT NULL,
sip_endpoint_disposition varchar(50) DEFAULT NULL,
sip_current_application varchar(50) DEFAULT NULL
);
CREATE TABLE cdr_table_both (
CallId varchar(50) DEFAULT NULL,
orig_id varchar(50) DEFAULT NULL,
TEST_id varchar(50) DEFAULT NULL
);
4. 配置wss
实现webrtc
5. freeswitch
端口
5.1 基本端口
FireWall Ports Network Protocol Application Protocol Description
1719 UDP H.323 Gatekeeper RAS port
1720 TCP H.323 Call Signaling
3478 UDP STUN service Used for NAT traversal
3479 UDP STUN service Used for NAT traversal
5002 TCP MLP protocol server
5003 UDP Neighborhood service
5060 UDP & TCP SIP UAS Used for SIP signaling (Standard SIP Port, for default Internal Profile)
5070 UDP & TCP SIP UAS Used for SIP signaling (For default "NAT" Profile)
5080 UDP & TCP SIP UAS Used for SIP signaling (For default "External" Profile)
8021 TCP ESL Used for mod_event_socket *
16384-32768 UDP RTP/ RTCP multimedia streaming Used for audio/video data in SIP and other protocols
5066 TCP Websocket Used for WebRTC
7443 TCP Websocket Used for WebRTC
5.2 rtp
端口范围
conf/autoload_configs/switch.conf.xml
<param name="rtp-start-port" value="16384"/>
<param name="rtp-end-port" value="16389"/>
网友评论
sh support-d/prereq.sh
我查看这个脚本并没有去下载安装 1.4 代码依赖包 呢
UNAME=`uname`
NEEDED_PACKAGES_YUM='automake autoconf libtool screen gdb gcc-c++ compat-gcc-32 compat-gcc-32-c++ subversion ncurses-devel unixODBC-devel make wget'
NEEDED_PACAKGES_APT='automake autoconf libtool screen gdb libncurses5-dev unixodbc-dev subversion emacs22-nox gcc g++ make libjpeg-dev'
NEEDED_PACKAGES_PKG_ADD=''
echo ${UNAME} | grep "Linux" && GETTER='wget -c'
echo ${UNAME} | grep "BSD" && GETTER='fetch'
which apt-get >> /dev/null && INSTALLER='apt-get -y install' && NEEDED_PACKAGES=$NEEDED_PACAKGES_APT
which yum >> /dev/null && INSTALLER='yum -y install' && NEEDED_PACKAGES=$NEEDED_PACKAGES_YUM
which pkg_add >> /dev/null && INSTALLER='pkg_add -r' && NEEDED_PACKAGES=$NEEDED_PACKAGES_PKG_ADD
#echo $GETTER and $INSTALLER
#echo ${INSTALLER} ${NEEDED_PACKAGES}
${INSTALLER} ${NEEDED_PACKAGES}
```