Client events
Client events let one client send an event straight to the other clients on a channel, without a round trip through your server. They suit things like typing indicators and cursor positions.
Turn them on
Client events are off by default. Switch on Client events in your app's Settings tab.
Send one
js
const channel = pusher.subscribe("private-room-1");
channel.bind("client-typing", (data) => console.log(data.user, "is typing"));
// Only after the subscription has succeeded:
channel.bind("pusher:subscription_succeeded", () => {
channel.trigger("client-typing", { user: "Ada" });
});Rules
- The event name must start with
client-. - The client must already be subscribed to the channel.
- Use them on private or presence channels. The Pusher protocol only defines client events there, and your authorization endpoint is what makes the channel trustworthy.
- The data must fit your app's maximum event size (10 KB on every plan today), and the event name must be 200 characters or fewer.
- Each connection can send a limited number per second, set by your plan (Client events per second in Limits and quotas).
- The sender does not receive its own event back.
A client event that breaks a rule is dropped and the sender gets a pusher:error with code 4301 and a message saying why, see Errors and close codes.
Treat them as untrusted
Your server does not see client events and cannot validate them. Anyone allowed on the channel can send any data under a client- name, so do not use them for anything that must be trusted (payments, permissions, authoritative state). Send those through your server's publish call instead.
Pausing an app
Pausing an app (or a billing or quota pause) refuses new connections and server-side publishing, but clients that are already connected can keep sending client events to each other until they reconnect.