Best Performance - emit to sockets via a loop or rooms

后端 未结 2 1870
挽巷
挽巷 2021-01-22 00:20

We currently have a chat app whereby when emitting messages out to the appropriate users (could be 1 or several depending how many are in the conversation) we loop through all s

2条回答
  •  [愿得一人]
    2021-01-22 00:50

    I would use Socket.io rooms to accomplish what you want to do.

    Server side, adding a client to a chat room:

    socket.join('some room');
    

    Then I would use socket.to('some room').emit for a sender message to be sent to all participants in the room.

提交回复
热议问题