sails.sockets.subscribeToFirehose()
Subscribe to the “firehose”, which (while running in the development environment) broadcasts messages about all model events.
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
// Controller actionenableDebugMode: function(req, res) {if (!req.isSocket) return res.badRequest();sails.sockets.subscribeToFirehose(req.socket);return res.ok();}
Notes
- You can also subscribe to the firehose using only client-side code by making a socket GET request to
/firehose(only enabled whenprocess.env.NODE_ENV==='development')- The phrase “request socket” here refers to an application-layer WebSocket/Socket.io connection.
req.socketalso exists for HTTP requests, but it refers to the underlying TCP socket at the transport layer, which is different. Be sure and ensurereq.isSocket == truebefore usingreq.socketwith this method.
