feat(realtime): add subscribe client for receive-only session viewing#80
Merged
AdirAmsalem merged 7 commits intomainfrom Feb 10, 2026
Merged
feat(realtime): add subscribe client for receive-only session viewing#80AdirAmsalem merged 7 commits intomainfrom
AdirAmsalem merged 7 commits intomainfrom
Conversation
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
commit: |
2b07801 to
13a6495
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Add subscribe functionality allowing viewers to watch existing realtime sessions.
How it works
session_idmessage → SDK encodes it into an opaquesubscribeToken(base64 JSON of{sid, ip, port})client.realtime.subscribe({ token, onRemoteStream })→ SDK decodes the token, builds the subscribe URL, connects with receive-only WebRTC transceiversWhat's included
subscribe-client.ts— Token encode/decode functions +RealTimeSubscribeClienttype (read-only: noset,setPrompt,setImage)event-buffer.ts— Extracted sharedcreateEventBuffer<E>()utility used by both connect and subscribe flowsclient.ts—subscribeTokengetter on producer client,subscribe()method on realtime clientwebrtc-connection.ts— Handlessession_idmessages from server, adds recvonly video+audio transceivers whenlocalStreamis nullwebrtc-manager.ts—subscribeModeflag enabling reconnection for subscribers even without a local streamtypes.ts—SessionIdMessagetype matching server's{"type":"session_id",...}formatindex.ts— Re-exportsRealTimeSubscribeClient,SubscribeEvents,SubscribeOptionsTests
87/87 passing — includes subscribe-specific tests for:
session_idmessage →subscribeTokenpopulationNote
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
subscribeTokenderived from a server-sentsession_id, and a newrealtime.subscribe({ token, onRemoteStream })API connects in receive-only mode.Refactors realtime event buffering into a shared
createEventBuffer, extends WebRTC signaling/types to handlesession_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-streamerTanStack Start app demonstrating producer webcam streaming + shareable viewer link, and adds unit tests covering token encoding/validation, subscribe-mode transceivers/reconnect, event buffering, andsubscribeTokenpopulation. Also removes the SDK’suuiddependency.Written by Cursor Bugbot for commit be6ae66. This will update automatically on new commits. Configure here.