简体   繁体   English

Socket.io-服务器监听特定房间

[英]Socket.io - Server listen to specific room

as mentioned in Socket.io Doc about rooms - i know that the server can move sockets to a specific room and send an event to that specific room 如Socket.io文件中有关房间的内容所述 -我知道服务器可以将套接字移至特定房间并将事件发送到该特定房间

transfer socket to a room : 将插座转移到房间:

io.on('connection', (socket)=>{
  socket.join('roomId');
});

emit event to sockets in that room : 向该房间的套接字发出事件:

io.to('roomId').emit('some event');

but i can't find a way that the server will listen to event coming only from a specific room , something like: 但是我找不到服务器只能监听来自特定房间的事件的方式,例如:

io.in('roomId').on('someevent',(socket)=>{....})

Socket.io has no function for this. Socket.io没有为此功能。 You will have to listen for everyone on that event and check the socket's joined rooms array. 您将必须在该事件上倾听每个人的声音,并检查套接字的连接房间阵列。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM