Answers for "create room socket io"

0

create room socket io

// client side code
var socket = io.connect();
socket.emit('create', 'room1');

// server side code
io.sockets.on('connection', function(socket) {
  socket.on('create', function(room) {
    socket.join(room);
  });
});
Posted by: Guest on August-28-2021
0

rooms in socket io

io.on('connection', socket => {
  socket.join('some room');
});
//And then simply use to or in (they are the same) when broadcasting or emitting:

io.to('some room').emit('some event');
//You can emit to several rooms at the same time:

io.to('room1').to('room2').to('room3').emit('some event');
//In that case, an union is performed: every socket that is at least in one of the rooms will get the event once (even if the socket is in two or more rooms).
//You can also broadcast to a room from a given socket:

io.on('connection', function(socket){
  socket.to('some room').emit('some event');
});
Posted by: Guest on October-16-2020
0

create room socket io

io.sockets.in(room).emit('event', data);
Posted by: Guest on August-28-2021
0

create room socket io

socket.on('create', function (room) {
  socket.join(room);
});
Posted by: Guest on August-28-2021

Browse Popular Code Answers by Language