Reputation: 79
const peerConnection = new RTCPeerConnection({ iceServers: [] });
peerConnection.createDataChannel('');
peerConnection.createOffer()
.then((offer) => peerConnection.setLocalDescription(offer))
.catch((error) => console.log(error));
peerConnection.onicecandidate = (event) => {
if (event.candidate) {
console.log(`Client's IP address is ${event.candidate.address}`);
}
};
Upvotes: 8
Views: 39120
Reputation: 66
const ipAddress = event.candidate.candidate.split(' ')[4];
console.log('IP address:', ipAddress);
Upvotes: 0