socket.on() event is triggering twice. #3945
Unanswered
rajpurohityogesh
asked this question in
Q&A
Replies: 1 comment 2 replies
-
In most cases, it means the event handler was registered twice. Did you register the event handler in the socket.on("connect", () => {
// BAD, will be registered every time the socket reconnects
socket.on("receiving returned signal", () => {
// ...
});
});
// GOOD
socket.on("receiving returned signal", () => {
// ...
});
Reference: https://socket.io/docs/v4/client-socket-instance/#connect |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello, community
I am facing an issue in my web meet project in which I used a simple-peer library to create peer and socket.io library to share data. So the issue is that the last event is emitted from the server to a particular socket client. That is executing twice on the client side.
Server side event emitting:
io.to(payload.callerID).emit('receiving returned signal', { signal: payload.signal, id: socket.id });
Client-Side even listening:
user.socket.on("receiving returned signal", async payload => {
console.log("Getting receiving returned signal event");
const item = peersRef.current.find(p => p.peerID === payload.id);
item.peer.signal(payload.signal);
});
If anyone has any clue please help!!!!
Beta Was this translation helpful? Give feedback.
All reactions