简体   繁体   中英

Chrome does not generate the ice candidate , WebRTC

I'm trying to establish a video call between two peers using Chrome to Chrome browser, at local , not using STUN/TURN servers.

Imagine the first peer's name is " Sara ", she presents a video call as a caller. The second peer's name is " Bill ", he is a viewer and only watches Sara's video.

1- Sara's computer generates an offer and sets it as the local description using pc.setLocalDescription(offer) .

2- It sends a generated offer using the signaling server to Bill.

3- Bill's computer sets the incoming offer form Sara as the remote description using pc.setRemoteDescription(offer) .

4- Bill generates an answer and sets it as the local description.

5- Bill sends the generated answer to Sara by using the signaling server.

6- Sara gets the answer and sets it as the remote description.

I've defined an event listener for those ice-candidates in both sides:

pc.onicecandidate = (event)=>{
   console.log("Event : ",event);
   pc.addIceCandidate(event.candidate);
};

In Chrome it never invokes pc.onicecandidate , I mean the onicecandidate never executes and logs, but in Firefox it logs an event object that its candidate property equals null .

Please can someone tell me that when exactly pc.onicecandidate = (event)=>... invokes?

When setLocalDescription() is success, onicecandidate invokes.

In onicecandidate, event parameter will have own candidate.

So you have to send Sara's candidate to Bill, vice versa.

If Sara or Bill receives opponent's candidate, that candidate must be added to pc.

const pc = new RTCPeerConnection();

pc.onicecandidate = evt => {
    // send evt.candidate to opponent
    // you don't need to add own candidate self.
};

...

pc.createOffer().then(sdp => {
    pc.setLocalDescription(sdp); // onicecandidate invokes !
    // send sdp to opponent.
}).catch(err => console.error(err));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM