Broadcast a message to all sockets connected to the server (or any server in the cluster, if you have a multi-server deployment using Redis).
sails.sockets.blast(data);
Or:
sails.sockets.blast(eventName, data);
sails.sockets.blast(data, socketToOmit);
sails.sockets.blast(eventName, data, socketToOmit);
Argument | Type | Details | |
---|---|---|---|
1 | eventName | Optional. Defaults to 'message' . |
|
2 | data | The data to send in the message. | |
3 | socketToOmit | Optional. If provided, the socket associated with this socket request will not receive the message blasted out to everyone else. Useful when the broadcast-worthy event is triggered by a requesting user who doesn't need to hear about it again. |
In a controller action...
sails.sockets.blast('user_logged_in', {
msg: 'User #' + req.session.userId + ' just logged in.',
user: {
id: req.session.userId,
username: req.session.username
}
}, req);
- Be sure and check
req.isSocket === true
before passing inreq
to this method. For the socket to be omitted, the currentreq
must be from a socket request, not just any HTTP request.