Websocket 连接失败并显示星号 11

2024-05-04

我正在尝试将 websocket 配置为与 asterisk 11 一起使用。但是存在一些问题。 我遵循的步骤是: 在 http.conf 中启用以下内容

enabled=yes
bindaddr=0.0.0.0  
bindport=8088   

我还为星号配置了 DTLS 支持。 但是当我尝试连接到 websocket new WebSocket ("ws://mySeverIp:8088/ws"); 。它抛出一个错误

WebSocket connection failed: Error during WebSocket handshake: Unexpected response code: 400  

请任何人帮忙。

Thanks


这是完整的安装指南。如果这可以解决您的问题,请告诉我。 Asterisk 还提供关于此事的维基帖子 https://wiki.asterisk.org/wiki/display/AST/Asterisk+WebRTC+Support

安装 SRTP:

cd ~
git clone https://github.com/cisco/libsrtp.git
cd libsrtp/
autoconf
./configure CFLAGS=-fPIC --prefix=/usr
make
make runtest
sudo make install

安装 PJPROJECT :

cd ~
git clone https://github.com/asterisk/pjproject pjproject
cd pjproject/
./configure --prefix=/usr --enable-shared --disable-sound --disable-resample --disable-video --disable-opencore-amr --with-external-srtp
make
sudo make install

安装 UUID 开发库(Asterisk 12 不需要):

cd ~ 
sudo apt-get install uuid-dev -y (for Debian & ubuntu, libuuid-devel for CentOS)

安装星号 11 :

cd ~
wget http://downloads.asterisk.org/pub/telephony/asterisk/asterisk-11-current.tar.gz
tar -xzf asterisk-11-current.tar.gz

为 SRTP 生成并安装 DTLS 证书:

cd asterisk*/contrib/scripts
sudo mkdir /etc/asterisk/
sudo mkdir /etc/asterisk/keys/

要生成自签名 SSL 证书,请使用以下命令:

### Replace 10.x.x.x by the IP adress of your server. 10.x.x.x is intern, use a public IP if your Asterisk will be exposed over Internet.
sudo ./ast_tls_cert -C 10.x.x.x -O "Your Company" -d /etc/asterisk/keys

在此过程中,系统会要求您选择一个密钥。每次输入同一个键,按一次有效Enter key.

如果您要从证书颁发机构生成 SSL 证书,请使用以下方法:
http://codeghar.wordpress.com/2013/04/16/generate-certificate-signing-request-on-linux/ http://codeghar.wordpress.com/2013/04/16/generate-certificate-signing-request-on-linux/ http://codeghar.wordpress.com/2013/04/16/use-private-certificate-authority-to-sign-certificate-signing-request-on-linux/ http://codeghar.wordpress.com/2013/04/16/use-private-certificate-authority-to-sign-certificate-signing-request-on-linux/

本例中的证书路径为/etc/asterisk/keys/asterisk.pem

安装Asterisk(是的,您需要使用PJPROJECT和LIBSRTP编译Asterisk):

cd ~
cd asterisk*
sudo ./configure --with-pjproject --with-ssl --with-srtp
make menuselect

检查包pbx_realtime, res_odbc, res_http_websocket, res_crypto and chan_sip被激活。为了在 Asterisk 中通过 WS 或 WSS 使用 WebRTC,这是必须具备的。

make
sudo make install
sudo make config
## Recommended demo conf files with : 
sudo make samples
cd ~

激活 WebSocket 和安全 WebSocket/etc/asterisk/http.conf(管理 HTTP Apache Asterisk Web 实例的文件)。如果您使用 Asterisk Realtime (ODBC),那么您必须在每个对等点(行dtlscertfile & dtlsprivatekey在表中sippeers). :

enabled=yes;
bindport=8088;
tlscertfile=/etc/asterisk/keys/asterisk.pem
tlsprivatekey=/etc/asterisk/keys/asterisk.pem

确保文件夹权限良好:(将 AsteriskUser 替换为运行 Asterisk 服务的用户)

sudo chown AsteriskUser. /var/run/asterisk
sudo chown -R AsteriskUser. /etc/asterisk
sudo chown -R AsteriskUser. /var/{lib,log,spool}/asterisk
sudo chown -R AsteriskUser. /usr/lib/asterisk

在 sip.conf 中创建您的 WebRTC 对等点(复制以创建另一个用户):

[1060] ; This will be WebRTC client
type=friend ;
username=1060 ; The Auth user for SIP.js
host=dynamic ; Allows any host to register
secret=password ; The SIP Password for SIP.js
encryption=yes ; Tell Asterisk to use encryption for this peer
avpf=yes ; Tell Asterisk to use AVPF for this peer
icesupport=yes ; Tell Asterisk to use ICE for this peer
context=default ; Tell Asterisk which context to use when this peer is dialing
directmedia=no ; Asterisk will relay media for this peer
transport=udp,ws,wss ; Asterisk will allow this peer to register on UDP or WebSockets
force_avp=yes ; Force Asterisk to use avp. Introduced in Asterisk 11.11
dtlsenable=yes ; Tell Asterisk to enable DTLS for this peer
dtlsverify=no ; Tell Asterisk to not verify your DTLS certs
dtlscertfile=/etc/asterisk/keys/asterisk.pem ; Tell Asterisk where your DTLS cert file is
dtlsprivatekey=/etc/asterisk/keys/asterisk.pem ; Tell Asterisk where your DTLS private key is
dtlssetup=actpass ; Tell Asterisk to use actpass SDP parameter when setting up DTLS

[1061] ; This will be the legacy SIP client
type=friend;
username=1061;
host=dynamic;
secret=password;
context=default;

编辑extensions.conf以允许每个对等点调用:

[default]
exten => 1060,1,Dial(SIP/1060) ; Dialing 1060 will call the SIP client registered to 1060
exten => 1061,1,Dial(SIP/1061) ; Dialing 1061 will call the SIP client registered to 1061

启动星号服务:

sudo service asterisk start

打开所需的端口:

[Ubuntu] :
sudo ufw allow 5060 (or whatever port you have choosen in sip.conf `udpbindaddr=10.x.x.x:5060; tcpbindaddr=10.x.x.x:5060;tlsbindaddr=10.x.x.x:5061`)
sudo ufw allow 5061
sudo ufw allow 8088 (or whatever port you have choosen in http.conf : `bindport=8088`)
sudo ufw allow 8089 (or whatever port you have choosen in http.conf : `tlsbindaddr=10.x.x.x:8089`)
sudo ufw allow 10000:20000/udp (or whatever range you have choosen in rtp.conf : `rtpstart=10000; rtpend=20000`)
[or if you are on Debian] : 
sudo iptables -A INPUT -p tcp --dport 5060 -j ACCEPT
sudo iptables -A INPUT -p tcp --dport 5061 -j ACCEPT
sudo iptables -A INPUT -p tcp --dport 8088 -j ACCEPT
sudo iptables -A INPUT -p tcp --dport 8089 -j ACCEPT
sudo iptables -A INPUT -p tcp --match multiport --dports 10000:20000 -j ACCEPT

重新启动(或启动)服务:sudo service asterisk restart

从另一台机器测试 WebSockets:安装 WSCATsudo apt-get install wscat –y

## If error "connect ECONNREFUSED" it's not OK.
## If Echo service returns your messages, it's OK.
wscat -s echo -c ws://10.x.x.x:8088/ws
## The same command with WSS should work if you've installed WSS.

使用 Javascript 客户端(例如 JsSIP、sipML5、WebRTComm 等)测试通过 WebSocket 的 SIP

使用以下命令访问 SIP 控制台sudo asterisk -vvvvvv -g -dddddd -r进行调试和跟踪。

要对 Asterisk 12 执行相同的操作,只需在 Asterisk 安装中将 Asterisk-11 替换为 Asterisk-12 即可。

在这里,您将找到使用 Realtime、WS、WSS(省略 ODBC conf)的 Asterisk 12 的完整配置文件。我发布它是因为您可能会发现检查安装中是否缺少某些参数很有用:

http.conf

;
; Asterisk Builtin mini-HTTP server
;
[general]
enabled=yes;
bindaddr=10.x.x.x;
bindport=8088;
tlsenable=yes          ; enable tls - default no.
tlsbindaddr=10.x.x.x:8089    ; address and port to bind to - default is bindaddr and port 8089.
tlscertfile=/etc/asterisk/keys/asterisk.pem  ; path to the certificate file (*.pem) only.
tlsprivatekey=/etc/asterisk/keys/asterisk.pem    ; path to private key file (*.pem) only.

extensions.conf(为实时而生!!)

[general]
[globals]
;
[default]
switch =>Realtime

module.conf(为实时而生!!!)

[modules]
autoload=yes
preload => res_odbc.so
preload => res_config_odbc.so
noload => pbx_gtkconsole.so
load => res_musiconhold.so
noload => chan_alsa.so
noload => chan_console.so

extconfig.conf(为实时而设计!!!)

[settings]
sippeers => odbc,YourAsteriskrealtimeDB,sippeers
sipusers => odbc,YourAsteriskrealtimeDB,sippeers
extensions => odbc,YourAsteriskrealtimeDB,extensions
ps_endpoints => odbc,YourAsteriskrealtimeDB,ps_endpoints
ps_auths => odbc,YourAsteriskrealtimeDB,ps_auths

星号.conf

[directories](!)
astetcdir => /etc/asterisk
astmoddir => /usr/lib/asterisk/modules
astvarlibdir => /var/lib/asterisk
astdbdir => /var/lib/asterisk
astkeydir => /var/lib/asterisk
astdatadir => /var/lib/asterisk
astagidir => /var/lib/asterisk/agi-bin
astspooldir => /var/spool/asterisk
astrundir => /var/run/asterisk
astlogdir => /var/log/asterisk
astsbindir => /usr/sbin
[options];
verbose = 3;
debug = 3;
highpriority = yes      ; Run realtime priority (same as -p at startup).
initcrypto = yes        ; Initialize crypto keys (same as -i at startup).
[compat];
pbx_realtime=1.6;
res_agi=1.6;
app_set=1.6;

rtp.conf

;
; RTP Configuration
;
[general];
rtpstart=10000;
rtpend=20000;
icesupport=true;
stunaddr=stun.l.google.com:19302;

sip.conf

;
; SIP Configuration for Asterisk
;
[general] 
context=default ; Default context for incoming calls. Defaults to 'default' 
allowoverlap=no                 ; Disable overlap dialing support. (Default is yes)
realm=YourAsteriskREALM             ; Realm for digest authentication
                                ; defaults to "asterisk". If you set a system name in
                                ; asterisk.conf, it defaults to that system name
                                ; Realms MUST be globally unique according to RFC 3261
                                ; Set this to your host name or domain name

udpbindaddr=10.x.x.x             ; IP address to bind UDP listen socket to (0.0.0.0 binds to all)
                                ; Optionally add a port number, 192.168.1.1:5062 (default is port 5060)
videosupport=yes              ; Turn on support for SIP video. You need to turn this
                                ; on in this section to get any video support at all.
                                ; You can turn it off on a per peer basis if the general
                                ; video support is enabled, but you can't enable it for
                                ; one peer only without enabling in the general section.
                                ; If you set videosupport to "always", then RTP ports will
                                ; always be set up for video, even on clients that don't
                                ; support it.  This assists callfile-derived calls and
                                ; certain transferred calls to use always use video when
                                ; available. [yes|NO|always]
rtsavepath=yes                 ; If using dynamic realtime, store the path headers
send_diversion=no              ; Default "yes"     ; Asterisk normally sends Diversion headers with certain SIP
                                                    ; invites to relay data about forwarded calls. If this option
                                                    ; is disabled, Asterisk won't send Diversion headers unless
                                                    ; they are added manually.
rtpkeepalive=2            ; Send keepalives in the RTP stream to keep NAT open (default is off - zero)(secs)
;--------------------------- SIP DEBUGGING ---------------------------------------------------
sipdebug = yes                 ; Turn on SIP debugging by default, from
                                ; the moment the channel loads this configuration
icesupport = yes;
;----------------------------------------- REALTIME SUPPORT ------------------------
; For additional information on ARA, the Asterisk Realtime Architecture,
; please read https://wiki.asterisk.org/wiki/display/AST/Realtime+Database+Configuration
;
rtcachefriends=yes             ; Cache realtime friends by adding them to the internal list
                                ; just like friends added from the config file only on a
                                ; as-needed basis? (yes|no)

rtsavesysname=yes              ; Save systemname in realtime database at registration
                                ; Default= no

rtupdate=yes                   ; Send registry updates to database using realtime? (yes|no)
                                ; If set to yes, when a SIP UA registers successfully, the ip address,
                                ; the origination port, the registration period, and the username of
                                ; the UA will be set to database via realtime.
                                ; If not present, defaults to 'yes'. Note: realtime peers will
                                ; probably not function across reloads in the way that you expect, if
                                ; you turn this option off.
rtautoclear=yes                ; Auto-Expire friends created on the fly on the same schedule
                                ; as if it had just registered? (yes|no|<seconds>)
                                ; If set to yes, when the registration expires, the friend will
                                ; vanish from the configuration until requested again. If set
                                ; to an integer, friends expire within this number of seconds
                                ; instead of the registration interval.

[authentication]
;
; DTLS-SRTP CONFIGURATION
;
dtlsenable = yes                   ; Enable or disable DTLS-SRTP support
dtlsverify = no                   ; Verify that provided peer certificate and fingerprint are valid
dtlscertfile=/etc/asterisk/keys/asterisk.pem                ; Path to certificate file to present
dtlsprivatekey=/etc/asterisk/keys/asterisk.pem              ; Path to private key for certificate file
dtlssetup = actpass                ; Whether we are willing to accept connections, connect to the other party, or both.

[basic-options](!)                ; a template
        dtmfmode=rfc2833
        context=from-office
        type=friend

[natted-phone](!,basic-options)   ; another template inheriting basic-options
        directmedia=no
        host=dynamic

[public-phone](!,basic-options)   ; another template inheriting basic-options
        directmedia=yes

[my-codecs](!)                    ; a template for my preferred codecs
        disallow=all
        allow=ilbc
        allow=g729
        allow=gsm
        allow=g723
        allow=ulaw

[ulaw-phone](!)                   ; and another one for ulaw-only
        disallow=all
        allow=ulaw

[1060] ; This will be WebRTC client
type=friend
username=1060 ; The Auth user for SIP.js
host=dynamic ; Allows any host to register
secret=password ; The SIP Password for SIP.js
encryption=yes ; Tell Asterisk to use encryption for this peer
avpf=yes ; Tell Asterisk to use AVPF for this peer
icesupport=yes ; Tell Asterisk to use ICE for this peer
context=default ; Tell Asterisk which context to use when this peer is dialing
directmedia=no ; Asterisk will relay media for this peer
transport=udp,ws ; Asterisk will allow this peer to register on UDP or WebSockets
force_avp=yes ; Force Asterisk to use avp. Introduced in Asterisk 11.11
dtlsenable=yes ; Tell Asterisk to enable DTLS for this peer
dtlsverify=no ; Tell Asterisk to not verify your DTLS certs
dtlscertfile=/etc/asterisk/keys/asterisk.pem ; Tell Asterisk where your DTLS cert file is
dtlsprivatekey=/etc/asterisk/keys/asterisk.pem ; Tell Asterisk where your DTLS private key is
dtlssetup=actpass ; Tell Asterisk to use actpass SDP parameter when setting up DTLS

[1061] ; This will be the legacy SIP client
type=friend
username=1061
host=dynamic
secret=password
context=default

res_odbc.conf(仅适用于 Asterisk Realtime!!!)

[YourAsteriskrealtimeDB]
enabled => yes
dsn => your-asterisk-BD-connector-name-as-defined-in-file-odbcinst.ini
username => YourMySQLUser
password => YourMySQLPassword
pre-connect => yes

如果您使用实时,请插入以下通用拨号方案:

INSERT INTO `extensions`    (   `context`,  `exten`,    `priority`,     `app`,  `appdata`   ) VALUES    (   'default',  '_X.',  1,  'Dial',     'SIP/${EXTEN}'  );
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Websocket 连接失败并显示星号 11 的相关文章

随机推荐

  • 从控制器传递 gsp 参数

    我如何通过不是域类实例的控制器将参数传递到groovy服务器页面 您将参数放入返回给 GSP 的模型对象映射中 例如 def index def hobbies basketball photography render view inde
  • 如何在 Django 查询中动态提供查找字段名称? [复制]

    这个问题在这里已经有答案了 我想在 Django 模型的几个字段中查找某个字符串 理想情况下 它会类似于 keyword keyword fields foo bar baz results for field in fields look
  • jQuery 函数在不应该运行的时候运行

    我有一个函数 仅当宽度小于特定值时才需要运行 我已经这样做了if window width lt n 但当宽度大于 n 时 该函数也会运行 The if if window width lt n 由于背景颜色发生变化 浅灰色 1000px
  • VBA - 从 Internet Explorer 的框架通知栏中选择另存为

    我正在尝试通过以下方式下载另存为的文件框架通知栏的互联网浏览器 然而 经过大量搜索后 我只找到了点击解决方案save在框架通知栏上 到目前为止 我一直在尝试另存为示例站点上的文件 http www tvsubtitles net subti
  • Angular 5 webpack 3 aot

    我正在尝试使用 webpack 3 和 Angular 5 进行 aot 构建 但是网上有很多教程 没有一个没有问题地显示完整的示例 到目前为止我已经有了以下配置 对于那些对路径有疑问的人 我在 java 应用程序中使用它 webpack
  • Azure DataCache Windows Azure 模拟器出现问题,但未生成错误。应用程序只是挂起

    我有一个现有的 mvc4 Web 项目 我想将其部署到云服务并开始使用 azure 数据缓存 我已将 Windows azure 缓存 nuget 包添加到解决方案中的两个项目中 即 Web 项目和类库项目 这两个项目都需要这些项目 然后
  • CGContextSaveGState 无效上下文

    我正在开发一个 iOS 应用程序 它使用实时摄像头扫描条形码和二维码 然而有时我会遇到错误 这些错误不会使应用程序崩溃 但修复它们可能是个好主意 这些是错误
  • Firebase 的云功能:序列化 Promise

    在 onWrite 处理程序中 我想执行多次读取 操作一些数据 然后存储它 我对 Promise 概念还很陌生 关于 Firebase 在完成之前不会终止我的查询 我对以下 Promise 处理是否安全 exports test funct
  • 如何通过 JavaScript 设置输入值?

    我有 id txt1 的输入字段 但我无法从 JavaScript 更改该值
  • 根据 VS 活动配置定义 Wix 属性和值

    如何定义根据激活的 Visual Studio 配置而变化的 Wix 属性和值 例如对于我们的发布版本 var x 1 对于导出版本 var x 2 我们使用 wixproj 文件将属性传递到 WiX
  • 在 Fragment 和 Activity 之外通过 Hilt 进行现场注入

    我想知道是否可以在片段或活动之外使用字段注入 我知道我可以使用构造函数注入 但是我想知道是否也可以使用字段注入 我认为 Dagger 是可能的 当我尝试用注入的东西做某事时yclass字段我收到此错误 lateinit property y
  • 保存的数据带有不需要的引号

    我使用以下代码将数据框导出到 csv data write format com databricks spark csv options delimiter t codec org apache hadoop io compress Gz
  • 使用 BufferedImages 获取图像每个像素的颜色

    我试图获取图像的每个像素的每种颜色 我的想法如下 int pixels BufferedImage image image ImageIO read this getClass getResources image png int pixe
  • 打字稿地图迭代失败

    我正在使用下面的函数来比较两个地图 有趣的是 for 循环内的代码永远不会被执行 所以 console log key val 代码永远不会被执行 当然 我确保我正在比较的映射不为空并且大小相同 以强制执行 for 循环内的代码 我犯了一个
  • 创建自定义工具栏?

    Please help me to create a toolbar like this home page design 工具栏顶部有 3 个按钮 3 个图像按钮 下面2个按钮 搜索框 imagebutton 和镜头 imagebutto
  • 为什么我的自定义 JSONEncoder.default() 忽略布尔值?

    我想将字典转换为带有布尔值的 JSON 字符串True值转换为数字1和布尔值False值转换为数字0 我正在使用一个JSONEncoder子类 但它似乎忽略布尔值 import json class MyEncoder json JSONE
  • 如何在 Kotlin Android 中正确使用 URL

    我想用 override fun onCreate savedInstanceState Bundle super onCreate savedInstanceState setContentView R layout activity m
  • Tomcat 是否提供对 Java 9 BETA 的支持

    我正在使用 Eclipse Mars 开发 Java 9 BETA 版本 想知道 Tomcat 是否提供对 Java 9 BETA 的支持 2017 年 8 月 26 日更新 在我寻求答案的过程中在 IntelliJ 2017 2 2 中的
  • 在Android中,如何在考虑由fling引起的加速的同时实现列表视图的捕捉效果?

    为了演示 我有一个显示数字列表的 ListView 我想实现这样的效果 当用户滚动ListView并且滚动结束时 它只会停在某些位置 以便第一个可见项始终完全显示 我在下面附上了我尝试的代码 当用户拖动滚动 ListView 时它会起作用
  • Websocket 连接失败并显示星号 11

    我正在尝试将 websocket 配置为与 asterisk 11 一起使用 但是存在一些问题 我遵循的步骤是 在 http conf 中启用以下内容 enabled yes bindaddr 0 0 0 0 bindport 8088 我