sails.sockets.subscribers()
Get the IDs of all sockets subscribed to a room.
sails.sockets.subscribers(roomName);
Usage
Argument | Type | Details | |
---|---|---|---|
1 | roomName | The name of the room whose socket ids should be retrieved. e.g. 'supportchat' |
Example
sails.sockets.subscribers('supportchat');
// => ['BetX2G-2889Bg22xi-jy', 'BTA4G-8126Kr32bi-za']
// Controller action
getRoomSubscribers: function(req, res) {
if (!req.isSocket) return res.badRequest();
if (!req.param('room')) return res.badRequest('No room
specified- please specify the name of the room whose subscribers you want to look up.');
var subscribers = sails.sockets.subscribers(room); return res.ok(require('util').format( 'The "%s" room currently has %d subscribers: ', req.param('room'), subscribers.length, subscribers )); } ``` -->
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