Skip to content

Version 4 io.sockets.connected returns undefined #3993

Discussion options

You must be logged in to vote

The connected attribute was indeed removed in [email protected].

See here: https://socket.io/docs/v4/migrating-from-2-x-to-3-0/#Namespace-connected-is-renamed-to-Namespace-sockets-and-is-now-a-Map

You can either:

  • use the sockets attribute instead
if (io.sockets.sockets.has(target.socketId) {
  io.sockets.sockets.get(target.socketId).leave(room);
}

Reference: https://socket.io/docs/v4/server-api/#namespace-sockets

  • or use the socketsLeave method (preferred way, as it works in a multi server setup)
io.in(target.socketId).socketsLeave(room);

Reference: https://socket.io/docs/v4/server-api/#server-socketsLeave-rooms

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@taylordwright44
Comment options

@darrachequesne
Comment options

Answer selected by darrachequesne
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants