Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/398.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript iceConnectionState已断开连接(通过internet使用时)_Javascript_Webrtc_Peerjs_Coturn - Fatal编程技术网

Javascript iceConnectionState已断开连接(通过internet使用时)

Javascript iceConnectionState已断开连接(通过internet使用时),javascript,webrtc,peerjs,coturn,Javascript,Webrtc,Peerjs,Coturn,这个问题以前有人问过,但我还没有找到答案。我的问题基本上和前面描述的一样 我正在尝试使用PeerJS建立webRTC连接。它在局域网中工作完美无瑕,但我无法让它在互联网上工作。我使用coturn作为TURN服务器,但到目前为止还没有解决问题。Chromium控制台打印出以下内容: PeerJS: Added ICE candidate for: client1 peer.js:1476 PeerJS: Set remoteDescription: ANSWER for: client1 pe

这个问题以前有人问过,但我还没有找到答案。我的问题基本上和前面描述的一样

我正在尝试使用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
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)
我使用的对等对象如下所示:

var peer = new Peer(
    GetURLParameter('id'),
    { key: peerKey, debug: peerDebug},
    {config:
        { 'iceServers': [
            { url: 'stun:[server ip here]:3478'},
            { url: 'turn:[server ip here]:3478'}
        ]}
    }
);
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
var peer = new Peer(
    GetURLParameter('id'), {
        key: peerKey,
        debug: peerDebug,
        config: {
            'iceServers': [
                { url: 'stun:[server ip]:3478'},
                { url: 'turn:[server ip]:3478'}
            ]
        }
    }
);
使用turnserver-L[服务器ip]启动turnserver时,coturn会打印以下内容:

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
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配置目前看起来如下:

var peer = new Peer(
    GetURLParameter('id'),
    { key: peerKey, debug: peerDebug},
    {config:
        { 'iceServers': [
            { url: 'stun:[server ip here]:3478'},
            { url: 'turn:[server ip here]:3478'}
        ]}
    }
);
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
var peer = new Peer(
    GetURLParameter('id'), {
        key: peerKey,
        debug: peerDebug,
        config: {
            'iceServers': [
                { url: 'stun:[server ip]:3478'},
                { url: 'turn:[server ip]:3478'}
            ]
        }
    }
);
有人知道如何让这东西工作吗?任何帮助都将不胜感激

编辑:原来我的回合配置JSON很混乱。我的新对等对象现在看起来如下所示:

var peer = new Peer(
    GetURLParameter('id'),
    { key: peerKey, debug: peerDebug},
    {config:
        { 'iceServers': [
            { url: 'stun:[server ip here]:3478'},
            { url: 'turn:[server ip here]:3478'}
        ]}
    }
);
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
var peer = new Peer(
    GetURLParameter('id'), {
        key: peerKey,
        debug: peerDebug,
        config: {
            'iceServers': [
                { url: 'stun:[server ip]:3478'},
                { url: 'turn:[server ip]:3478'}
            ]
        }
    }
);
这给了我更多关于TURN server的反馈(因此我想我的方向是正确的),但问题仍然存在


EDIT2: 嗯,这很奇怪。这似乎是某种跨浏览器兼容性问题。使用mido建议的TURN服务器测试工具,我在Firefox中得到的结果与在Chromium中得到的结果不同。我打算使用Chromium,因为它的kiosk模式对我的应用非常方便。但是回到回合服务器。在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 server上的终端反复打印401条错误消息时。在我看来,使用chromium时,凭据永远不会到达服务器。401错误消息表示用户名为空


我真的可以用铬做那东西。有人知道如何让它工作吗?

请检查你的回合服务器的防火墙设置。

对于初学者,你的回合服务器在哪里托管,它有公共ip吗?我正在使用一个基于Ubuntu的虚拟服务器(他们称之为“droplet”)。我可以从这里ping它,所以我猜,是的,它有一个公共ip。你能测试回合是否独立工作,检查这个,通常对于回合,人们提供用户名密码,他们在你的回合中丢失了配置你交换网络了吗?Peerjs在你交换网络时工作不好。谢谢链接,mido。我将运行一些测试并报告结果。似乎是个有用的工具@你说的交换网络是什么意思(老实说,我不太擅长我所做的…)?我正在建立一个连接,从我家的DSL连接到4G/LTS连接上的raspberry pi。谢谢你迄今为止的帮助!测试时,我通过调用ufw disable禁用了服务器上的防火墙。我想这应该是防火墙的问题了。但谢谢你的提示。即使防火墙被禁用,也一样。