Back to Sails

`.leaveAll()`

docs/reference/websockets/sails.sockets/sails.sockets.leaveAll.md

12.12.20001.5 KB
Original Source

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

javascript
sails.sockets.leaveAll(roomName, cb);

Usage

ArgumentTypeDetails
1roomName((string))The room to evactuate. Note that this room's members will be forced to leave all of their rooms, not just this one.
2cb((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:

javascript
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.
<docmeta name="displayName" value=".leaveAll()"> <docmeta name="pageType" value="method">