Understanding the Timing of .emit() After .join() in Socket.IO #5015
Unanswered
KishonShrill
asked this question in
Q&A
Replies: 1 comment 1 reply
-
Hi!
Hmm, this should not happen. Are you sure the client is listening to the 'match-found' event? |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Is it feasible to invoke the .emit() method immediately after calling the .join() method in Socket.IO?
While developing a Rock-Paper-Scissors game utilizing Socket.IO for real-time communication, I encountered an issue wherein newly joined players were not receiving notification messages upon joining a room. My intention was to promptly inform the joining player about their opponent's userID and display a "Match has been found" message. However, despite emitting the event within the join-room event listener, the notification was successfully dispatched to the opponent, while the newly joined player did not receive the opponent's userID or the match notification.
The relevant snippet of the code is as follows:
rooms[roomToJoin].length
is true toMAX_VALUE_PER_KEY
What could be the underlying reason for a newly joined socket failing to receive an emit event, despite the .emit() function being called after the .join() operation? Additionally, how can this issue be addressed to ensure that all players in the room receive the appropriate notifications promptly upon joining?
From what I understood while experimenting around the socket, it WILL receive the
.emit
function as long as it already has.join
on the start, but won't if it has just joined recently...For the complete code and further reference, please visit the following GitHub repository: Rock-Paper-Scissors Game Repository
Beta Was this translation helpful? Give feedback.
All reactions