question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Sockets not joining rooms

See original GitHub issue

You want to:

  • report a bug
  • request a feature

Current behaviour

After updating my socket.io from 1.x to ^2.1.1 my sockets are not joining any rooms anymore.

Steps to reproduce (if the current behaviour is a bug)

async socketJoinRoom(socket: any, room: string, userId: number) {
        await socket.join(room)

        // tried this to log all the clients in the room, the room ID is correct but "clients" array is empty
        this.io.in(room).clients((err, clients) => {
            console.log(room)  // loggs the correct room
            console.log(clients) // loggs an empty array
        })
        catSystem.info("User "+userId+" joined socket room '"+room+"'")
    }

also this is not working:

  this.io.in('myroom').emit('test', {})

Expected behaviour

I expected to get a list of sockets in the room and that messages are emitted to the room.

Note: Emitting to a single socket works fine.

Setup

  • OS: Ubuntu 18.04
  • browser: Chrome Version 69.0.3497.81 (64 Bit)
  • socket.io version: " ^2.1.1"
  • NodeJs version v10.9.0

Any suggestions here?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:13 (1 by maintainers)

github_iconTop GitHub Comments

19reactions
mpopedevelopercommented, Sep 26, 2018

Will this be fixed soon? My Projects depends largely on socket rooms…So if I cannot use them with socket.io anymore i need to refactor my code soon to use pure WebsocketApi…please answer

Are You using a namespace? I faced this same problem as stated above and was able to make mine work by changing

io.to.(room)

to

io.of(namespace).to(room)

7reactions
GolamKibriaSajibcommented, Sep 14, 2018

i also face this problem

Read more comments on GitHub >

github_iconTop Results From Across the Web

socket.join does not work (socket.io) - Stack Overflow
join calls are doing nothing. After calling socket.join, and then listing the rooms the socket is in, the socket is only connected to...
Read more >
Rooms | Socket.IO
A room is an arbitrary channel that sockets can join and leave. It can be used to broadcast events to a subset of...
Read more >
Socket.IO - Rooms - Tutorialspoint
You can call the join method on the socket to subscribe the socket to a given channel/room. For example, let us create rooms...
Read more >
Chat Rooms With Socket.io - Medium
Rooms : A server-side-only concept that lets you create a room inside ... The only difference is socket.in will not include the sender, ......
Read more >
Learn Socket.io In 30 Minutes - YouTube
Socket.io is an amazing library for client/server communication, but it can be a bit confusing to get started with. In this video I...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found