WebRTC connectiong only send one candidate

140 Views Asked by At

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 }));
    };

                
0

There are 0 best solutions below