tryit-jssip 的本地部署

1. tryit-jssip 本地部署

1.1. sip代理服务器

tryit-jssip后端需要sip代理服务器。

jssip所测试过的sip代理服务器

使用 resiprocate 的 repro 作为sip代理服务器。

1.1.1. 下载并编译resiprocate

git clone https://github.com/resiprocate/resiprocate.git
git checkout -b 1.12.0 resiprocate-1.12.0
autoreconf --install
./configure --with-popt --with-mysql --with-ssl --with-repro --enable-dtls --enable-ipv6 --enable-shared=no CXXFLAGS="-I/mnt/resiprocate/contrib/cajun/include/"

1.1.2. 修改repro配置,同时启用ws和wss

关于 repro 如何配置以支持wss的资料较少,以下配置通过ip方式测试可行,但仍然存在问题

修改 resiprocate/repro/repro.config

diff --git a/repro/repro.config b/repro/repro.config
index bfb68c782..5358fd981 100644
--- a/repro/repro.config
+++ b/repro/repro.config
@@ -232,6 +232,19 @@ TlsDHParamsFilename = dh2048.pem
 # Transport6TlsClientVerification = None
 # Transport6RecordRouteUri = sip:h1.sipdomain.com;transport=WS
 
+# WS transport config
+ Transport1Interface = 10.18.0.200:6060
+ Transport1Type = WS
+ Transport1RecordRouteUri = auto
+# WSS transport config
+ Transport2Interface = 10.18.0.200:10443
+ Transport2Type = WSS
+ Transport2TlsDomain = sip-wss-server.repro.localhost
+ Transport2TlsClientVerification = None
+ Transport2RecordRouteUri = sip:repro.localhost;transport=ws
+ Transport2TlsCertificate = /mnt/resiprocate/resip/certs/domain_cert_sip-wss-server.repro.localhost.pem
+ Transport2TlsPrivateKey = /mnt/resiprocate/resip/certs/domain_key_sip-wss-server.repro.localhost.pem
+
 # Comma separated list of DNS servers, overrides default OS detected list (leave blank 
 # for default)
 DNSServers =
@@ -244,14 +257,14 @@ DisableIPv4 = false
 
 # Comma separated list of IP addresses used for binding the HTTP configuration interface
 # and/or certificate server. If left blank it will bind to all adapters.
-HttpBindAddress = 127.0.0.1, ::1
+HttpBindAddress = 10.18.0.200
 
 # Port on which to run the HTTP configuration interface and/or certificate server 
 # 0 to disable (default: 5080)
 HttpPort = 5080
 
 # disable HTTP challenges for web based configuration GUI
-DisableHttpAuth = false
+DisableHttpAuth = true
 
 # Realm to use for HTTP admin interface digest authentication
 HttpAdminRealm = repro
@@ -702,7 +715,7 @@ CongestionManagementTolerance = 200
 # Specify the number of seconds between writes of the stack statistics block to the log files.
 # Specifying 0 will disable the statistics collection entirely.  If disabled the statistics
 # also cannot be retreived using the reprocmd interface.
-StatisticsLogInterval = 3600
+StatisticsLogInterval = 0
 
 # Use MultipleThreads stack processing.
 ThreadedStack = true
@@ -802,7 +815,7 @@ DNSGreylistDuration = 1800000
 # the alternate transport specification mechanism and defining a RecordRouteUri per
 # transport: TransportXRecordRouteUri
 # WebSocket / WebRTC users: it is usually necessary to set this to false
-DisableOutbound = true
+DisableOutbound = false
 
 # Set the draft version of outbound to support (default: RFC5626)
 # Other accepted values are the versions of the IETF drafts, before RFC5626 was issued
@@ -835,7 +848,7 @@ AssumeFirstHopSupportsFlowTokens = false
 # the alternate transport specification mechanism and defining a RecordRouteUri per
 # transport: TransportXRecordRouteUri
 # WebSocket / WebRTC users: it is usually necessary to set this to true
-EnableFlowTokens = false
+EnableFlowTokens = true
 
 # If EnableFlowTokens is enabled, then by default flow tokens are only used for inbound
 # Record-Routes if the client is directly connected (ie: has only a single Via header).  If you

参考资料:

基于resip 的WSS调试(踩坑记)

Configuring repro for WebRTC

resiprocate - WebRTC and SIP Over WebSockets

1.1.2.1. 启用wss需要的证书

参考 resiprocate/resip/certs/ 中的说明,直接利用其提供的脚本程序生成私钥和公钥

./makeCA
./makeCert sip-wss-server.repro.localhost 3650

之后将生成私钥 domain_key_sip-wss-server.repro.localhost.pem 和 证书 domain_cert_sip-wss-server.repro.localhost.pem

1.1.3. 添加domain和user

这里添加的用户在后续网页注册sip代理时需要用到。

  1. 启动 repro 后,通过 web 页面添加 domain ,10.18.0.200。
  2. 通过 web 页面添加 users ,test1/123456、test2/123456。
  3. 重启 repro

1.2. tryit-jssip部署

node环境:

npm@9.7.1 (/root/.nvm/versions/node/v18.16.0/lib/node_modules/cnpm/node_modules/npm/index.js)
node@18.16.0 (/root/.nvm/versions/node/v18.16.0/bin/node)
npminstall@7.9.0 (/root/.nvm/versions/node/v18.16.0/lib/node_modules/cnpm/node_modules/npminstall/lib/index.js)
prefix=/root/.nvm/versions/node/v18.16.0 

1.2.1. 下载tryit-jssip

git clone https://github.com/versatica/tryit-jssip.git
git checkout -b v1.0.3 1.0.3

1.2.2. 依赖包安装

参考资料

tryit-jssip - github

Issues with libraries using an outdated vinyl version #288

由于这个仓库长期停止维护,有些依赖包已经发生变更,再加上国内网络环境影响。

修改 package.json

diff --git a/package.json b/package.json
index 70f7924..5da52ad 100644
--- a/package.json
+++ b/package.json
@@ -20,9 +20,10 @@
     "react-addons-css-transition-group": "^15.4.0",
     "react-copy-to-clipboard": "^4.2.3",
     "react-dom": "^15.4.0",
-    "react-notification-system": "ibc/react-notification-system#master",
+    "react-notification-system": "^0.4.0",
     "react-tap-event-plugin": "^2.0.1",
-    "url-parse": "^1.1.7"
+    "url-parse": "^1.1.7",
+    "vinyl": "^3.0.0"
   },
   "devDependencies": {
     "babel-plugin-transform-object-assign": "^6.8.0",
@@ -37,7 +38,7 @@
     "eslint": "^3.10.2",
     "eslint-plugin-import": "^2.2.0",
     "eslint-plugin-react": "6.2.1",
-    "gulp": "git://github.com/gulpjs/gulp.git#4.0",
+    "gulp": "^4.0.2",
     "gulp-css-base64": "^1.3.4",
     "gulp-eslint": "^3.0.1",
     "gulp-header": "^1.8.8",
@@ -52,7 +53,7 @@
     "ncp": "^2.0.0",
     "nib": "^1.1.2",
     "vinyl-buffer": "^1.0.0",
-    "vinyl-source-stream": "^1.1.0",
+    "vinyl-source-stream": "^2.0.0",
     "watchify": "^3.7.0"
   }
 }

npm install

安装gulp-cli,这个工具用来启动项目。

npm install -g gulp-cli

1.2.3. https + wss

1.2.3.1. 私钥和证书一致

tryit-jssip/gulpfile.js 中默认使用的https页面,其中带有密钥和自颁发的证书,具体位置位于 tryit-jssip/node_modules/browser-sync/certs/, 而以上的 repro 也有使用到自己的密钥和证书,两者是不一致的,会导致后续注册到 repro 出现证书认证错误而注册失败!

因此需要将之前 repro 生成的私钥和公钥拷贝到 tryit-jssip 项目中。使得 https 和 wss 使用的同一密钥和自签名的证书

cp -p /mnt/resiprocate/resip/certs/domain_key_sip-wss-server.repro.localhost.pem /mnt/tryit-jssip/node_modules/browser-sync/certs/server.key
cp -p /mnt/resiprocate/resip/certs/domain_cert_sip-wss-server.repro.localhost.pem /mnt/tryit-jssip/node_modules/browser-sync/certs/server.crt

1.2.3.2. 启动项目

gulp live

出现以下信息表示项目成功启动

[11:03:54] Finished 'live' after 3.8 s
[Browsersync] Access URLs:
 -------------------------------------
       Local: https://localhost:3000
    External: https://10.18.0.200:3000
 -------------------------------------
          UI: http://localhost:3001
 UI External: http://localhost:3001
 -------------------------------------
[Browsersync] Serving files from: out
[Browsersync] Watching files...
[Browsersync] Couldn't open browser (if you are using BrowserSync in a headless environment, you might want to set the open option to false)

1.2.3.3. 页面配置

打开 https://10.18.0.200:3000,配置sip用户代理和服务器。

  • SIP URI: sip:test1@10.18.0.200
  • SIP password: 123456
  • WebSocket URI: wss://10.18.0.200:10443
  • 其他默认即可

1.2.4. http + ws

1.2.4.1. 修改启动配置,以http方式启动项目

修改 tryit-jssip/gulpfile.js

diff --git a/gulpfile.js b/gulpfile.js
index 5f859e2..15c2c4f 100644
--- a/gulpfile.js
+++ b/gulpfile.js
@@ -315,7 +315,7 @@ gulp.task('openbrowser', (done) =>
                        {
                                baseDir : OUTPUT_DIR
                        },
-                       https     : true,
+                       https     : false,
                        ghostMode : false,
                    

1.2.4.2. 页面配置

打开 http://10.18.0.200:3000,配置sip用户代理和服务器。

  • SIP URI: sip:test1@10.18.0.200
  • SIP password: 123456
  • WebSocket URI: ws://10.18.0.200:6060
  • 其他默认即可

1.2.4.3. 修改chrome安全设置

呼叫时会提示 TypeError: Cannot read properties of undefined (reading 'getUserMedia')

这是由于采用的http和ws方式,需要修改chrome浏览器的安全设置,打开 chrome://flags/#unsafely-treat-insecure-origin-as-secure,填入 http://10.18.0.200:3000 并启用。

参考:

关于使用通过ip访问网站无法使用多媒体,MediaDevices.getUserMedia()为undefined的解决方案--(亲测可用)。

1.3. 现存问题

1.3.1.

呼叫按钮点击后,要等40多秒的时间才能获取本端sdp的问题

判断应该是获取ice候选地址时造成的长时间延迟,目前通过在配置中删除iceservers可以立即呼叫。

修改 tryit-jssip/lib/settingsManager.js

diff --git a/lib/settingsManager.js b/lib/settingsManager.js
index 0c05636..07c9f9d 100644
--- a/lib/settingsManager.js
+++ b/lib/settingsManager.js
@@ -25,15 +25,6 @@ const DEFAULT_SETTINGS =
        instance_id         : null,
        session_timers      : true,
        use_preloaded_route : false,
-       pcConfig            :
-       {
-               iceServers          :
-               [
-                       {
-                               urls : [ 'stun:stun.l.google.com:19302' ]
-                       }
-               ]
-       },
        callstats           :
        {
                enabled   : false,

其他方法可尝试参考:

_createLocalDescription answer/connect delay greater than 10 seconds

1.3.2.

https+wss方式下呼叫一段时间后断开的问题

在呼叫后 主叫的ACK响应无法送达被叫端,导致被叫一直重传200OK,在session超时后,会话会结束。

初步判断还是 repro 的wss设置尚不完全准确。目前暂时以http+ws方式规避。

posted @ 2023-06-27 16:52  never715  阅读(300)  评论(2编辑  收藏  举报