Sails.js + socket.io: Sending messages from server to clients

前端 未结 1 383
盖世英雄少女心
盖世英雄少女心 2021-01-06 01:24

I\'m attempting to set up a system with sails.js to have the server broadcast messages to a set of clients. Basically:

  1. A client in Group A sends an AJAX reques
相关标签:
1条回答
  • 2021-01-06 02:01

    The Sails way to do this would be to have a model backing your "Groups", and in a controller action have a socket subscribe to a group with Group.subscribe(groupId, req.socket). Then you can send messages to a specific group with Group.publish(groupId, data).

    You can also subscribe to an arbitrary room name in a controller using req.listen(groupId), and broadcast to that room with req.broadcast(roomName, data).

    This is all in the Sails documentation for working with Sockets!

    0 讨论(0)
提交回复
热议问题