Cuando ejecuto este código, la conexión no se establece,
en el error de la consola de Firefox "WebRTC: ICE falló, agregue un servidor STUN y consulte: webrtc para obtener más detalles" aparece y dataChannel.readyState se está conectando
en la consola Chrome, el error no aparece, pero nuevamente dataChannel.readyState se está conectando
var localconn, remoteconn, dataChannel, recievedDataChannel; connect(); async function connect(){ localconn = new RTCPeerConnection(); remoteconn = new RTCPeerConnection(); dataChannel = localconn.createDataChannel("dataChannel"); dataChannel.onopen = e =>{ console.log("data channel is open"); } dataChannel.onmessage = e=>{ console.log("new message: " +e.data); } remoteconn.ondatachannel = e =>{ recievedDataChannel = e.channel; recievedDataChannel.onmessage = e=>{ console.log("new message from remote : " +e.data); } } var offer = await localconn.createOffer(); await localconn.setLocalDescription(offer); await remoteconn.setRemoteDescription(offer); var answer = await remoteconn.createAnswer(); await remoteconn.setLocalDescription(answer); await localconn.setRemoteDescription(answer);}
Necesita un oyente para los candidatos de ICE en la conexión del par y aplicarlos al otro par.
localconn.onicecandidate = function(event) { if (event.candidate) { remoteconn.addIceCandidate(event.candidate); } else { // All ICE candidates have been sent } } remoteconn.onicecandidate = function(event) { if (event.candidate) { localconn.addIceCandidate(event.candidate); } else { // All ICE candidates have been sent } }Consulte también https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection/onicecandidate