SRProxy introduction

At present, the communication between WebRTC and SIP is mainly used in enterprise call centers, intra-enterprise communication, telephone conference (PSTN), and intelligent access control. To enable the communication between WebRTC and SIP, two problems must be solved: the signaling layer and the media layer. The two networks use different signaling mechanisms, so the signaling must be converted to complete media negotiation and establish sessions. The media layer should complete the coding conversion, as well as RTP/SRTP conversion and other functions. AnyRTC open source SRProxy gateway solves the protocol conversion between WebRTC and SIP, and works with anyRTC open source ARCall audio and video call Demo to demonstrate how to call the landing through App/Web end. The following describes how to deploy SRProxy gateway. And how to communicate with ARCall to expand, familiar with how to use, can integrate SDK into their own applications, with their own business to do the corresponding scenes.

The call flow

ARCall logic

2. SRProxy forwarding logic

1. What can SRProxy do?

SRProxy is a bridge for service communication between RTC and SIP and a key service for service expansion.

2. ARCall Call process

1) State flow diagram

In the call invitation, the caller can use the [getState] method provided by [LocalInvitation] to query the status of the current call invitation. The called party can query the current call invitation status using the [getState] method of the [RemoteInvitation] object returned by the SDK.

LocalInvitationState

The following figure describes the call invitation status flow diagram related to the calling party:

RemoteInvitationState

The following figure describes the call invitation status flow diagram related to called parties:

2) API sequence diagram

Cancel the sent call invitation

Accept/reject the call invitation

Notes and Restrictions

  • Call invitation content The value contains 8 KB and is in utF-8 format.
  • Call invitation response Set by the called party The character string is 8 KB in UTF-8 format.
  • The channelId of a call invitation can be set only when the call can communicate with the signaling. The channelId must be the same as the signaling SDK. The value contains 64 bytes in utF-8 format.

Creating an application

First, register an account

Go to anyRTC website to register a developer account and create an application

2. Create an application to obtain the AppId

The deployment of freeswitch

A, preparation,

A,

Centos 7.9 is recommended to clean the server otherwise there may be dependency failure or conflicts

Two, firewall

Reference freeswitch firewall: freeswitch.org/confluence/…

[root@localhost ~]# firewall-cmd --permanent --add-port=5060/ TCP # Open SIP port UDP [root@localhost ~]# Firewall-cmd --permanent --add-port=5060/udp # open ws port [root@localhost ~]# firewall-cmd --permanent --add-port=5066/ TCP # Open WSS port [root@localhost ~]# firewall-cmd --permanent --add-port=7443/ TCP # Open RTP port (range) [root@localhost ~]# firewall-cmd --permanent --add-port=16384-32768/udp # make firewall configuration effective [root@localhost ~]# firewall-cmd --reload # [root@localhost ~]# systemctl stop firewalld [root@localhost ~]# systemctl disable firewalldCopy the code

Build environment and FreeSwitch dependency libraries

[root@localhost ~]# yum install -y yum-utils git GCC GCC c++ Automake autoconf libtool libtiff-devel libjpeg-devel openssl-devel vim # add environment variables [root@localhost ~]# vim /etc/profile Export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig [root@localhost ~]# source /etc/profile # download spandsp source code separately [root@localhost ~]# cd /usr/local/src [root@localhost src]# git clone https://github.com/freeswitch/spandsp.git [root@localhost src]# cd  spandsp [root@localhost spandsp]# ./bootstrap.sh [root@localhost spandsp]# ./configure [root@localhost spandsp]# make [root@localhost spandsp]# make install [root@localhost spandsp]# ldconfig # Sofia -sip [root@localhost ~]# CD /usr/local/src [root@localhost SRC]# git clone https://github.com/freeswitch/sofia-sip.git [root@localhost src]# cd sofia-sip [root@localhost sofia-sip]# ./bootstrap.sh -j [root@localhost sofia-sip]# ./configure [root@localhost sofia-sip]# make [root@localhost sofia-sip]# Make install [root@localhost sofia-sip]# ldconfig # libuuid [root@localhost ~]# CD /usr/local/src [root@localhost The SRC] # # wget HTTP: / / https://jaist.dl.sourceforge.net/project/libuuid/libuuid-1.0.3.tar.gz/root @ localhost SRC tar ZXVF. - Gz [root@localhost SRC]# CD libuuID-1.0.3 [root@localhost libuuid-1.0.3]#./configure [root@localhost Libuuid-1.0.3]# make [root@localhost libuuid-1.0.3]# make install cmake 3.8.2 [root@localhost ~]# CD / usr/local/SRC/root @ localhost SRC] # # wget HTTP: / / https://cmake.org/files/v3.8/cmake-3.8.2.tar.gz/root @ localhost SRC tar ZXVF Gz [root@localhost cmake]# CD cmake-3.8.2 [root@localhost cmake-3.8.2]#./bootstrap [root@localhost Cmake-3.8.2]# gmake [root@localhost cmake-3.8.2]# gmake install # [root@localhost ~]# CD /usr/local/src [root@localhost SRC]# git clone https://github.com/signalwire/libks.git [root @ localhost libks] # cmake. # # if uuid mistakes, just recompile libuuid source, [root@localhost libks]# make [root@localhost libks]# make install # Install fs dependency [root@localhost ~] # yum install - y http://files.freeswitch.org/freeswitch-release-1-6.noarch.rpm epel - release # ffmpeg installation needs [root@localhost ~]# rpm --import http://li.nux.ro/download/nux/RPM-GPG-KEY-nux.ro [root@localhost ~]# rpm -Uvh http://li.nux.ro/download/nux/dextop/el7/x86_64/nux-dextop-release-0-1.el7.nux.noarch.rpm # yum install related rely on [root @ localhost ~]# yum install -y alsa-lib-devel bison broadvoice-devel bzip2 curl-devel libdb4-devel e2fsprogs-devel erlang flite-devel g722_1-devel gdbm-devel gnutls-devel ilbc2-devel ldns-devel libcodec2-devel libcurl-devel libedit-devel libidn-devel libmemcached-devel libogg-devel libsilk-devel libsndfile-devel libtheora-devel libuuid-devel libvorbis-devel libxml2-devel lua-devel lzo-devel ncurses-devel net-snmp-devel opus-devel pcre-devel perl perl-ExtUtils-Embed pkgconfig portaudio-devel postgresql-devel python-devel python-devel soundtouch-devel speex-devel sqlite-devel unbound-devel unixODBC-devel which yasm zlib-devel libshout-devel libmpg123-devel lame-devel rpm-build Libx11-devel libyuv-devel swig wget ffmpeg ffmpeg-devel # install python components [root@localhost ~]# curl https://bootstrap.pypa.io/pip/2.7/get-pip.py - the output of the get - PIP - 2.7. Py/root @ localhost ~ # python get - PIP - 2.7 p y # Verify that PIP is installed successfully [root@localhost ~]# PIP --version # PIP Install Python components [root@localhost ~]# PIP install pydub python-ESL pika dbutilsCopy the code

Install FreeSwitch

# download git freeswitch/root @ localhost ~ # git clone - b v1.10 freeswitch # https://github.com/signalwire/freeswitch.git If Github is not connected properly, Can try yards cloud image warehouse (update slow. 1 day)/root @ localhost ~ # git clone - b v1.10 freeswitch # https://gitee.com/mirrors/FreeSWITCH.git [root@localhost ~]# CD freeswitch [root@localhost freeswitch]#./bootstrap.sh -j [root@localhost freeswitch]# vim modules.confCopy the code

Turn comments on or off as needed

formats/mod_shout
languages/mod_python
#event_handlers/mod_cdr_pg_csv
asr_tts/mod_unimrcp
endpoints/mod_rtmp
Copy the code

If you want to use mod_XML_curl

xml_int/mod_xml_curl
Copy the code

Comment modules that are not needed

#applications/mod_av
#applications/mod_signalwire
Copy the code

Compile the installation

/configure --with-python=/usr/bin/python2.7 --with-lua=/usr/bin/lua -- enable-core-pgsqL-support /configure [root@localhost freeswitch]# export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig Mod_cdr_pg_csv -install [root@localhost freeswitch]# make mod_unimrcp-install # [root@localhost freeswitch]# make mod_xml_curl-install [root@localhost freeswitch]# make Cd-sounds-install [root@localhost freeswitch]# make cd-moh-install # freeswitch [root@localhost freeswitch]# make installCopy the code

Additional installation of audio files (English)

[root@localhost freeswitch]# make uhd-sounds-install
[root@localhost freeswitch]# make uhd-moh-install
[root@localhost freeswitch]# make hd-sounds-install
[root@localhost freeswitch]# make hd-moh-install
[root@localhost freeswitch]# make sounds-install
[root@localhost freeswitch]# make moh-install
Copy the code

Establishing a soft connection

[root@localhost freeswitch]# sudo ln -sf /usr/local/freeswitch/bin/freeswitch /usr/local/bin/
[root@localhost freeswitch]# sudo ln -sf /usr/local/freeswitch/bin/fs_cli /usr/local/bin/
Copy the code

Configure the mod

[root@localhost ~]# vim /usr/local/freeswitch/conf/autoload_configs/modules.conf.xml
Copy the code

Open in the first 3 lines (may not be in the right position, can be found)

    <load module="mod_console"/>
    <load module="mod_logfile"/>
    <load module="mod_xml_curl"/>
Copy the code

Open the annotation

    <load module="mod_python"/>
    <load module="mod_shout"/>
Copy the code

Add the configuration

<load module="mod_cdr_pg_csv"/> <load module="mod_unimrcp"/> <! --<load module="mod_vad"/>-->Copy the code

Comment out other modules that are not needed

<! -- <load module="mod_av"/> --> <! -- <load module="mod_signalwire"/> -->Copy the code

If there is no other requirement to deploy Freeswitch to this end

Configure an ACL whitelist

[root@localhost ~]# vim /usr/local/freeswitch/conf/autoload_configs/acl.conf.xml
Copy the code
<! <list name="domains" default="deny"> <! -- domain= is special it scans the domain from the directory to build t$ --> <node type="allow" domain="$${domain}"/> <! - = = = = = = = = = = = = = = = = = = here add native IP 127.0.0.1 = = = = = = = = = = = = = = = = = = = = = = = = -- -- > <! - = = = = = = = = = = = = = = = = = = here add native network IP = = = = = = = = = = = = = = = = = = = = = = = = -- -- > <! - = = = = = = = = = = = = = = = = = = here add this closed network IP = = = = = = = = = = = = = = = = = = = = = = = = -- -- > <! - = = = = = = = = = = = = = = = = = = here add web network IP 192.168.1.221 = = = = = = = = = = = = = = = = = = = = = = = = -- -- > <! - = = = = = = = = = = = = = = = = = = here add web IP networks outside public IP = = = = = = = = = = = = = = = = = = = = = = = = -- -- > <! - = = = = = = = = = = = = = = = = = = here add runcall inside and outside the network Ip = = = = = = = = = = = = = = = = = = = = = = = = -- -- > < node type = "allow" cidr = "192.168.1.0/24" / > < node Type ="allow" cidr=" public IP/32"/> </list>Copy the code
# After saving, in the Freeswitch client, Enter reloadacl reloadxml to reload the ACL file [root@localhost ~]# fs_cli freeswitch@localhost>reloadacl reloadxmlCopy the code

Configuration of ESL

[root@localhost ~]# vim /usr/local/freeswitch/conf/autoload_configs/event_socket.conf.xml
Copy the code
<configuration name="event_socket.conf" description="Socket Client"> <settings> <param name="nat-map" value="false"/> <! - IP unity as 0.0.0.0 - > < param name = "listen - IP" value = "0.0.0.0" / > <! <param name="listen-port" value="8021"/> <! <param name="password" value="Aicyber"/> <! --> <param name="apply-inbound-acl" value="domains"/> <! --<param name="apply-inbound-acl" value="loopback.auto"/>--> <! --<param name="stop-on-bind-error" value="true"/>--> </settings> </configuration>Copy the code

WebRTC (JSSIP/SIPJS)

[root@localhost ~]# vim /usr/local/freeswitch/conf/sip_profiles/internal.xml
Copy the code
<param name="apply-candidate-acl" value="rfc1918.auto"/> <param name="apply-candidate-acl" value="localnet.auto"/> <param name="apply-candidate-acl" value="candidate"/> <! --> <param name="enable-100rel" value="true"/>Copy the code

Dial plan

[root@localhost ~]# vim /usr/local/freeswitch/conf/sip_profiles/internal.xml
Copy the code
<! Public --> <param name="context" value="default"/>Copy the code

Close the ipv6

[root@localhost ~]# cd /usr/local/freeswitch/conf/sip_profiles
[root@localhost sip_profiles]# mv internal-ipv6.xml internal-ipv6.xml.removed
[root@localhost sip_profiles]# mv external-ipv6.xml external-ipv6.xml.removed
Copy the code

4. Configure Sip Proxy forwarding rules

/ root @ localhost ~ # vim/usr/local/freeswitch/conf/dialplan/default XML # # config file to add the following configuration, multiple SRProxy configure multiple Numbers

<extension name="group_dial_sip_proxy"> <condition field="destination_number" expression="^0(.*)$"> <action application="set"><! [CDATA [sip_h_X - Number = "sip: $1 @ ${domain_name} >]] > < / action > < action application =" bridge "data =" user / 1000 @192.168.x.xx "/ > </condition> </extension>Copy the code

If a SIP number is preceded by 0, a call is automatically routed to the number 1000. The 1000 number is the Proxy account configured on SRProxy. In this way, SRProxy can receive Sip outbound call requests and initiate calls from the sender to the RTC.

Note: In the configuration, 192.168.x.x is the real IP address of your machine. If there is a public EIP address, enter a public EIP address. If there is a LAN, enter a LAN IP address.

5. Change the call time of FreeSwitch

After freeswitch is installed, sip calls are received with a delay of about 10 seconds. The reason is that freeswitch has a default delay. You only need to comment out the delay to solve this problem

[root@localhost freeswitch]# vim /usr/local/freeswitch/conf/dialplan/default.xml

<condition field="${default_password}" expression="^1234$" break="never"> <action application="log" data="CRIT WARNING WARNING WARNING WARNING WARNING WARNING WARNI NG WARNING WARNING "/> <action application="log" data="CRIT Open $${conf_dir}/vars.xml and change the default_pas sword."/> <action application="log" data="CRIT Once changed type 'reloadxml' at the console."/> <action application="log" data="CRIT WARNING WARNING WARNING WARNING WARNING WARNING WARNI NG WARNING WARNING "/> <! <action application="sleep" data="10000"/>Copy the code

Start to take effect

FreeSwitch Displays the calling number

[root@localhost freeswitch]# cd /usr/local/freeswitch/conf/directory/default [root@localhost default]# vim 1000.xml

<include> <user id="1000"> <params> <param name="password" value="$${default_password}"/> <param name="vm-password" value="1000"/> </params> <variables> <variable name="toll_allow" value="domestic,international,local"/> <variable name="accountcode" value="1000"/> <variable name="user_context" value="default"/> <! --<variable name="effective_caller_id_name" value="Extension 1000"/>--> --<variable name="effective_caller_id_number" value="1000"/>--> value="$${outbound_caller_name}"/> <variable name="outbound_caller_id_number" value="$${outbound_caller_id}"/> <variable  name="callgroup" value="techsupport"/> </variables> </user> </include>Copy the code

Start to take effect

## Background quick start [root@localhost ~]# freeswitching-nC-nonat ## Console start (exit to shut down service) [root@localhost ~]# freeswitchCopy the code

7. FreeSwitch automatically adds numbers

Freeswitch is an open source call center service. The default number is 1000-1019. If only 20 numbers cannot be configured, you need to add numbers

[root@localhost ~]# vim /usr/local/freeswitch/conf/dialplan/default.xml

<extension name="Local_Extension"> <! --<condition field="destination_number" expression="^(10[01][0-9])$">--> # comment this line or modify this line <condition Field = "destination_number" expression = "^ (1 [0-9] [0-9] [0-9] | 20 [0-9] [0-9]) $" > section of the period of 1000 ~ 2099 # to redefine the number < action application="export" data="dialed_extension=$1"/> <! -- bind_meta_app can have these args <key> [a|b|ab] [a|b|o|s] <app> --> <action application="bind_meta_app" data="1 b s execute_extension::dx XML features"/>Copy the code

[root@localhost ~]# freeswitch.sh

#! /bin/bash # Author: Lzy # data: The 2021-11-16 # # set variables freeswitch storage directory number TARGET_FREESWITCH_PREFIX = / usr/local/freeswitch/conf/directory/default / # While [$I -le 2599] do # I =$I +1 $I =$I +1 $I =1020 +1 let I =$I +1 # cp copy 1000. XML rename $I step +1 cp $TARGET_FREESWITCH_PREFIX/1000. XML $TARGET_FREESWITCH_PREFIX/$i.ml # Sed -i "s/1000/$I /" $TARGET_FREESWITCH_PREFIX/$i.xml done sed -I "s/1000/$I /" $TARGET_FREESWITCH_PREFIX/$i.xml doneCopy the code
[root@localhost ~]# chmod +x freeswitch.sh [root@localhost ~]#./freeswitch.sh # Type reloadxml. XML file [root@localhost ~]# fs_cli freeswitch@localhost>reloadxmlCopy the code

Deploy SRProxy

Source code address: github.com/anyRTC-UseC…

Windows 7 +

Double-click siprTCproxy. SLN to run it directly

VS2017 project is created, VS2015, VS2019 can be verified by themselves.

Linux – Centos7.0 +

Download the code locally

[root@localhost ~]# git clone github.com/anyRTC-UseC…

[root@localhost ~]# cd SipRtcProxy.git

The environment variable

[root@localhost SipRtcProxy]# vim  /etc/profile
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/root/SipRtcProxy/so/
[root@localhost SipRtcProxy]# source /etc/profile
Copy the code

perform

[root@localhost SipRtcProxy]# make

The configuration file

[root@localhost SipRtcProxy]# vim rtx.conf

[global] appId =XXXXX ## appid sip_svr=IP:5060 ## #[RTC] # IP =RTC_IP #port=6080 #[RTM] # IP =RTM_IP #port=7080 [rtm2sip] on=1 0: disabled 1: enabled Acc_rule =1005 10[06-19] ## Number range adjusted according to Freeswitch; Number :1005, 1006-1019 There are 15 numbers in total, which cannot conflict with multiple SRProxy numbers in Appid. [proxy] on=1 ## Whether to enable SIP proxy. 0: disable 1: enable SIP_account =1000 ## freeswitch Agent account :1000, the client cannot conflict with this number. Only one SRProxy number can be used. If you change the environment, change the number, for example, 1001 SIP_PWd =1234 ## freeswitch Password rtm_account=1086 ## When you log in to the RTM account, the client cannot conflict with the RTM number, and only one APPID can be used. You need to change the number when changing the environment, for example, 1087 [log] #* 0:SENSITIVE 1:VERBOSE 2:INFO 3:WARNING 4:ERROR 5:NONE level=2 file=rtc_sip.log max_file_size=100Copy the code

The front desk to start the

[root@localhost SipRtcProxy]# ./SRProxy rtx.conf

Linux-centos 7.0 + compiled

Download address: pan.baidu.com/s/1QhhIsO3N…

Extraction code: L1F2

Create a directory

[root@localhost ~]# mkdir /usr/local/ar4/

[root@localhost ~]# tar zxvf SRProxy.tar.gz

Add srproxy.tar.gz to /usr/local/ar4/and decompress it

[root@localhost ~]# cd /usr/local/ar4/

[root@localhost ar4]# tar zxvf srproxy.tar.gz

Place the rtx.sh script under /usr/bin and grant permissions

[root@localhost ~]# chmod +x /usr/bin/rtx.sh

Enter the directory

[root@localhost ~]# cd /usr/local/ar4/srproxy/ [root@localhost srproxy]# vim conf/rtx.conf

[global] appId =XXXXX ## appid sip_svr=IP:5060 ## #[RTC] # IP =RTC_IP #port=6080 #[RTM] # IP =RTM_IP #port=7080 [rtm2sip] on=1 0: disabled 1: enabled Acc_rule =1005 10[06-19] ## Number range adjusted according to Freeswitch; Number :1005, 1006-1019 There are 15 numbers in total, which cannot conflict with multiple SRProxy numbers in Appid. [proxy] on=1 ## Whether to enable SIP proxy. 0: disable 1: enable SIP_account =1000 ## freeswitch Agent account :1000, the client cannot conflict with this number. Only one SRProxy number can be used. If you change the environment, change the number, for example, 1001 SIP_PWd =1234 ## freeswitch Password rtm_account=1086 ## When you log in to the RTM account, the client cannot conflict with the RTM number, and only one APPID can be used. You need to change the number when changing the environment, for example, 1087 [log] #* 0:SENSITIVE 1:VERBOSE 2:INFO 3:WARNING 4:ERROR 5:NONE level=2 file=rtc_sip.log max_file_size=100Copy the code

Start SRProxy after the configuration is complete

Enter the directory:

[root@localhost ~]# cd /usr/local/ar4/srproxy/

[root@localhost srproxy]# rtx.sh start srproxy #

[root@localhost srproxy]# rtx.sh restart srproxy #

[root@localhost srproxy]# rtx.sh stop srproxy #

Add a task plan for automatic startup

[root@localhost ~]# crontab -e

*/1 * * * * sh /usr/local/ar4/srproxy/moni_srp.sh >/dev/null 2>&1

The Demo presentation

1. Login ARCall (Connect to public RTC and RTM)

ARCall source download address: github.com/anyRTC-UseC…

The AppId must be consistent with the SRProxy configuration file

Login SIP (analog phone connection FreeSwitch)

Download address: www.microsip.org/downloads

The connected Freeswitch must be the same as that configured on SRProxy

To Add an account, click Menu– >Add Account

3. ARCall dials SIP

ARCall Dial SIP using the normal process. Dial the number of the sip number

Note: Dial devices must have a microphone to dial

Call success

4. Sip Dial ARCall

Sip ARCall must be preceded by 0, which depends on the CONFIGURATION of SIP forwarding rules

Note: Dial devices must have a microphone to dial

Call success