DEV Community

Discussion on: Let’s Build a Video Chat App with JavaScript and WebRTC

Collapse
 
boopalanm profile image
Boopalan-M

I have one doubt. could you please explain. how the offers are created and how this function works.
function handleIceCandidate(event) {
console.log('icecandidate event: ', event);
if (event.candidate) {
sendMessage({
type: 'candidate',
label: event.candidate.sdpMLineIndex,
id: event.candidate.sdpMid,
candidate: event.candidate.candidate
}, room);
} else {
console.log('End of candidates.');
}
}

Thanks in advance

Collapse
 
nilmadhabmondal profile image
Nil Madhab • Edited

You have asked me two things:-

  1. How is the offer created?
    The Offer is created using pc.createOffer(setLocalAndSendMessage, handleCreateOfferError); where pc is an object of RTCPeerConnection .

  2. How handleIceCandidate function works?
    Browser starts creating candidates as soon as we create an object of RTCPeerConnection. To handle these candidates, we must pass a handler function to this RTCPeerConnection Object as follows
    pc.onicecandidate = handleIceCandidate; , where pc is an object of RTCPeerConnection .
    Whenever a candidate is created by the browser, the handleIceCandidate function will be called