Skip to content

feat(realtime): add subscribe client for receive-only session viewing#80

Merged
AdirAmsalem merged 7 commits intomainfrom
feat/subscribe-client
Feb 10, 2026
Merged

feat(realtime): add subscribe client for receive-only session viewing#80
AdirAmsalem merged 7 commits intomainfrom
feat/subscribe-client

Conversation

@AdirAmsalem
Copy link
Contributor

@AdirAmsalem AdirAmsalem commented Feb 10, 2026

Summary

Add subscribe functionality allowing viewers to watch existing realtime sessions.

How it works

  1. Producer connects normally → server sends session_id message → SDK encodes it into an opaque subscribeToken (base64 JSON of {sid, ip, port})
  2. Subscriber calls client.realtime.subscribe({ token, onRemoteStream }) → SDK decodes the token, builds the subscribe URL, connects with receive-only WebRTC transceivers
// Producer side
const producer = await client.realtime.connect(stream, { model, onRemoteStream });
const token = producer.subscribeToken;

// Subscriber side
const viewer = await client.realtime.subscribe({
  token,
  onRemoteStream: (stream) => { videoElement.srcObject = stream; },
});

What's included

  • subscribe-client.ts — Token encode/decode functions + RealTimeSubscribeClient type (read-only: no set, setPrompt, setImage)
  • event-buffer.ts — Extracted shared createEventBuffer<E>() utility used by both connect and subscribe flows
  • client.tssubscribeToken getter on producer client, subscribe() method on realtime client
  • webrtc-connection.ts — Handles session_id messages from server, adds recvonly video+audio transceivers when localStream is null
  • webrtc-manager.tssubscribeMode flag enabling reconnection for subscribers even without a local stream
  • types.tsSessionIdMessage type matching server's {"type":"session_id",...} format
  • index.ts — Re-exports RealTimeSubscribeClient, SubscribeEvents, SubscribeOptions

Tests

87/87 passing — includes subscribe-specific tests for:

  • Token encode/decode round-trip
  • Invalid token handling (bad base64, missing fields)
  • Recvonly transceiver setup
  • Reconnect with null stream in subscribe mode
  • session_id message → subscribeToken population
  • Subscribe event buffering

Note

Medium Risk
Touches core WebRTC connection and reconnect behavior and introduces a new public realtime API surface (subscribeToken/subscribe()), which could affect existing streaming sessions if regressions slip in.

Overview
Adds a new realtime subscriber flow to the SDK: producer connections now expose a subscribeToken derived from a server-sent session_id, and a new realtime.subscribe({ token, onRemoteStream }) API connects in receive-only mode.

Refactors realtime event buffering into a shared createEventBuffer, extends WebRTC signaling/types to handle session_id, and updates WebRTC connection/manager logic to support subscribe mode (recvonly audio/video transceivers, reconnection without a local stream, and more robust remote-stream handling).

Includes a new examples/tanstack-streamer TanStack Start app demonstrating producer webcam streaming + shareable viewer link, and adds unit tests covering token encoding/validation, subscribe-mode transceivers/reconnect, event buffering, and subscribeToken population. Also removes the SDK’s uuid dependency.

Written by Cursor Bugbot for commit be6ae66. This will update automatically on new commits. Configure here.

Add subscribe functionality allowing viewers to watch existing realtime
sessions using SDK-encoded opaque tokens. The producer client captures
session_id messages from the server and exposes a subscribeToken getter.
Subscribers decode the token, connect with recvonly WebRTC transceivers,
and receive the remote stream with full reconnection support via p-retry.

- Add encodeSubscribeToken/decodeSubscribeToken for opaque token handling
- Add subscribe() method on realtime client with event buffering
- Add recvonly video+audio transceivers when localStream is null
- Add subscribeMode flag on WebRTCManager for reconnect support
- Extract shared createEventBuffer utility for both connect and subscribe
- Expose sessionId property on subscribe client
- Re-export RealTimeSubscribeClient, SubscribeEvents, SubscribeOptions
@pkg-pr-new
Copy link

pkg-pr-new bot commented Feb 10, 2026

Open in StackBlitz

npm i https://pkg.pr.new/DecartAI/sdk/@decartai/sdk@80

commit: be6ae66

@AdirAmsalem AdirAmsalem force-pushed the feat/subscribe-client branch from 2b07801 to 13a6495 Compare February 10, 2026 12:02
Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

@AdirAmsalem AdirAmsalem merged commit 7b2a634 into main Feb 10, 2026
5 checks passed
@AdirAmsalem AdirAmsalem deleted the feat/subscribe-client branch February 10, 2026 15:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant