我的webRTC项目出了问题。我的代码在Chrome和Firefox上运行良好,直到版本52.自从Firefox 53我得到错误:" ICE失败,请参阅:webrtc了解更多详情"。这是我的代码:
let connection;
let dataChannel;
const initCon = (initiatorBoolean, choosenONE) => {
createConnection();
startConnection(initiatorBoolean, choosenONE);
console.log('initCon(' + initiatorBoolean + ') / choosenONE = ' +choosenONE);
}
var boolJoin = false;
var lobbies = [];
var me = prompt("Please enter your name", "Bert");
// Helper für das Errorlogging
const logErrors = err => console.log(err);
// Websockets-Verbindung herstellen
const socket = io.connect('http://7daysclub.de:8080');
/* Methode to send information between to Users
*@param
*receiver= User who get the message
*type= Type of the message: could be init, joined, getUsers, setUsers, offer, answer, candidate
*descr= Content of the message
*/
const sendMessage = (receiver, type, descr) => {
message = Object.assign({to: 'default'}, {
user: receiver,
type: type,
descr: descr,
from: me
});
socket.emit('message', message);
console.log("send: " + message.type + ". to: " + message.user);
};
const createConnection = () => {
//Verbindung erstellen
connection = new RTCPeerConnection( {
'iceServers': [
{
/*
'urls': 'stun:stun.l.google.com:19302'
*/
'urls': 'stun:185.223.29.90:3478'
},
{
'urls': 'turn:185.223.29.90:3478',
'credential': '***',
'username': '***'
}
]
});
connection.oniceconnectionstatechange = function(event) {
console.log('state: '+connection.iceConnectionState );
if (connection.iceConnectionState === "failed" ||
connection.iceConnectionState === "disconnected" ||
connection.iceConnectionState === "closed") {
// Handle the failure
}
};
}
const call = choosenONE => {
if (!boolJoin) {
sendMessage(choosenONE, 'joined', null);
}
};
// Nachricht vom Signaling-Kanal empfangen
const receiveMessage = message => {
console.log("receive: " + message.type);
//Filter messages
if (message.user != 'all' && message.user != me) {
console.log("Block= " + message.user);
return;
}
// Nachricht verarbeiten
switch (message.type) {
// Partner ist verfügbar
case 'joined':
choosenONE = message.from;
sendMessage( choosenONE, 'init', null);
boolJoin = true;
initCon(true, choosenONE);
break;
case 'getUsers':
sendMessage(message.from,'setUsers', null)
lobbies.push(message.from);
lobbylist();
console.log('add User: ' + lobbies[lobbies.length-1] + ' to List');
break;
case 'setUsers':
lobbies.push(message.from);
console.log('add User: ' + lobbies[lobbies.length-1] + ' to List');
lobbylist();
break;
// Verbindungsaufbau wurde vom Partner angefordert
case 'init':
choosenONE = message.from;
boolJoin = true;
initCon(false, choosenONE);
break;
// Ein SDP-Verbindungsangebot ist eingegangen – wir erstellen eine Antwort
case 'offer':
connection
.setRemoteDescription(new RTCSessionDescription(message.descr))
.then(() => connection.createAnswer())
.then(answer => connection.setLocalDescription(new RTCSessionDescription(answer)))
.then(() => sendMessage(message.from,'answer', connection.localDescription, me))
.catch(logErrors);
break;
// Eine SDP-Verbindungsantwort auf unsere Anfrage ist eingegangen.
case 'answer':
connection.setRemoteDescription(new RTCSessionDescription(message.descr));
break;
// Der Partner hat eine mögliche Host-Port-Kombination ("ICE Candidate") gefunden
case 'candidate':
connection.addIceCandidate(new RTCIceCandidate({candidate: message.descr}));
break;
}
};
socket.on('message', receiveMessage);
// Verbindung initialisieren
const startConnection = (isCreator, choosenONE) => {
// Wenn wir mögliche Kommunikationsendpunkte finden, diese an den Partner weitergeben
connection.onicecandidate = event => {
if (event.candidate) {
sendMessage(choosenONE, 'candidate', event.candidate.candidate);
}
};
// Wenn die Gegenseite einen Stream hinzufügt, diesen an das video-element hängen
connection.ontrack = (e) => {
document.getElementById('vidRemote').src = window.URL.createObjectURL(e.stream);
};
// Falls wir der erste Teilnehmer sind, starten wir den Verbindungsaufbau
if (isCreator) {
// Datenkanal anlegen
dataChannel = connection.createDataChannel('chat');
onDataChannelCreated(dataChannel);
connection
.createOffer()
.then(offer => connection.setLocalDescription(new RTCSessionDescription(offer)))
.then(() => sendMessage(choosenONE, 'offer', connection.localDescription))
.catch(logErrors);
} else {
// Wenn wir nicht der Initiator sind, reagieren wir nur auf das Anlegen eines Datenkanals
connection.ondatachannel = function (event) {
dataChannel = event.channel;
onDataChannelCreated(dataChannel);
};
}
};
const onDataChannelCreated = (channel, choosenONE) => {
// Sobald der Datenkanal verfügbar ist, Chateingaben zulassen
channel.onopen = () => {
const enterChat = document.getElementById('enterChat');
enterChat.disabled = false;
enterChat.onkeyup = (keyevent) => {
// Bei "Enter" absenden
if (keyevent.keyCode === 13) {
dataChannel.send(enterChat.value);
appendChatMessage(me+':', enterChat.value);
enterChat.value = '';
}
}
};
channel.onmessage = (message) => appendChatMessage(choosenONE+':', message.data);
};
const appendChatMessage = (name, text) => {
const displayChat = document.getElementById('displayChat');
const time = new Date().toString('H:i:s');
displayChat.innerHTML = `<p>${name} - ${time}<br>${text}</p>` + displayChat.innerHTML;
};
function lobbylist() {
allusers = "";
lobbies.forEach( element => {
allusers += "<li><button onclick=\"call('"+element+"')\">"+element+"</button></li>"
});
document.getElementById('lobbylist').innerHTML = allusers;
}
//Alle User bei Ankunft erfragen
sendMessage('all','getUsers', null);
lobbylist();
关于:webrtc =
(注册表/信息)插入&#39; ice&#39; (注册表)成功:ice
(registry / INFO)insert&#39; ice.pref&#39; (注册表)成功:ice.pref
(registry / INFO)insert&quot; ice.pref.type&#39; (注册表)成功:ice.pref.type
(注册表/信息)插入&#39; ice.pref.type.srv_rflx&#39; (UCHAR)成功:0x64
(注册表/信息)插入&#39; ice.pref.type.peer_rflx&#39; (UCHAR)成功:0x6e
(registry / INFO)insert&#39; ice.pref.type.host&#39; (UCHAR)成功:0x7e
(registry / INFO)insert&quot; ice.pref.type.relayed&#39; (UCHAR)成功:0x05
(registry / INFO)insert&#39; ice.pref.type.srv_rflx_tcp&#39; (UCHAR)成功:0x63
(registry / INFO)insert&#39; ice.pref.type.peer_rflx_tcp&#39; (UCHAR)成功:0x6d
(registry / INFO)insert&quot; ice.pref.type.host_tcp&#39; (UCHAR)成功:0x7d
(注册表/ INFO)insert&quot; ice.pref.type.relayed_tcp&#39; (UCHAR)成功:0x00
(注册表/信息)插入&#39;眩晕&#39; (注册表)成功:眩晕
(注册表/ INFO)插入stun.client&#39; (注册表)成功:stun.client
(注册表/信息)插入&#39; stun.client.maximum_transmits&#39; (UINT4)成功:7
(注册表/信息)插入&#39; ice.trickle_grace_period&#39; (UINT4)成功:5000
(注册表/信息)插入&#39; ice.tcp&#39; (注册表)成功:ice.tcp
(注册表/信息)插入&#39; ice.tcp.so_sock_count&#39; (INT4)成功:0
(注册表/信息)插入&#39; ice.tcp.listen_backlog&#39; (INT4)成功:10
(注册表/信息)插入&#39; ice.tcp.disable&#39; (char)成功了:\ 000
(通用/ EMERG)退出UDP套接字连接
(通用/错误)UDP套接字错误:z处的内部错误:/build/build/src/dom/network/UDPSocketParent.cpp:283 this = 00000000120CC400
(ice / INFO)z:/build/build/src/media/mtransport/third_party/nICEr/src/net/nr_socket_multi_tcp.c:173函数nr_socket_multi_tcp_create_stun_server_socket跳过UDP STUN服务器(地址:IP4:185.223.29.90:3478 / UDP)
(ice / INFO)z:/build/build/src/media/mtransport/third_party/nICEr/src/net/nr_socket_multi_tcp.c:173函数nr_socket_multi_tcp_create_stun_server_socket跳过UDP STUN服务器(地址:IP4:185.223.29.90:3478 / UDP)
(ice / WARNING)z:/build/build/src/media/mtransport/third_party/nICEr/src/net/nr_socket_multi_tcp.c:617函数nr_socket_multi_tcp_listen失败,错误3
(ice / WARNING)ICE(PC:1512241952789000(id = 19327352835 url = http://7daysclub.de/webrtc2/)):无法创建被动TCP主机候选者:3
(ice / NOTICE)ICE(PC:1512241952789000(id = 19327352835 url = http://7daysclub.de/webrtc2/)):peer(PC:1512241952789000(id = 19327352835 url = http://7daysclub.de/webrtc2/):default)没有非空流检查清单
(ice / NOTICE)ICE(PC:1512241952789000(id = 19327352835 url = http://7daysclub.de/webrtc2/)):peer(PC:1512241952789000(id = 19327352835 url = http://7daysclub.de/webrtc2/):default)没有预先回答的流请求
(ice / NOTICE)ICE(PC:1512241952789000(id = 19327352835 url = http://7daysclub.de/webrtc2/)):peer(PC:1512241952789000(id = 19327352835 url = http://7daysclub.de/webrtc2/):default)没有检查开始
(ice / ERR)ICE(PC:1512241952789000(id = 19327352835 url = http://7daysclub.de/webrtc2/)):peer(PC:1512241952789000(id = 19327352835 url = http://7daysclub.de/webrtc2/):default)配对本地滴流ICE候选主机(IP4:192.168.0.4:54605 / UDP)
(ice / ERR)ICE(PC:1512241952789000(id = 19327352835 url = http://7daysclub.de/webrtc2/)):peer(PC:1512241952789000(id = 19327352835 url = http://7daysclub.de/webrtc2/):default)配对本地滴流ICE候选主机(IP4:192.168.0.4:62417 / TCP)有效
(stun / INFO)无法识别的属性:0x802b
(ice / ERR)ICE(PC:1512241952789000(id = 19327352835 url = http://7daysclub.de/webrtc2/)):peer(PC:1512241952789000(id = 19327352835 url = http://7daysclub.de/webrtc2/):default)配对本地滴流ICE候选者srflx (IP4:192.168.0.4:54605 / UDP | IP4:185.223.29.90:3478 / UDP)
(stun / WARNING)STUN-CLIENT(中继(IP4:192.168.0.4:54605 / UDP | IP4:185.223.29.90:3478 / UDP):: TURN):处理响应错误:可能重试,晕眩错误代码401。
(stun / WARNING)STUN-CLIENT(中继(IP4:192.168.0.4:54605 / UDP | IP4:185.223.29.90:3478 / UDP):: TURN):处理响应错误:可能重试,晕眩错误代码401。
(转/警告)转(继电器(IP4:192.168.0.4:54605 / UDP | IP4:185.223.29.90:3478 / UDP)):超过重试次数
(转/警告)转(继电器(IP4:192.168.0.4:54605 / UDP | IP4:185.223.29.90:3478 / UDP)):模式20,nr_turn_client_error_cb
(转/警告)转(继电器(IP4:192.168.0.4:54605 / UDP | IP4:185.223.29.90:3478 / UDP))失败
(转/ INFO)转(继电器(IP4:192.168.0.4:54605 / UDP | IP4:185.223.29.90:3478 / UDP)):取消
(转/警告)ICE-CANDIDATE(继电器(IP4:192.168.0.4:54605 / UDP | IP4:185.223.29.90:3478 / UDP)):nr_turn_allocated_cb用状态4调用
(转/警告)ICE-CANDIDATE(继电器(IP4:192.168.0.4:54605 / UDP | IP4:185.223.29.90:3478 / UDP)):nr_turn_allocated_cb失败
(ice / INFO)ICE(PC:1512241952789000(id = 19327352835 url = http://7daysclub.de/webrtc2/)):peer(PC:1512241952789000(id = 19327352835 url = http://7daysclub.de/webrtc2/):default)涓流宽限期结束;将只有失败对的每个组件标记为失败。
(ice / INFO)ICE-PEER(PC:1512241952789000(id = 19327352835 url = http://7daysclub.de/webrtc2/):default)/STREAM(0-1512241952789000(id = 19327352835 url = http://7daysclub.de/webrtc2/)aLevel = 0)/ COMP(1):所有对失败,宽限期已过。将组件标记为失败。
(ice / INFO)ICE-PEER(PC:1512241952789000(id = 19327352835 url = http://7daysclub.de/webrtc2/):default):所有检查成功完成= 0失败= 1
(通用/ EMERG)退出UDP套接字连接
(通用/ ERR)UDP套接字错误:z处的内部错误:/build/build/src/dom/network/UDPSocketParent.cpp:283 this = 000000000BAE3000
(ice / INFO)z:/build/build/src/media/mtransport/third_party/nICEr/src/net/nr_socket_multi_tcp.c:173函数nr_socket_multi_tcp_create_stun_server_socket跳过UDP STUN服务器(地址:IP4:185.223.29.90:3478 / UDP)
(ice / INFO)z:/build/build/src/media/mtransport/third_party/nICEr/src/net/nr_socket_multi_tcp.c:173函数nr_socket_multi_tcp_create_stun_server_socket跳过UDP STUN服务器(地址:IP4:185.223.29.90:3478 / UDP)
(ice / WARNING)z:/build/build/src/media/mtransport/third_party/nICEr/src/net/nr_socket_multi_tcp.c:617函数nr_socket_multi_tcp_listen失败,错误3
(ice / WARNING)ICE(PC:1512242125375000(id = 19327352836 url = http://7daysclub.de/webrtc2/)):无法创建被动TCP主机候选者:3
(ice / NOTICE)ICE(PC:1512242125375000(id = 19327352836 url = http://7daysclub.de/webrtc2/)):peer(PC:1512242125375000(id = 19327352836 url = http://7daysclub.de/webrtc2/):default)没有非空流检查清单
(ice / NOTICE)ICE(PC:1512242125375000(id = 19327352836 url = http://7daysclub.de/webrtc2/)):peer(PC:1512242125375000(id = 19327352836 url = http://7daysclub.de/webrtc2/):default)没有预先回答的流请求
(ice / NOTICE)ICE(PC:1512242125375000(id = 19327352836 url = http://7daysclub.de/webrtc2/)):peer(PC:1512242125375000(id = 19327352836 url = http://7daysclub.de/webrtc2/):default)没有检查开始
(ice / ERR)ICE(PC:1512242125375000(id = 19327352836 url = http://7daysclub.de/webrtc2/)):peer(PC:1512242125375000(id = 19327352836 url = http://7daysclub.de/webrtc2/):default)配对本地滴流ICE候选主机(IP4:192.168.0.4:63286 / UDP)
(ice / ERR)ICE(PC:1512242125375000(id = 19327352836 url = http://7daysclub.de/webrtc2/)):peer(PC:1512242125375000(id = 19327352836 url = http://7daysclub.de/webrtc2/):default)配对本地滴流ICE候选主机(IP4:192.168.0.4:54433 / TCP)有效
(stun / INFO)无法识别的属性:0x802b
(ice / ERR)ICE(PC:1512242125375000(id = 19327352836 url = http://7daysclub.de/webrtc2/)):peer(PC:1512242125375000(id = 19327352836 url = http://7daysclub.de/webrtc2/):default)配对本地滴流ICE候选者srflx (IP4:192.168.0.4:63286 / UDP | IP4:185.223.29.90:3478 / UDP)
(stun / WARNING)STUN-CLIENT(中继(IP4:192.168.0.4:63286 / UDP | IP4:185.223.29.90:3478 / UDP):: TURN):处理响应错误:可能重试,晕眩错误代码401。
(转/ INFO)转(继电器(IP4:192.168.0.4:63286 / UDP | IP4:185.223.29.90:3478 / UDP)):成功分配地址IP4:185.223.29.90:50497 / UDP生存期= 3600 < / p>
(ice / ERR)ICE(PC:1512242125375000(id = 19327352836 url = http://7daysclub.de/webrtc2/)):peer(PC:1512242125375000(id = 19327352836 url = http://7daysclub.de/webrtc2/):default)配对本地滴流ICE候选转弯-relay(IP4:192.168.0.4:63286 / UDP | IP4:185.223.29.90:50497 / UDP)
(ice / INFO)ICE(PC:1512242125375000(id = 19327352836 url = http://7daysclub.de/webrtc2/)):peer(PC:1512242125375000(id = 19327352836 url = http://7daysclub.de/webrtc2/):default)涓流宽限期结束;将只有失败对的每个组件标记为失败。
(ice / INFO)ICE-PEER(PC:1512242125375000(id = 19327352836 url = http://7daysclub.de/webrtc2/):default)/STREAM(0-1512242125375000(id = 19327352836 url = http://7daysclub.de/webrtc2/)aLevel = 0)/ COMP(1):所有对失败,宽限期已过。将组件标记为失败。
(ice / INFO)ICE-PEER(PC:1512242125375000(id = 19327352836 url = http://7daysclub.de/webrtc2/):default):所有检查成功完成= 0失败= 1
++++++++++++++++++++++++++++++++++++++++++
我的turnserver配置看起来像这样:
# TURN listener port for UDP and TCP (Default: 3478).
# Note: actually, TLS & DTLS sessions can connect to the
# "plain" TCP & UDP port(s), too - if allowed by configuration.
#
listening-port=3478
# TURN listener port for TLS (Default: 5349).
# Note: actually, "plain" TCP & UDP sessions can connect to the TLS & DTLS
# port(s), too - if allowed by configuration. The TURN server
# "automatically" recognizes the type of traffic. Actually, two listening
# endpoints (the "plain" one and the "tls" one) are equivalent in terms of
# functionality; but we keep both endpoints to satisfy the RFC 5766 specs.
# For secure TCP connections, we currently support SSL version 3 and
# TLS version 1.0, 1.1 and 1.2. SSL2 "encapculation mode" is also supported.
# For secure UDP connections, we support DTLS version 1.
#
tls-listening-port=5349
# Listener IP address of relay server. Multiple listeners can be specified.
# If no IP(s) specified in the config file or in the command line options,
# then all IPv4 and IPv6 system IPs will be used for listening.
#
listening-ip=185.223.29.90
# Relay address (the local IP address that will be used to relay the
# packets to the peer).
# Multiple relay addresses may be used.
# The same IP(s) can be used as both listening IP(s) and relay IP(s).
#
# If no relay IP(s) specified, then the turnserver will apply the default
# policy: it will decide itself which relay addresses to be used, and it
# will always be using the client socket IP address as the relay IP address
# of the TURN session (if the requested relay address family is the same
# as the family of the client socket).
#
relay-ip=185.223.29.90
lt-cred-mech
# Realm for long-term credentials mechanism and for TURN REST API.
#
realm=7daysclub.de
#Local system IP address to be used for CLI server endpoint. Default value
# is 127.0.0.1.
#
cli-ip=185.223.29.90
# CLI server port. Default is 5766.
#
cli-port=5766
答案 0 :(得分:8)
查看您的在线演示,远程SDP中没有a =候选行,表明候选人永远不会被添加。
sendMessage(choosenONE, 'candidate', event.candidate.candidate);
这是丢弃需要向远程对等方发信号通知的sdpMid和sdpMLineIndex。将.catch添加到addIceCandidate以记录任何错误。