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

时间:2017-11-02 23:48:40

标签: node.js webrtc

我无法使Simple-Peer 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

解决这个问题的方法是什么?感谢

1 个答案:

答案 0 :(得分:0)

chrome:// webrtc-internals的屏幕截图显示,尽管您使用了TURN服务器凭据,但不会收集带类型中继的icecandidate。有关详细信息,请参阅this blog post

您可以使用this page

检查凭据