Realtime clients
Choose and operate an official Sockudo realtime client for web, mobile, desktop, Python, and backend WebSocket consumers.
Realtime client SDKs connect to Sockudo over WebSocket, subscribe to channels, receive events, authorize protected channels through your backend, and expose Protocol V2 features.
Install client SDKs from the package names below. The old per-SDK repositories should be treated as archived/legacy mirrors.
Official clients
| SDK | Package | Runtime | Default |
|---|---|---|---|
| JavaScript / TypeScript | @sockudo/client | Web, Node, worker, React, Vue, React Native, NativeScript | Protocol V1 compatibility |
| Swift | SockudoSwift via SwiftPM | iOS, macOS, tvOS, watchOS, visionOS | Protocol V1 compatibility |
| Kotlin | io.sockudo:sockudo-kotlin | Android and JVM | Protocol V2 by default |
| Flutter / Dart | sockudo_flutter | Flutter and Dart | Protocol V1 compatibility |
| .NET realtime | Sockudo.Client | .NET apps | Protocol V2 by default |
| Python realtime | sockudo-python | Python 3.10+ and asyncio | Protocol V2 by default |
Use Protocol V1 when migrating existing Pusher clients. Use Protocol V2 for recovery, rewind, delta compression, tag filters, mutable messages, annotations, and native Sockudo metadata.
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.
| Language | Realtime package | Trusted HTTP package |
|---|---|---|
| JavaScript / TypeScript | @sockudo/client | sockudo |
| Python | sockudo-python | sockudo-http-python |
| .NET | Sockudo.Client | SockudoServer |
| Swift | SockudoSwift | Sockudo 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
They should never contain the app secret, provider credentials, an encryption master key, or an unrestricted capability token.
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
const client = new Sockudo("app-key", {
wsHost: "realtime.example.com",
forceTLS: true,
protocolVersion: 2,
connectionRecovery: true,
});Use this sequence in every client:
- Construct one long-lived client with your public key and public WebSocket endpoint.
- Bind connection diagnostics and event handlers.
- Subscribe to channels, using a backend auth endpoint for protected names.
- Connect and let the SDK resubscribe after transient failures.
- If recovery fails, replace derived state from an authoritative snapshot.
- Unbind or unsubscribe when a screen or worker no longer needs a channel.
- Disconnect during application shutdown.
Choosing features
| Requirement | Client setting or API | Backend requirement |
|---|---|---|
| Pusher migration | Protocol V1 | Pusher-compatible app config |
| Resume after a short outage | Protocol V2 recovery | Durable or hot recovery configured |
| Initial backlog | Subscription rewind | History enabled with suitable retention |
| Gap-free late join | History with until_attach | Authorized history proxy |
| Lower high-volume bandwidth | Tag filters and delta compression | V2 filtering/delta enabled |
| Private data | Private channel auth | Session-aware auth endpoint |
| End-to-end content encryption | private-encrypted-* | Shared-secret auth and key management |
| User-targeted events | User sign-in | User auth endpoint |
| Mobile notifications | Provider token collection | Push 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.
Event handlers should be idempotent. Network reconnects, application retries,
and upstream publishing workflows can all repeat logical work even when the
client deduplicates messages by message_id.
Protected-channel auth flow
client -> your backend: socket_id + requested channel
your backend: authenticate session and authorize that exact channel
your backend -> client: short-lived signed auth response
client -> Sockudo: subscribe with auth responseDo 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.
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, and429separately 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.
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,
}),
});Next steps
JavaScript
Browser, Node, React, Vue, worker, React Native, and NativeScript examples.
Swift
Apple platforms with auth, recovery, filters, deltas, and push proxy notes.
Kotlin
Android and JVM WebSocket client examples.
Flutter
Flutter and pure Dart client examples.
.NET realtime
Protocol V2 by default for .NET applications.
Python realtime
Asyncio client for services, agents, workers, and CLIs.