0

I am new coding in Javascript. I am creating a WebRTC connection between my iPhone and my browser. The connection works but my code only send one candidate and I don't know if I am doing anything wrong. I would appreciate any comment or support.

Thanks

const createPeerConnection = (signaling) => {
            const peerConnection = new RTCPeerConnection({
                iceServers: [],
            });

            const offerOptions = {
                offerToReceiveVideo: true, offerToReceiveAudio: true
            };

            peerConnection.createOffer(offerOptions);
    
            createAndSendOffer(signaling, peerConnection);

            peerConnection.onicecandidate = (iceEvent) => {
                if (iceEvent && iceEvent.candidate) {
                    signaling.send(JSON.stringify({
                        type: MESSAGE_TYPE.IceCandidate,
                        payload: iceEvent.candidate,
                    }));
                }
            };
    
            peerConnection.onconnectionstatechange = (state ) => {
                console.log(peerConnection.connectionState);
            };
    
            return peerConnection;
        };

const createAndSendOffer = async (signaling, peerConnection) => {
        const offer = await peerConnection.createOffer();
        await peerConnection.setLocalDescription(offer);
        signaling.send(JSON.stringify({ type: MESSAGE_TYPE.SessionDescription, payload: offer }));
    };

                
Juan Gil
  • 21
  • 1
  • 4
  • one candidate may be sufficient if the connection gets established. You can't make any assumptions about the number of candidates you gather. – Philipp Hancke Sep 03 '21 at 08:46
  • Thanks. I have checked it out with another code and it still gives me one candidate only. – Juan Gil Sep 05 '21 at 15:46

0 Answers0