sails.sockets.subscribeToFirehose()

Subscribe to the “firehose”, which (while running in the development environment) broadcasts messages about all model events.

  1. sails.sockets.subscribeToFirehose(socket);

Usage

Argument Type Details
1 socket ((Socket)) A request socket (WebSocket/Socket.io) object
e.g. req.socket.

The firehose publishes messages using the “firehose” event. By default, messages will be published when a model instance is created, destroyed, or updated, or when an associated collection is added to or removed from. The message content is similar to that for the PubSub methods like publishUpdate, publishCreate, etc.

Example

  1. // Controller action
  2. enableDebugMode: function(req, res) {
  3. if (!req.isSocket) return res.badRequest();
  4. sails.sockets.subscribeToFirehose(req.socket);
  5. return res.ok();
  6. }

Notes

  • You can also subscribe to the firehose using only client-side code by making a socket GET request to /firehose (only enabled when process.env.NODE_ENV==='development')
  • The phrase “request socket” here refers to an application-layer WebSocket/Socket.io connection. req.socket also exists for HTTP requests, but it refers to the underlying TCP socket at the transport layer, which is different. Be sure and ensure req.isSocket == true before using req.socket with this method.