.getRoomName()
获取给定记录的 PubSub “房间” 的名称。
Something.getRoomName(id);
参数 | 类型 | 详情 | |
---|---|---|---|
1 | id | 或 |
要获取其 PubSub 房间名称的记录的 ID(主键值)。 |
// 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();
});
}