Skip to content
Docs/Listening to Events
Docs/Events

Listening to Events

Event subscription bindings and Pusher Channels protocol wire frames.

Event Binding Mechanics

Clients can register event listeners at three distinct scoping levels:

1. Channel-Level Binding

Listens for broadcasts dispatched to a specific channel:

ts
const channel = pusher.subscribe('orders')

// Bind callback to specific event
channel.bind('order-created', (data: { orderId: string }) => {
  console.log('Order created:', data.orderId)
})

// Unbind a specific listener callback
channel.unbind('order-created', callbackFn)

// Unbind all callbacks for an event
channel.unbind('order-created')

// Unbind all callbacks on the channel
channel.unbind_all()

2. Global Connection Binding

Interprets all incoming events across all subscribed channels on the socket connection:

ts
pusher.bind_global((eventName: string, data: any) => {
  console.log(`Global event [${eventName}]:`, data)
})

3. User-Level Binding

Listens for user-targeted broadcasts dispatched via pusher.sendToUser(...). Requires prior connection-level authentication via pusher.signin():

ts
pusher.signin()

pusher.user.bind('notification', (payload: { title: string }) => {
  console.log('User notification:', payload.title)
})

Protocol Wire Frames vs SDK Events

Socketo distinguishes between raw WebSocket frames exchanged over the wire and client SDK synthesized events:

Event NameLevelDescriptionPayload Structure
pusher:connection_establishedWire & SDKConnection handshake successful{ socket_id, activity_timeout }
pusher_internal:subscription_succeededWireChannel subscription accepted{} or presence roster object
pusher:subscription_succeededSDKClient notification of subscriptionInitial channel metadata
pusher:subscription_errorSDKChannel subscription rejected{ error, status }
pusher_internal:member_addedWirePresence member joined{ user_id, user_info }
pusher:member_addedSDKPresence member joinedMember object
pusher_internal:member_removedWirePresence member vacated{ user_id }
pusher:member_removedSDKPresence member vacatedMember object
pusher:ping / pusher:pongWireHeartbeat liveness probe{}
pusher:errorWire & SDKProtocol or edge policy error{ code, message }

Protocol Error Structure

When a protocol violation or rate limit is reached, Socketo transmits a pusher:error event:

json
{
  "event": "pusher:error",
  "data": {
    "code": 4301,
    "message": "Rate limit exceeded"
  }
}
ts
pusher.bind('pusher:error', (err: { code: number; message: string }) => {
  console.error(`Socketo Protocol Error [${err.code}]: ${err.message}`)
})