Skip to content

Conversation

@PurnAnrup
Copy link

@hkirat I could see the main issue here is when the first user is joining he is emiting the description with out checking if the second user is present and it was being lost.

and second user stream was able to see the stream because at the time he joined there is already an user present and he could make an connection

Fix updated ref in video.jsx and update logic in meetingPage.jsx in a way the user can only click once preventing multiple instance of RTCPeerConnection and only emiting when the second user is joined.

              onClick={() => {
                setIsClicked(true);
                socket.emit("join", {
                  roomId,
                });
                // sending pc
                socket.on("userJoined", ({ startMeet }) => {
                  console.log("2 users jined");
                  let pc = new RTCPeerConnection({
                    iceServers: [
                      {
                        urls: "stun:stun.l.google.com:19302",
                      },
                    ],
                  });
                  pc.onicecandidate = ({ candidate }) => {
                    socket.emit("iceCandidate", { candidate });
                  };
                  pc.addTrack(videoStream.getVideoTracks()[0]);

                  pc.onnegotiationneeded = async () => {
                    try {
                      await pc.setLocalDescription(await pc.createOffer());
                      console.log(pc.localDescription);
                      socket.emit("localDescription", {
                        description: pc.localDescription,
                      });
                    } catch (err) {
                      console.error(err);
                    }
                  };

                  socket.on("remoteDescription", async ({ description }) => {
                    await pc.setRemoteDescription(description);
                  });
                  socket.on("iceCandidateReply", ({ candidate }) => {
                    pc.addIceCandidate(candidate);
                  });
                  setMeetingJoined(true);
                });
              }}
              disabled={isClicked}
              variant="contained"
            >
              Join meeting
            </Button>```
            
            for index.js emiting an event when two users joined the room
            
            ```if (rooms[roomId].users.length === 2) {
      let otherUsers = rooms[roomId].users;
      otherUsers.forEach((otherUser) => {
        io.to(otherUser).emit("userJoined", {
          startMeet: true,
        });
      });
    }```
    
   
            
             

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant