Edit Page

.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);

Usage

#
Argument Type Details
1 roomName String 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 Function? 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).

Example

#

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();

  });
}

Notes

#
  • 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.

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