NodeJS 简单对等WebRTC错误:Ice连接失败

a2mppw5e  于 2022-11-29  发布在  Node.js
关注(0)|答案(2)|浏览(223)

在浏览器中不能使简单对等NPM库连接两个不同网络中的两台计算机,如果计算机在同一个局域网中,浏览器可以相互连接,否则不能使它们连接。
两种浏览器都返回此错误:

"Error: Ice connection failed. 
at Peer._onIceStateChange"
at RTCPeerConnection.Peer.self._pc.oniceconnectionstatechange

信号看起来对我来说是正确的:

{ type: 'offer',
     sdp: 'v=0\r\no=- 2275520429720515716 2 IN IP4 127.0.0.1\r\ns=-\r\nt=0 0\r\na=group:BUNDLE data\r\na=msid-semantic: WMS\r\nm=application 49523 DTLS/SCTP 5000\r\nc=IN IP4 5.12.206.160\r\na=candidate:2020300070 1 udp 2113937151 192.168.2.8 49523 typ host generation 0 network-cost 50\r\na=candidate:842163049 1 udp 1677729535 5.12.206.160 49523 typ srflx raddr 192.168.2.8 rport 49523 generation 0 network-cost 50\r\na=ice-ufrag:Ph/x\r\na=ice-pwd:csnTbzHs+dxzakEKPY8LfvBg\r\na=fingerprint:sha-256 B9:C0:9D:91:46:1B:E8:5C:83:B1:11:A7:C5:D7:64:97:A6:63:D9:12:11:0F:9A:05:8F:46:83:BC:90:38:86:9E\r\na=setup:actpass\r\na=mid:data\r\na=sctpmap:5000 webrtc-datachannel 1024\r\n' } }

{ type: 'answer',
     sdp: 'v=0\r\no=- 1356997482353729498 2 IN IP4 127.0.0.1\r\ns=-\r\nt=0 0\r\na=group:BUNDLE data\r\na=msid-semantic: WMS\r\nm=application 56005 DTLS/SCTP 5000\r\nc=IN IP4 86.126.104.54\r\nb=AS:30\r\na=candidate:2702239670 1 udp 2113937151 192.168.1.103 56003 typ host generation 0 network-cost 50\r\na=candidate:842163049 1 udp 1677729535 86.126.104.54 56005 typ srflx raddr 192.168.1.103 rport 56003 generation 0 network-cost 50\r\na=ice-ufrag:W6zA\r\na=ice-pwd:1NhU5D47rSz83ANxlY+Tz/XI\r\na=ice-options:trickle\r\na=fingerprint:sha-256 2C:0B:78:49:F5:F0:44:6C:86:DD:27:BC:B6:7D:77:B9:B1:07:F4:2F:37:F5:24:D9:A3:54:7D:B3:A0:3C:57:C0\r\na=setup:active\r\na=mid:data\r\na=sctpmap:5000 webrtc-datachannel 1024\r\n' } }

但是当库想要建立连接时,两个浏览器都返回上述错误。
这是我的密码

//TUTORIAL BASED ON
// https://github.com/feross/simple-peer

var initiator = (location.hash||'') === '#1';
console.log("inititator",location.hash , initiator);

var Peer = require('simple-peer');

params = {
    initiator: initiator,
    trickle: false,
    reconnectTimer: 100,
    iceTransportPolicy: 'relay',
    config: {

        iceServers: [
            {
                urls: "stun:numb.viagenie.ca",
                username: "pasaseh@ether123.net",
                credential: "12345678"
            },
            {
                urls: "turn:numb.viagenie.ca",
                username: "pasaseh@ether123.net",
                credential: "12345678"
            }
        ]
    }
};

if (typeof window === "undefined"){
    var wrtc = require('wrtc');
    params.wrtc=  wrtc;
}

var p = new Peer(params);

p.on('error', function (err) { console.log('error', err) })

p.on('signal', function (data) {
    console.log('SIGNAL', JSON.stringify(data));
    document.querySelector('#outgoing').textContent = JSON.stringify(data)
});

document.querySelector('form').addEventListener('submit', function (ev) {
    ev.preventDefault();
    console.log("am apasat pe button");
    p.signal(JSON.parse(document.querySelector('#incoming').value))
});

let index = Math.floor(Math.random()*100);

p.on('connect', function (data) {

    console.log('CONNECT', data, p);

    setInterval(function() {
        if ((typeof p !== 'undefined')&& ( p !== null)) {
            console.log(p);
            p.send('whatever' + index + " ___ " + Math.random())
        }
    }, 500);

    p.on("hello", function(data){
        alert(data);
    });

    p.emit("hello",55);

})

p.on('data', function (data) {
    console.log('data: ' + data)
});

module.exports = function(){
    console.log("Hello World Server");
};

webrtc-internals
这个问题有什么解决办法吗?谢谢

zd287kbt

zd287kbt1#

chrome://webrtc-internals的屏幕截图显示,尽管您使用了TURN服务器凭据,但没有收集到类型为relay的icecandidate。有关详细信息,请参阅this blog post
您可以使用this page检查凭据

68bkxrlz

68bkxrlz2#

我建议使用仍然工作的冰服务器时,列出你的冰服务器如下

new SimplePeer({
          initiator: false,
          tricle: false,
          config: {
            iceServers: [
              {
                urls: "turn:numb.viagenie.ca",
                credential: "muazkh",
                username: "webrtc@live.com",
              },
            ],
          },
        })

相关问题