如果不在socket.io的特定房间中,如何发出特定的套接字

时间:2018-08-21 19:42:59

标签: websocket socket.io emit chatroom

这就是我现在正在尝试做的。 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);

0 个答案:

没有答案