Can I manually unsubscribe clients from my server?

The short answer is no. The long answer is...

You can of course include logic in your clients so that you can tell them to unsubscribe themselves (`pusher.unsubscribe("some-channel")`), however this doesn't protect agains malicious clients who might want to continue to listen in on a channel longer than you would like them to. A workaround for this is the following

  • Have each client subscribe to a unique private channel, for their ears only.
  • Send any events destined for a particular client on their unique private channel.

Now if you wish to stop a client listening in on events, that is as simple as stopping sending them any – it doesn't matter if they stay subscribed since they won't overhear any events that they shouldn't.

You can simulate traditional mutiple-client channels by

  • Keeping a list of clients for each of your virtual channels.
  • Every time you want to send an event to some virtual channel, look at the list of clients, and send the event on each of their unique private channels.
  • "Unsubscribing" a client from this channel is then just a case of removing their name from the virtual channel members list.
Was this article helpful?
2 out of 2 found this helpful
Haven't found what you were looking for?
Submit a ticket