'Web RTC connection is not established

When I run this code connection is not established,

  • in firefox console error "WebRTC: ICE failed, add a STUN server and see about:webrtc for more details" shows up and dataChannel.readyState is connecting

  • in Chrome console error does not show up but again dataChannel.readyState is connecting

     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);
    

    }



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source