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.
Within each namespace, you can also define arbitrary channels that sockets can
joinandleave.Joining and leaving
You can call
jointo subscribe the socket to a given channel:And then simply use
towhen emitting:To leave a channel you call
leavein the same fashion asjoin.Default room
Each
Socketin 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:
Disconnection
Upon disconnection, socket
leaveall the channels they were part of automatically, and so specially teardown is needed on your part.