Skip to content

Implement Rooms #7

@gil0mendes

Description

@gil0mendes

Within each namespace, you can also define arbitrary channels that sockets can join and leave.

Joining and leaving

You can call join to subscribe the socket to a given channel:

socket.on('connection', (socket) {
  socket.join('funny_room');
});

And then simply use to when emitting:

socket.to('funny_room').emit('some event');

To leave a channel you call leave in the same fashion as join.

Default room

Each Socket in Connexa is identified by a random, unguessable, unique identifier Socket#id. For your convenience, each socket automatically joins a room identified by this id.

This makes it easy to broadcast messages to other sockets:

server.on('connection', (socket) {
  socket.on('say to someone', (from, msg) {
    socket.to(from.id).emit('my message', msg);
  });
});

Disconnection

Upon disconnection, socket leave all the channels they were part of automatically, and so specially teardown is needed on your part.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions