以前有人问过这个问题,但我还没有找到答案。我基本上遇到了与此处和此处描述的相同的问题。
我正在尝试使用 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 来做那件事。有没有人知道如何让它工作?