I was learning webRTC and encountered this problem. I have created a peerConnection without using any media(audio or video).
I have created the offer and set the local description. As fas as I know icecandidate event is triggered as soon as the local description is set. Accordingly I have coded and used console.log(event.candidate). But not getting the desired output.Please go through the code below and correct me where I have gone wrong.
const configuration = {
iceServers: [{
urls:['stun:stun.l.google.com:19302','stun:stun2.l.google.com:19302']
}]
};
const peerConnection = new RTCPeerConnection(configuration);
peerConnection.onicecandidate = (event)=>{
if (event.candidate) {
console.log('New ICE candidate:', event.candidate);
// Display the ICE candidate for manual exchange
// const iceCandidatesTextArea = document.getElementById('iceCandidates');
// iceCandidatesTextArea.value += JSON.stringify(event.candidate) + 'n';
}
else
{
console.log("All ICE candidates gathered");
}
};
// Add event listener for ICE candidates
async function createOffer() {
try{
const offer = await peerConnection.createOffer();
await peerConnection.setLocalDescription(offer);
console.log(peerConnection);
}catch(error){
console.log("error generating offer",error);
}
}
createOffer();
I tried out all the possible ways to print the ice candidates but no output obtained!!
Nagarjun CS is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.