node.js - 简单对等 WebRTC 错误 : Ice connection failed

标签 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

这个问题有解决办法吗?谢谢

最佳答案

来自 chrome://webrtc-internals 的屏幕截图显示,尽管您使用了 TURN 服务器凭据,但没有收集具有中继类型的icecandidate。请参阅this blog post了解详情。

您可以使用 this page 检查凭据

关于node.js - 简单对等 WebRTC 错误 : Ice connection failed,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47086373/

相关文章:

android - 在 webrtc android 中调用时出现错误

javascript - navigator.mediaDevices.getDisplayMedia 不支持

node.js - WEBRTC 视频聊天应用程序无法在不同网络中运行

javascript - libnice 是做什么的?

javascript - Android React Native 应用程序在 getUserMedia WebRTC 调用时崩溃

node.js - 在 Mongoose 中将数组更新到文档中

node.js - 当win.show();时, Electron 会不断被选择。

javascript - 未调用 react 函数

node.js - child_process.js 在哪里?

node.js - token 在环回中如何工作