View our GitHub

Please visit sails-docs on GitHub to view documentation on your mobile device.

Edit Page

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

We wrote a book!

Get early access to the book
with promotion code: mcneildoc

Get the Book