Realtime clients

Choose and operate an official Sockudo realtime client for web, mobile, desktop, Python, and backend WebSocket consumers.

5 min read
View .mdEdit on GitHub

A realtime client SDK holds a long-lived WebSocket connection to Sockudo. Over that one connection it subscribes to channels (named streams of events such as orders or presence-lobby), delivers each incoming event to the handlers you bind, reconnects after network failures, and asks your backend to authorize channels that carry protected data. On Protocol V2 it also exposes Sockudo’s native features: recovery, rewind, filters, deltas, and versioned messages.

Install client SDKs from the package names below. The old per-SDK repositories should be treated as archived/legacy mirrors.

Official clients

SDKPackageRuntimeDefault protocol
JavaScript / TypeScript@sockudo/clientWeb, Node, worker, React, Vue, React Native, NativeScriptProtocol V1 compatibility
SwiftSockudoSwift via SwiftPMiOS, macOS, tvOS, watchOS, visionOSProtocol V1 compatibility
Kotlinio.sockudo:sockudo-kotlinAndroid and JVMProtocol V2
Flutter / Dartsockudo_flutterFlutterProtocol V1 compatibility
.NET realtimeSockudo.Client.NET appsProtocol V2
Python realtimesockudo-pythonPython 3.10+ and asyncioProtocol V2

Every SDK page follows the same order: install, connect, subscribe, protected channels, Protocol V2 features, connection lifecycle, error handling, and platform notes.

Choose a protocol

Sockudo serves two protocols on the same port, chosen per connection:

  • Protocol V1 is byte-compatible with Pusher. Use it when migrating existing Pusher or Laravel Echo clients without code changes.
  • Protocol V2 is Sockudo-native. Use it for recovery, rewind, delta compression, tag filters, mutable messages, annotations, and native Sockudo metadata.

A backend publishes once; Sockudo strips V2-only fields from deliveries to V1 subscribers. Read Protocol V2 for the details.

Clients and servers have different trust levels

The realtime and HTTP SDKs have different trust boundaries. Realtime clients hold only the public app key and maintain WebSocket subscriptions. Server SDKs hold the app secret, publish over HTTP, authorize protected subscriptions, and validate webhooks. For Python and .NET in particular, make sure you choose the package whose role matches your process.

LanguageRealtime packageTrusted HTTP package
JavaScript / TypeScript@sockudo/clientsockudo
Pythonsockudo-pythonsockudo-http-python
.NETSockudo.ClientSockudoServer
SwiftSockudoSwiftSockudo server package

Client responsibilities

Client SDKs should:

  • connect with public app key only
  • call your backend for private, presence, encrypted, push, and history proxy operations
  • keep app secrets out of the client bundle
  • bind events and update UI state
  • store recovery positions when V2 recovery is enabled
  • register devices for push through trusted backend endpoints

Server responsibilities

Server SDKs should:

  • publish events over the HTTP API
  • sign channel and user authentication responses
  • proxy presence history and versioned message reads for clients
  • validate webhooks
  • manage push registration, credentials, channel push subscriptions, and publish workflows

Common V2 setup

realtime.ts
const client = new Sockudo("app-key", {
wsHost: "realtime.example.com",
forceTLS: true,
protocolVersion: 2,
connectionRecovery: true,
});

Use this sequence in every client:

  1. Construct one long-lived client with your public key and public WebSocket endpoint.
  2. Bind connection diagnostics and event handlers.
  3. Subscribe to channels, using a backend auth endpoint for protected names.
  4. Connect and let the SDK resubscribe after transient failures.
  5. If recovery fails, replace derived state from an authoritative snapshot.
  6. Unbind or unsubscribe when a screen or worker no longer needs a channel.
  7. Disconnect during application shutdown.

Choosing features

RequirementClient setting or APIBackend requirement
Pusher migrationProtocol V1Pusher-compatible app config
Resume after a short outageProtocol V2 recoveryDurable or hot recovery configured
Initial backlogSubscription rewindHistory enabled with suitable retention
Gap-free late joinHistory with until_attachDurable history enabled for the channel
Lower high-volume bandwidthTag filters and delta compressionV2 filtering/delta enabled
Private dataPrivate channel authSession-aware auth endpoint
End-to-end content encryptionprivate-encrypted-*Shared-secret auth and key management
User-targeted eventsUser sign-inUser auth endpoint
Mobile notificationsProvider token collectionPush registration and publish backend

Connection and state model

A successful WebSocket connection does not mean every channel is subscribed. Wait for each channel’s subscription-success event before treating its state as live. During reconnect, keep the last rendered state but mark it stale. After a successful resume, continue from the recovered serial; after a failed resume, discard derived state and fetch a fresh snapshot.

Protected-channel auth flow

Channels named private-*, presence-*, or private-encrypted-* carry data that not every holder of the public app key may see. Sockudo cannot know who your users are, so it delegates that decision to your backend: the client asks your auth endpoint to sign a specific socket and channel, and Sockudo verifies the signature with the app secret before completing the subscription.

Client SDK
Your backend
Sockudo
1Open WebSocket with public app key
2socket_id
3socket_id and requested channel
Authenticate session and authorize that exact channel
4Short-lived signed auth response
5Subscribe with auth response
Verify signature with the app secret
6subscription_succeeded
sequenceDiagram
  participant C as Client SDK
  participant B as Your backend
  participant S as Sockudo
  C->>S: Open WebSocket with public app key
  S-->>C: socket_id
  C->>B: socket_id and requested channel
  Note over B: Authenticate session and authorize that exact channel
  B-->>C: Short-lived signed auth response
  C->>S: Subscribe with auth response
  Note over S: Verify signature with the app secret
  S-->>C: subscription_succeeded

Do not implement an auth endpoint that signs every requested channel. Validate tenant ownership, resource access, and presence identity before signing. For encrypted channels, return only the derived channel shared secret, not the encryption master key.

Protocol V2 can also authorize the whole connection with a scoped capability token instead of per-channel signatures. See Authentication for both flows end to end.

Production checklist

  • Terminate TLS at Sockudo or a load balancer and use wss://.
  • Keep a single client per app or process unless isolation is intentional.
  • Observe connected, unavailable, failed, and reconnecting states.
  • Set auth and proxy request timeouts; handle 401, 403, and 429 separately from transport failures.
  • Bound rewind and history page sizes.
  • Test a rolling restart, network interruption, auth expiry, and resume failure.
  • Unsubscribe and unbind handlers when views or jobs end.

Push from clients

Mobile and browser clients can collect provider tokens, but they should not call Sockudo push admin APIs directly. Send provider tokens to your backend, bind them to the authenticated user, and let the backend call Sockudo.

register-device.ts
await fetch("/api/push/devices", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
device_id: "browser-device-1",
platform: "webpush",
provider_token: subscription,
}),
});

See Push notifications for the backend side.

Next steps