[英]socket.io doesn't send to all room
I am using Socket.io with react to do a chat room, when a new user join the room i want to send an update to all clients.我正在使用 Socket.io 来做一个聊天室,当新用户加入聊天室时,我想向所有客户发送更新。
const updateDiscussionClients = room => {
let currentClients = RoomClients({room, io, connections})
console.log(currentClients); // printing correct data
console.log(io.sockets.adapter.rooms.get(room));
socket.to(room).emit('clients_discussion', currentClients)
}
socket.on("join_discussion", (data) => {
let room = 'room_' + data.id + data.name
socket.join(room)
updateDiscussionClients(room)
})
everything is working fine but the message received by old client, without the last one who一切正常,但老客户收到的消息,没有最后一个
output of the logs: output的日志:
[
{ name: 'Mohamad Zbib', id: '202100006' },
{ name: 'pu10', id: '10' }
]
Set(2) { 'pbKuaEdrfg7n83YyAAAD', '3QYOJCzlxxMOLquzAAAB' }
the event is received by pbKuaEdrfg7n83YyAAAD
, but 3QYOJCzlxxMOLquzAAAB
didn't receive it, he will receive if an update happened later事件由pbKuaEdrfg7n83YyAAAD
收到,但3QYOJCzlxxMOLquzAAAB
没有收到,如果以后有更新他会收到
is 3QYOJCzlxxMOLquzAAAB sender of that event, which will not receive? 3QYOJCzlxxMOLquzAAAB是那个事件的发送者,哪个不会收到?
socket.to("room1").emit(/*... */);
will send to all in room except sender.将发送给房间里的所有人,除了发件人。 io.in("room1").emit(/*... */);
will send to all in room将发送给房间里的所有人
Check this cheat sheet for more info查看此备忘单以获取更多信息
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.