.leaveAll()
Unsubscribe all members of a room (e.g. chatroom7
) from that room and every other room they are currently subscribed to, except the automatic room associated with their socket ID.
sails.sockets.leaveAll(roomName, cb);
Argument | Type | Details | |
---|---|---|---|
1 | roomName | The room to evactuate. Note that this room's members will be forced to leave all of their rooms, not just this one. | |
2 | cb | An optional callback, which will be called when the operation is complete on the current server (see notes below for more information), or if fatal errors were encountered. In the case of errors, it will be called with a single argument (err ). |
In a controller action:
unsubscribeFunRoomMembersFromEverything: function(req, res) {
sails.sockets.leaveAll('funRoom', function(err) {
if (err) { return res.serverError(err); }
// Unsubscribed all sockets in "funRoom" from "funRoom".
// And... from every other room too.
return res.ok();
});
}
- In a multi-server environment, the callback function (
cb
) will be executed when the.leaveAll()
call completes on the current server. This does not guarantee that other servers in the cluster have already finished running the operation.