Channels and events
Channel types
Section titled “Channel types”| Prefix | Who can subscribe | Use it for |
|---|---|---|
(none), e.g. news |
Anyone with your key | Public updates |
private- |
Clients your server authorizes | Per-user or per-team data |
private-encrypted- |
Clients your server authorizes; payloads are end-to-end encrypted | Sensitive data |
presence- |
Clients your server authorizes, with user info | “Who’s online”, member lists |
Channel names can use letters, numbers and _ - = @ , . ;, up to 200 characters.
Authorizing private and presence channels
Section titled “Authorizing private and presence channels”When a client subscribes to a private- or presence- channel, pusher-js calls your auth endpoint. Sign the request with your server library:
// Express exampleapp.post('/pusher/auth', (req, res) => { const { socket_id, channel_name } = req.body; // check the signed-in user may join channel_name, then: const auth = channel_name.startsWith('presence-') ? pusher.authorizeChannel(socket_id, channel_name, { user_id: req.user.id, user_info: { name: req.user.name } }) : pusher.authorizeChannel(socket_id, channel_name); res.send(auth);});Presence
Section titled “Presence”Presence channels tell every member who else is there: pusher:subscription_succeeded gives the current members, then pusher:member_added and pusher:member_removed follow as people join and leave. A user with several tabs open counts once. Up to 100 members per presence channel.
Client events
Section titled “Client events”Turn on Client events in the app’s settings to let clients send events straight to each other (typing indicators, cursors). The event name must start with client-, and they work on private and presence channels only. Each connection can send up to 10 client events a second.
Sending to one user
Section titled “Sending to one user”After a client signs in (pusher.signin() with your server’s authenticateUser), your server can message every connection of that user with pusher.sendToUser(userId, 'event', data) or disconnect them with terminateUserConnections(userId).
Message size
Section titled “Message size”Event data can be up to 10 KB. A trigger can go to up to 100 channels, and a batch can hold up to 10 events.