Skip to content

Instantly share code, notes, and snippets.

@Tschrock
Created January 23, 2018 16:58
Show Gist options
  • Save Tschrock/4ae4613404198e85732d102bd0a15b67 to your computer and use it in GitHub Desktop.
Save Tschrock/4ae4613404198e85732d102bd0a15b67 to your computer and use it in GitHub Desktop.
function getIps() {
return new Promise((resolve, reject) => {
const candidateIps = new Map();
const rtc = new RTCPeerConnection({});
rtc.onicecandidate = (e) => {
if(e.candidate) {
candidateIps.set(e.candidate.candidate.split(' ')[4], e.candidate.candidate)
}
else {
rtc.close();
resolve(Array.from(candidateIps.keys()))
}
}
rtc.createDataChannel("test");
rtc.createOffer({ offerToReceiveVideo: 1 }).then(
desc => rtc.setLocalDescription(desc),
e => reject(e)
);
});
}
getIps().then(ips => console.log(ips), e => console.log(e));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment