Edit Page

.getRoomName()

Retrieve the name of the PubSub “room” for a given record.

Something.getRoomName(id);

Usage

#
Argument Type Details
1 id Number
or
String
The ID (primary key value) of the record to get the PubSub room name for.

Example

#
// On the server:

  subscribeAllBobWatchersToKaren: function (req, res) {

    // Look up all users named "bob" or "karen".
    User.find({name: ['bob', 'karen']}, function(err, users) {
      if (err) {return res.serverError(err);}

      // Get Bob's ID.  We'll assume there is only one Bob.
      var bobId = _.find(users, { name: 'bob' }).id;

      // Get Karen's ID.  We'll assume there is only one Karen.
      var karenId = _.find(users, { name: 'karen' }).id;

      // Subscribe all of Bob's sockets to Karen.
      sails.sockets.addRoomMembersToRooms(User.getRoomName(bobId), User.getRoomName(karenId));

      return res.send();
    });

  }

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 repo. Once we merge it, the changes will be reflected on the website the next time it is deployed.

Reference

Reference