Edit Page
sails.sockets.blast()
Broadcast a message to all sockets connected to the server.
sails.sockets.blast(data);
Or:
sails.sockets.blast(eventName, data);
sails.sockets.blast(data, socketToOmit);
sails.sockets.blast(eventName, data, socketToOmit);
Usage
Argument | Type | Details |
---|---|---|
eventName | Optional. Defaults to 'message' . |
|
data | The data to send in the message. | |
socketToOmit | Optional. If provided, that request socket 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. |
Example
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.socket);
Notes
- 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 ensurereq.isSocket == true
before usingreq.socket
with this method.
Is something missing?
If you notice something we've missed or could be improved on, please follow this link and submit a pull request to the sails-docs repo. Once we merge it, the changes will be reflected on the website the next time it is deployed.
Reference
-
Application
-
Blueprint API
-
Command Line Interface
-
Configuration
-
sails.config.*
-
sails.config.blueprints
-
sails.config.cors
-
sails.config.csrf
-
sails.config.bootstrap
-
sails.config.connections
-
sails.config.globals
-
sails.config.i18n
-
sails.config.http
-
sails.config.policies
-
sails.config.routes
-
sails.config.models
-
sails.config.log
-
sails.config.session
-
sails.config.sockets
-
sails.config.views
-
sails.config.*
-
Request (`req`)
-
req.options
-
req.accepts()
-
req.acceptedLanguages
-
req.accepted
-
req.acceptedCharsets
-
req.acceptsCharset()
-
req.acceptsLanguage()
-
req.body
-
req.allParams()
-
req.cookies
-
req.fresh
-
req.get()
-
req.host
-
req.file()
-
req.ip
-
req.headers
-
req.is()
-
req.ips
-
req.isSocket
-
req.param()
-
req.method
-
req.path
-
req.params
-
req.protocol
-
req.secure
-
req.query
-
req.subdomains
-
req.signedCookies
-
req.socket
-
req.url
-
req.wantsJSON
-
req.xhr
-
req.options
-
Response (`res`)
-
Waterline (ORM)
-
WebSockets