iceConnectionState已断开连接(在互联网上使用时)

时间:2016-06-19 23:59:37

标签: javascript webrtc peerjs coturn

之前已经问过这个问题,但我还没有找到答案。我基本上遇到与herehere所述相同的问题。

我尝试使用PeerJS设置webRTC连接。它在局域网中完美运行,但我无法在互联网上工作。我使用coturn作为TURN服务器,但到目前为止还没有解决问题.Chromium控制台打印出以下内容:

PeerJS:  Added ICE candidate for: client1
peer.js:1476 PeerJS:  Set remoteDescription: ANSWER for: client1
peer.js:1476 PeerJS:  Set remoteDescription: OFFER for: client1
peer.js:1476 PeerJS:  Set remoteDescription: ANSWER for: client1
peer.js:1476 PeerJS:  Received remote stream
peer.js:1476 PeerJS:  Receiving stream MediaStream
peer.js:1476 PeerJS:  Created answer.
peer.js:1476 PeerJS:  Set localDescription: answer for: client1
3peer.js:1476 PeerJS:  Received ICE candidates for: client1
3peer.js:1476 PeerJS:  Added ICE candidate for: client1
peer.js:1476 PeerJS:  iceConnectionState is disconnected, closing connections to client1
peer.js:1476 PeerJS:  Cleaning up PeerConnection to client1
2peer.js:1476 PeerJS:  iceConnectionState is disconnected, closing connections to client1

我使用的对等对象看起来像这样:

var peer = new Peer(
    GetURLParameter('id'),
    { key: peerKey, debug: peerDebug},
    {config:
        { 'iceServers': [
            { url: 'stun:[server ip here]:3478'},
            { url: 'turn:[server ip here]:3478'}
        ]}
    }
);

coturn,在使用turnserver -L [server ip]启动turnserver时,打印出以下内容:

0: Relay address to use: [server ip here]
0: pid file created: /var/run/turnserver.pid
0: IO method (main listener thread): epoll (with changelist)
0: WARNING: I cannot support STUN CHANGE_REQUEST functionality because only one IP address is provided
0: Wait for relay ports initialization...
0:   relay [server ip here] initialization...
0:   relay [server ip here] initialization done
0: Relay ports initialization done
0: IO method (general relay thread): epoll (with changelist)
0: turn server id=0 created
0: IPv4. UDP listener opened on: [server ip here]:3478
0: IPv4. TCP listener opened on : [server ip here]:3478
0: Total UDP servers: 1
0: Total General servers: 1
0: IO method (cli thread): epoll (with changelist)
0: IPv4. CLI listener opened on : 127.0.0.1:5766
0: IO method (auth thread): epoll (with changelist)

最后因为我猜这可能是一个安全问题,我的iptables配置目前看起来像这样:

Chain INPUT (policy ACCEPT)
target     prot opt source               destination         
ACCEPT     tcp  --  anywhere             anywhere             tcp dpt:3478
ACCEPT     udp  --  anywhere             anywhere             udp dpt:3478

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination         
ACCEPT     tcp  --  anywhere             anywhere             tcp dpt:3478
ACCEPT     udp  --  anywhere             anywhere             udp dpt:3478

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination         
ACCEPT     tcp  --  anywhere             anywhere             tcp dpt:3478
ACCEPT     udp  --  anywhere             anywhere             udp dpt:3478

任何人都知道如何使这个东西工作?任何帮助将不胜感激!

编辑:事实证明我的TURN配置的JSON很乱。我的新同伴对象现在看起来像这样:

var peer = new Peer(
    GetURLParameter('id'), {
        key: peerKey,
        debug: peerDebug,
        config: {
            'iceServers': [
                { url: 'stun:[server ip]:3478'},
                { url: 'turn:[server ip]:3478'}
            ]
        }
    }
);

这给了我关于TURN服务器的更多反馈(所以我想我正朝着正确的方向前进) - 但问题仍然存在。

EDIT2: 好吧,它变得相当奇怪。这似乎是某种跨浏览器兼容性问题。使用mido建议的TURN服务器测试工具,我在Firefox中得到的结果与Chromium不同。我打算使用Chromium,因为它的自助服务终端模式对我的应用来说非常方便。但回到转弯服务器。在Firefox中,当使用用户帐户时,一切似乎都运行良好: github测试页面的输出:

0.004   1   host    0   UDP 192.168.178.28  39919   126 | 32512 | 255
0.005   2   host    0   UDP 192.168.178.28  56123   126 | 32512 | 254
0.076   1   srflx   1   UDP 178.39.74.108   39919   100 | 32543 | 255
0.077   1   relay   2   UDP [Server IP ]    52147   5 | 32543 | 255
0.098   2   srflx   1   UDP 178.39.74.108   56123   100 | 32543 | 254
0.099   2   relay   2   UDP [Server IP ]    60002   5 | 32543 | 254
0.099   Done

但是,允许匿名访问TURN服务器并尝试在没有用户名和密码的情况下登录,绝对没有任何反应。

Chromium中的不同故事:提供用户名和密码后,会发生以下情况:

0.002   1   host    138421141   udp 192.168.178.28  42343   126 | 30 | 255
0.002   2   host    138421141   udp 192.168.178.28  49001   126 | 30 | 254
0.028   1   srflx   842163049   udp 178.39.74.108   42343   100 | 30 | 255
0.049   2   srflx   842163049   udp 178.39.74.108   49001   100 | 30 | 254

...当TURN服务器上的终端反复打印出401错误消息时。在我看来,使用铬时凭证永远不会到达服务器。 401错误消息表明空用户名。

我真的可以使用Chromium来做那件事。有没有人知道如何让它发挥作用?

2 个答案:

答案 0 :(得分:1)

请检查您的转弯服务器上的防火墙设置。

答案 1 :(得分:0)

这是一个与 TURN 服务器相关的问题,PeerJS 的自由轮服务器由于某些原因无法正常工作。切换回合服务器,问题就解决了。

var peer = new Peer({
  config: {'iceServers': [
    { url: 'stun:stun.l.google.com:19302' },
    { url: 'turn:homeo@turn.bistri.com:80', credential: 'homeo' }
  ]} /* Sample servers, please use appropriate ones */
});

注意:xirsys 为开发目的提供免费的轮流服务器。