I am trying to understand how to use WebRTC to establish P2P connections following the example here: https://developer.mozilla.org/en-US/docs/Web/API/WebRTC_API/Simple_RTCDataChannel_sample. In my mind, it seems like when I create a new RTCPeerConnection, that connection should contain information about my public ip and subnet, so that when I create an offer and pass it to the remote computer, the remote would then have the details about where to send the response offer. However, whenever I try creating an RTCPeerConnection, it has 0.0.0.0 in it and no mention of my ip (which is not 0.0.0.0). Do you know why this could be? What am I doing wrong? How do I get it to display my public ip?
var localConnection = new RTCPeerConnection({
'iceServers': [
{
'urls': ['stun:stun.l.google.com:19302'],
},
],
});
var offer = localConnection.createOffer();
await localConnection.setLocalDescription(offer);
console.log(localConnection.localDescription);
// RTCSessionDescription { type: "offer", sdp: "v=0\r\no=mozilla...THIS_IS_SDPARTA-97.0 5252435491124817570 1 IN IP4 0.0.0.0\r\ns=-\r\nt=0 0\r\na=sendrecv\r\na=fingerprint:sha-256 94:95:5B:C2:D2:DC:56:71:EF:D6:A6:3E:CB:07:09:B0:A3:DB:FD:0B:8D:80:96:8C:56:B6:72:84:F3:36:1A:04\r\na=group:BUNDLE 1\r\na=ice-options:trickle\r\na=msid-semantic:WMS *\r\nm=application 9 UDP/DTLS/SCTP webrtc-datachannel\r\nc=IN IP4 0.0.0.0\r\na=sendrecv\r\na=ice-pwd:e4ae4077195d25ff0973d2c70c50111f\r\na=ice-ufrag:efc13e32\r\na=mid:1\r\na=setup:actpass\r\na=sctp-port:5000\r\na=max-message-size:1073741823\r\n" }
The ICE Candidates haven't been gathered yet. It starts after SetLocalDescription
is called, and candidates will be added to your localDescription
as they arrive.
Set onicecandidate and it will called with your 'public ip'.