Guide
Private Channels and Presence After Reconnect


Compare Ably and Pusher Channels for private room access, multi-tab presence, and reconnects. Learn when to replace a roster and when to reload missed data.
Contents
Contents
Keep Pusher Channels if your app already authorizes room subscriptions and needs a list of signed-in users. Replace that list on every successful presence subscription. Choose Ably if you need permissions per channel operation, presence per connection, or channel resume with a signal that tells you when message continuity was lost. With either client, plan how to reload durable room data when you cannot account for the events the client missed.
Quick decision
| Requirement | Ably | Pusher Channels |
|---|---|---|
| Restrict who can join the room | Issue a token scoped to the channel and allowed operations. | Sign the requested private- or presence- subscription for the current socket after checking room access. |
| Show who's here | Explicitly enter presence. Read a synchronized roster keyed by clientId and connectionId. | Subscribe to a presence- channel. Read the member list keyed by user ID. |
| Keep a user visible when they close one of several tabs | Group the remaining connections under the same clientId. | The service reports when the user's first connection joins and last connection leaves. |
| Rebuild after a disconnect | Check channel continuity and use presence.get() for the synchronized roster. | Use the members payload from the next pusher:subscription_succeeded as a replacement roster. |
For a wider choice between hosted pub/sub and running a socket server, see the realtime library comparison and the Node.js WebSocket library guide.
Authorize the same private room
Start both implementations with the same server-side check. Read the signed-in identity from your session, resolve the requested room to its canonical channel name, and check that the user still has access. Use the session account ID as the presence identity. Treat the room name and any identity the browser sends as input to validate.
Ably issues an identity and a capability grant
The current browser client uses createClient() from @ably/pubsub-device. Code that already imports ably uses the earlier package and has a separate SDK migration to plan. The fixture below uses the current device package. Ably SDK migration guide.
Configure authUrl or authCallback so the device SDK can fetch and renew a token. For a member who can read room messages and appear in the roster, sign a JWT with the session account ID in x-ably-clientId. Scope x-ably-capability to the exact room, such as room:orchid. Grant message-subscribe to receive messages, presence-subscribe to read the roster, and presence to enter, update or leave. A client that only watches the roster needs no presence capability. Keep the signing key on the server and recheck the session and room policy each time you issue a token. Token authentication, JWT claims, capabilities.
Pusher Channels signs a subscription for the current socket
Pass the public app key to pusher-js and set channelAuthorization.endpoint. The AJAX request sends socket_id and channel_name to your server. For events without a roster, authorize a name such as private-room-orchid. For a room with events and a roster, use presence-room-orchid. That presence channel already requires authorization. Channel authorization, presence channels.
On the server, the pusher package's authorizeChannel() signs the socket ID and channel name. In the presence flow used here, supply user_id from the session as the third argument's user data. The response also includes signed channel_data for that presence subscription. The separate Pusher user authentication flow can also provide the presence identity. Keep the app secret on the server, return a denial for unauthorized rooms and show pusher:subscription_error separately from an empty room. Authorization signatures, subscription errors.
Restore presence after reconnect
Ably. Subscribe to presence changes, enter when the user should appear, and take the initial roster from presence.get(). The default waits for the SDK's presence set to synchronize. Keep members by the pair of clientId and connectionId, then group by clientId if the UI shows people. Leaving on one connection removes that connection from the group. Presence API, presence identity.
The Ably SDK attempts to resume after a network drop. Watch the channel's attached and update events. With a prior attachment, resumed: false means message continuity was lost. On a fresh connection, the first attachment has resumed: false. Load the initial room state then. After a loss of continuity, use a synchronized presence read and reload any durable data the room needs. Ably can re-enter members previously entered by the same SDK instance when it resynchronizes its presence set. A fresh instance recovering a previous connection needs to enter explicitly. Channel states, presence recovery.
Pusher Channels. Mark the displayed list stale when the connection drops. The client resubscribes to its channels when it reconnects. Wait for pusher:subscription_succeeded on the presence channel and copy members.each() into a fresh map keyed by member ID. Apply pusher:member_added and pusher:member_removed to that map. Replacing the entire map removes users who left during the gap. The connection's connected event can arrive before the room is authorized and ready. Presence events, client resubscription code.
Keep the member list separate from chat messages, acknowledgments or document changes. For ordinary Pusher Channels events, a new subscription gives you live delivery going forward. Use your application endpoint for missed durable events. Ably resume can preserve message continuity, but a failed resume calls for your application's recovery path. Fetch a snapshot with a server revision after subscribing, queue events while it loads, and apply newer events from the same room. Ignore a late snapshot from an older room or connection attempt. Pusher's message history example, Ably connection recovery.
Methodology
A loopback fixture ran @ably/pubsub-device 3.3.0 and pusher-js 8.6.0 through their Node-targeted builds on Bun. The Pusher authorization endpoint used the pusher 5.3.4 server signer. The fixture used synthetic credentials and scripted HTTP and WebSocket responses.
| Scenario | Local observation |
|---|---|
| Attempt to join an unauthorized room | The Ably fixture's token endpoint denied the other room, and the device client rejected its attach when the mock returned a channel authorization error. Pusher Channels surfaced a subscription error after the auth endpoint denied the other room. |
| Remove a connection for a user with another open tab | The Ably client returned both connections for Sam initially and still returned Sam's remaining connection after the scripted leave. Pusher's first-join and last-leave behavior is documented service behavior. |
| Disconnect, then replace a stale member | The Ably client requested resume and handled a resumed attachment. A later simulated continuity loss triggered an update and the synchronized roster replaced Sam with Lee. Pusher reauthorized with the new socket ID, resubscribed, and the new members snapshot replaced Sam with Lee. |
Repeat these scenarios against your hosted app before switching. Open two tabs under the same account and a separate observer. Close one tab and check that the observer still sees the user. Put the observer offline, have a different user join and the remaining tab leave, then bring the observer back and compare its roster with a fresh observer. In Ably, exercise a reconnect that resumes and one that reports lost continuity. In Pusher Channels, verify authorization runs again and wait for the new room snapshot. Check that an unauthorized room remains inaccessible in both cases. The loopback run verified client handling with scripted inputs. Hosted token enforcement, timing, message replay and first-join or last-leave behavior were outside that run.
If maintaining the room's document state is the larger job, compare Liveblocks, PartyKit and Hocuspocus before building the state layer on pub/sub.