这就是我现在正在尝试做的。 idk如何实际检查的主要问题是房间中存在插座。有什么想法吗?
var sockets = [{userId: 1, socketId: socketId}];
io.toUser = (userId) => {
var socket = sockets.find(e => e.userId== userId);
var receiver = socket.socketId || null;
var emit = (a, b) => receiver ? io.to(`${receiver}`).emit(a, b) : null;
var notIn = (room) => {
if(/* here me should check is receiver in room */) receiver = null;
return { emit: emit };
};
return { notin: notin, emit: emit };
};
io.toUser(userId).notIn(room).emit('event name', data);