Protocol reference

Compare Pusher-compatible Protocol V1 with Sockudo-native Protocol V2.

8 min read
View .mdEdit on GitHub

Sockudo serves two WebSocket protocols from the same server and the same port. Protocol V1 is a byte-compatible Pusher protocol for existing clients; Protocol V2 is Sockudo’s native protocol and adds continuity metadata, recovery, rewind, filtering, and mutable messages. Use this page to look up frame names, payload shapes, and the boundary between the two.

Negotiating a protocol

The protocol is chosen per connection by the protocol query parameter on the WebSocket upgrade URL, GET /app/{appKey}. Only the exact value 2 selects Protocol V2; an omitted or any other value selects Protocol V1, so unmodified Pusher clients always land on V1.

wss://realtime.example.com/app/app-key?protocol=2&format=msgpack
Query parameterApplies toMeaning
protocolBoth2 selects Protocol V2. Anything else, including omission, selects Protocol V1.
formatV2Wire format: json (default), msgpack or messagepack, protobuf or proto. An unknown value rejects the upgrade with 400. V1 always uses JSON and ignores this parameter.
echo_messagesV2false stops the connection receiving its own publishes. Honored only when [echo_control].enabled.
append_modeV2Delivery mode for mutable-message appends: delta (default) or full. An unknown value rejects the upgrade with 400.
append_rollup_windowV2AI Transport append rollup window in milliseconds. Must be one of 0, 20, 40, 100, 500 and within the configured rollup bounds, otherwise the upgrade is rejected with 400.
tokenV2Capability-token JWT used instead of signed channel auth.
client, versionBothClient library name and version, accepted for Pusher compatibility.

See HTTP endpoints for the full upgrade contract.

Protocol V1

Protocol V1 is Pusher-compatible. It preserves familiar event prefixes, channel names, subscription flows, auth response shapes, and HTTP API semantics.

Use V1 for:

  • existing pusher-js clients
  • Laravel Echo migrations
  • backend SDK compatibility
  • minimal drop-in deployments

Typical V1 connection and event frames keep the Pusher names and payload conventions. Note that V1 data is a JSON-encoded string, exactly as Pusher sends it:

{
"event": "pusher:connection_established",
"data": "{\"socket_id\":\"123.456\",\"activity_timeout\":120}"
}
{
"event": "order.created",
"channel": "orders",
"data": "{\"id\":\"ord_123\",\"total\":4200}"
}

Keep V1 payloads compatible with existing clients. Do not require V2-only fields such as message_id, serial, stream_id, tags, deltas, or annotation metadata when the recipient negotiated V1.

Protocol V2

Protocol V2 is Sockudo-native and uses sockudo: system event prefixes. Serials, message IDs, and connection recovery are native to V2 rather than opt-in extensions.

Use V2 for:

  • message_id
  • serial
  • stream_id
  • connection recovery
  • subscribe-time rewind
  • delta compression
  • tag filtering
  • durable history
  • mutable messages
  • annotations
  • push-helper client workflows through backend proxies

V2 keeps the event/channel shape familiar, then adds metadata required for continuity and durable workflows:

{
"event": "order.created",
"channel": "orders",
"data": { "id": "ord_123", "total": 4200 },
"message_id": "msg_01HX6J2P5N0Z9E",
"stream_id": "orders",
"serial": 42,
"tags": { "status": "paid", "region": "eu" },
"extras": {
"headers": { "tenant": "acme" }
}
}

Use V2 when the client needs to reconnect without guessing what it missed, rewind a subscription from known history, filter by event, tags, or message content, receive deltas, or render mutable message state.

System events

Every system event has one canonical name. On the wire it carries the pusher: or pusher_internal: prefix for V1 and the sockudo: or sockudo_internal: prefix for V2. The server accepts either prefix on inbound frames, and always replies with the prefix of the connection’s protocol.

Canonical nameDirectionV1V2Purpose
connection_establishedServer to clientYesYesAssigns the socket_id and announces activity_timeout.
errorServer to clientYesYesReports a protocol, auth, or limit error with a numeric code.
ping / pongBothYesYesApplication-level heartbeat.
subscribe / unsubscribeClient to serverYesYesJoin or leave a channel.
subscription_succeededServer to client (internal)YesYesConfirms a subscription; presence channels include the member list.
subscription_errorServer to client (internal)YesYesRejects a subscription.
member_added / member_removedServer to client (internal)YesYesPresence membership changes.
signin / signin_successBothYesYesUser authentication.
cache_missServer to clientYesYesCache channel had no cached event on subscribe.
presence_updateBothNoYesUpdate the current member’s presence data.
auth / auth_successBothNoYesRefresh a capability token on a live connection.
token_expiredServer to clientNoYesCapability token expired or was revoked.
resume / resume_success / resume_failedBothNoYesConnection recovery.
rewind_completeServer to clientNoYesSubscribe-time rewind finished.
channel_historyBothNoYesRead durable history over the WebSocket.
message.*Server to clientNoYesMutable message actions such as sockudo:message.update, sockudo:message.delete, and sockudo:message.append.

Connection established

Sent once, immediately after the upgrade. Store socket_id; backend publishes pass it as socket_id to suppress echo to the originating connection.

{
"event": "sockudo:connection_established",
"data": "{\"socket_id\":\"123.456\",\"activity_timeout\":120}"
}

Subscribe and subscription succeeded

The client subscribes to a channel. Private and presence channels include the signed auth string, and presence channels add channel_data. V2 subscriptions may also carry filter, rewind, and delta options.

{
"event": "sockudo:subscribe",
"data": {
"channel": "private-orders",
"auth": "app-key:3f2a9c..."
}
}

The server confirms the subscription. For presence channels, data carries the current presence object with ids, hash, and count.

{
"event": "sockudo_internal:subscription_succeeded",
"channel": "private-orders",
"data": "{}"
}

When recovery is enabled, V2 acknowledgements also include a stream_id and serial. Successful V2 subscriptions may include attach_serial when durable history is enabled for the channel. See Protocol V2 metadata.

Errors

error frames carry a numeric code and a human-readable message, plus the channel when the error relates to one. See Error codes for the code ranges.

{
"event": "pusher:error",
"data": { "code": 4009, "message": "Connection is unauthorized" }
}

Presence membership

Presence channels broadcast membership transitions. Sockudo emits member_added on a user’s first connection and member_removed on their last disconnect, not once per socket.

{
"event": "sockudo_internal:member_added",
"channel": "presence-room-1",
"data": "{\"user_id\":\"user-42\",\"user_info\":{\"name\":\"Ada\"}}"
}

Capability-token refresh

V2 clients that connected with ?token= refresh before expiry by sending sockudo:auth with a new token. The refreshed token must keep the same client_id.

{ "event": "sockudo:auth", "data": { "token": "eyJhbGciOiJIUzI1NiIs..." } }
{
"event": "sockudo:auth_success",
"data": { "client_id": "user-42", "jti": "tok_9f1c", "exp": 1710003600 }
}

When a token expires the server sends token_expired with code 40142 and reason expired; a revoked token produces code 40160 and reason revoked.

{ "event": "sockudo:token_expired", "data": { "code": 40142, "reason": "expired" } }

Connection recovery

After reconnecting, a V2 client sends its last known position per channel. channel_positions is the current form; the older channel_serials map of channel to serial is still accepted.

{
"event": "sockudo:resume",
"data": {
"channel_positions": {
"orders": { "serial": 42, "stream_id": "orders", "last_message_id": "msg_01HX" }
}
}
}

Recoverable channels are replayed, then the server sends one aggregate resume_success:

{
"event": "sockudo:resume_success",
"data": "{\"recovered\":[...],\"failed\":[]}"
}

Each channel that cannot be recovered also receives its own resume_failed. The code is one of position_expired, stream_reset, continuity_unverifiable, or persistence_unavailable.

{
"event": "sockudo:resume_failed",
"channel": "orders",
"data": "{\"code\":\"position_expired\",\"reason\":\"...\",\"expected_stream_id\":\"orders\",\"current_stream_id\":\"orders\",\"oldest_available_serial\":120,\"newest_available_serial\":180}"
}

Rewind complete

A V2 subscription with rewind (a message count, or { "seconds": N }) replays recent history before live delivery, then reports what was sent:

{
"event": "sockudo:rewind_complete",
"channel": "orders",
"data": {
"historical_count": 25,
"live_count": 0,
"complete": true,
"truncated_by_retention": false,
"truncated_by_limit": false
}
}

Channel history

V2 clients read durable history over the WebSocket. The response uses the same event name. See Client history for the response fields.

{
"event": "sockudo:channel_history",
"data": { "channel": "chat", "limit": 100, "direction": "backwards", "until_attach": true }
}

Subscription predicates

V2 subscriptions accept one compound filter. Its non-empty events, tags, and expression components use AND semantics; separate exact and wildcard subscriptions use OR semantics. The expression form is either a JMESPath source string or { "language": "jmespath", "source": "..." }.

{
"channel": "orders.*",
"filter": {
"events": ["order.updated"],
"tags": { "cmp": "eq", "key": "region", "val": "eu" },
"expression": "data.total >= `100` && headers.priority == `\"high\"`"
}
}

Predicates compile once at subscription time and apply consistently to live fanout, rewind, and recovery. Expression projection exposes event, channel, data, name, userId, tags, public headers, messageId, streamId, serial, and action. Internal sockudo_ headers, extras, and idempotency keys are never exposed. Source, AST, filter-tree, and projected-document sizes are bounded; invalid input is rejected and evaluation errors fail closed. This remains gated by Protocol V2 and [tag_filtering].enabled; Protocol V1 channel validation and delivery are unchanged.

Client
Sockudo
History
1subscribe orders with protocol_version=2
2sockudo_internal:subscription_succeeded
3persist event with stream_id and serial
4order.created with message_id and serial
5resume from last serial
6read gap
7replay missed events
sequenceDiagram
  participant Client
  participant Sockudo
  participant History
  Client->>Sockudo: subscribe orders with protocol_version=2
  Sockudo-->>Client: sockudo_internal:subscription_succeeded
  Sockudo->>History: persist event with stream_id and serial
  Sockudo-->>Client: order.created with message_id and serial
  Client->>Sockudo: resume from last serial
  Sockudo->>History: read gap
  Sockudo-->>Client: replay missed events

Prefixes

Event familyV1V2
Public system eventspusher:sockudo:
Internal eventspusher_internal:sockudo_internal:
Mutable messagesnot availablesockudo:message.*
Recoverynot availablesockudo:resume_*
Rewindnot availablesockudo:rewind_complete

Channel names

Channel names are limited to 200 bytes by default (configurable per app and per namespace) and may contain ASCII letters, digits, and - _ = @ , ; ., plus : for namespaces and # for V2 user-limited channels. The prefix selects the channel type.

ChannelPrefixAuth required
PublicnoneNo
Privateprivate-Yes
Presencepresence-Yes, with channel_data
Encryptedprivate-encrypted-Yes

Namespaced channel rules, user-limited channel syntax, and per-namespace permissions are covered in Channel namespaces.

Broadcast metadata

V2 deliveries add these fields to the familiar event, channel, and data:

FieldPurpose
message_idStable broadcast identity for deduplication.
stream_idOpaque per-channel continuity token. Changes only when Sockudo can no longer prove continuity for the stream.
serialMonotonically increasing per-channel position used by recovery and history.
tagsFlat string tags used by tag filtering.
extrasV2 envelope for headers, ephemeral, echo, push, and AI Transport metadata.
{
"event": "order.updated",
"channel": "orders",
"data": { "id": "ord_123" },
"message_id": "msg_01HX",
"stream_id": "orders",
"serial": 42,
"tags": { "status": "packed" },
"extras": {
"headers": { "tenant": "acme" }
}
}

V1 clients should not depend on V2-only fields. Idempotency keys are never sent to WebSocket clients in either protocol.

Compatibility boundary

The compatibility rule is simple: negotiate the richest protocol a client can safely understand, then deliver only fields that belong to that protocol.

ConcernV1 behaviorV2 behavior
System prefixespusher: and pusher_internal:sockudo: and sockudo_internal:
Event metadataPusher-compatible event, channel, and dataAdds serials, message IDs, stream IDs, extras, tags, and headers where enabled.
RecoveryClient reconnects and resubscribesClient can resume from continuity metadata when recovery is configured.
Mutable messagesNot exposedMessage updates, deletes, appends, versions, and annotations are explicit V2 events.
HeartbeatsPusher application ping/pongNative WebSocket Ping/Pong, with sockudo:ping fallback.
Server publishPusher-shaped HTTP APISame trusted API plus V2 acknowledgement fields when enabled.

For mixed deployments, treat Protocol V1 as a stable contract and Protocol V2 as an opt-in capability layer. A backend may publish once, but Sockudo must shape the delivery for each subscriber according to the subscriber protocol.

Push is outside the WebSocket protocol

Push notifications are HTTP-driven. They target device registrations, channel push subscriptions, clients, or explicit recipients. A push payload may reference a realtime channel or message serial, but provider delivery is not part of WebSocket ordering.

The optional Ably compatibility facade can resolve an Ably realtime-channel push recipient into a native MessageService publish. This is an internal push target, not another network provider or fallback transport; it follows the channel’s ordinary fanout, persistence, history, version, and idempotency semantics.

Next steps