Socket.IO emitting the event on the wrong Session

20 Views Asked by At

Newbie programmer here. Need some help on a mini-project for an ongoing job assessment.

The project is a Video Chat application that uses JavaScript, Socket.IO, and WebRTC concepts. The socket.id is being used as some sort of unique code to connect to other users / sessions.

I have 2 sessions of the application open for testing purposes.

The feature being tested is the "Reject" button, when one user (session) tries to connect another.

Scenario: (Session A tries to connect with Session B) It doesn't matter if the type of request is Video Call or Chat, when I click the "Reject" button, it seems like socket.io is emitting the event on Session B (the same session that's given a choice to either Accept/Reject the request), leaving Session A (the session that's trying to connect) stuck with a connection attempt dialog box.

Screenshot during the connection attempt: Session A attempting to connect to Session B Session B receives the incoming connection request

Screenshot of Session B rejecting the connection attempt Session B receiving the dialog box that Session A should have received Session A stuck on the connection attempt screen

This is the link to my project repository: Meet-n-Greet Video Chat App

I think the problem is coming from the function "sendPreOfferResponse()" from "webRTChandler.js" function "sendPreOfferResponse()" from "webRTChandler.js" The structure of the data it passes is:

const data = {
  callerSocketId: connectedUserDetails.socketId,
  preOfferResponse,
};

But the variable "connectedUserDetails" was initially defined without any value. So in the event listener on "app.js", it is only receiving the data as:

const data = {
  preOfferResponse
};

I tried assigning "callerSocketId" key with the value of "socket.id", but it gets the socket.id of the current session, not the session that's trying to connect. "callerSocketId" key assigned with the value of "socket.id"

How can I get the specific socket.id of the session that's attempting to connect??

0

There are 0 best solutions below