Add event when member is removed from presence channels
This version brings:
- added
pusher:member:removed
event - updated unsubscribe to only remove own callbacks, so if other clients are 'connected' theirs stay intact
To listen for this event (and others for members), you can do something like this:
it("should emit presence-channel events", async () => {
const client = createClient({ id: "my-id" });
const channel = client.subscribe("presence-channel");
const listener = jest.fn();
/**
* On bind, pusher:subscription_succeded will trigger
* for the client subscribing. Other clients will be
* notified via pusher:member_added as below.
*/
await channel.bind("pusher:subscription_succeeded", listener);
expect(listener).toHaveBeenCalledTimes(1);
/**
* Create and subscribe a new client that will trigger the
* pusher:member_added event. This only gets triggered for
* clients are not the client subscribing
*/
channel.bind("pusher:member_added", listener);
const otherClient = createClient({ id: "your-id" });
await otherClient.subscribe("presence-channel");
expect(listener).toHaveBeenCalledTimes(2);
/**
* Unsubscribe the otherClient to trigger pusher:member_removed.
* This only gets triggered for clients that are not the client
* unsubscribing.
*/
channel.bind("pusher:member_removed", listener);
await otherClient.unsubscribe("presence-channel");
expect(listener).toHaveBeenCalledTimes(3);
});