Unenroll the requesting client socket from this model's "class room" for this model, meaning it will no longer receive broadcasts every time publishCreate()
is called on this model, and also no longer be subscribed to those new records.
Something.unwatch(req);
Argument | Type | Details | |
---|---|---|---|
1 | req |
The incoming socket request (req ). |
See
.watch()
for more information.
Let's say we have a mobile app or single-page web app where new public pictures of cute animals are displayd in real time when you are viewing the dashboard. Since there is no page refresh, the client-side socket remains connected; so when you view your user settings, as an optimization our app might hit a special endpoint that uses .unwatch()
to temporarily stop receiving new animal pictures:
// We can only do this for socket requests.
// (to accomplish the same functionality using raw socket ids, see `sails.sockets.leave()`)
if (!req.isSocket) {
return res.badRequest('Only a socket request can use this endpoint!');
}
// Temporarily disable the cute animal picture firehose.
Photo.unwatch(req);
return res.ok();
- Be sure and check
req.isSocket === true
before passing inreq
to refer to the requesting socket. The providedreq
must be from a socket request, not just any old HTTP request.unwatch()
will only work when the request is made over a socket connection (e.g. usingio.socket.get()
), not over HTTP (e.g. usingjQuery.get()
).