feat: migrate realtime to LiveKit#56
Open
VerioN1 wants to merge 5 commits into
Open
Conversation
Replace the aiortc SDP/ICE media path with LiveKit room negotiation while preserving the realtime client lifecycle and control-message APIs. Co-authored-by: Cursor <cursoragent@cursor.com>
Default LiveKit publishing to H264 while allowing callers to choose the same codec set exposed by the JS SDK. Co-authored-by: Cursor <cursoragent@cursor.com>
Keep H264 as the default LiveKit publish codec and only expose VP9 as the alternate client-selectable codec. Co-authored-by: Cursor <cursoragent@cursor.com>
AdirAmsalem
approved these changes
Jun 3, 2026
Send initial control messages before media publish and correctly report LiveKit reconnecting state. Co-authored-by: Cursor <cursoragent@cursor.com>
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit a18d8ad. Configure here.
Mount the local LiveKit track immediately for no-initial-state sessions, while preserving ack gating for initial image or prompt setup. Co-authored-by: Cursor <cursoragent@cursor.com>
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
livekit.rtctracks and frames.Developer Interface: Before / After
Before, callers passed aiortc tracks and received aiortc remote tracks:
After, callers publish native LiveKit tracks and consume native LiveKit remote tracks:
Unchanged developer-facing methods:
set,set_prompt,set_image,disconnect,on/off,session_id,subscribe_token,is_connected, andget_connection_state.Test plan
uv sync --all-extrasuv run pytest tests/test_realtime_unit.py -vuv run pytest tests/ -vuv run ruff check decart/ tests/ examples/ playground/uv run black --check decart/ tests/ examples/ playground/uv run python -m py_compile examples/realtime_synthetic.py examples/realtime_file.py playground/playground.pyLocal testing
uv sync --all-extrasuv run pytest tests/test_realtime_unit.py -vuv run pytest tests/ -vDECART_API_KEY=... uv run python examples/realtime_synthetic.pyDECART_API_KEY=... uv run python examples/realtime_file.py path/to/input.mp4DECART_API_KEY=... uv run python playground/playground.py --model lucy-restyle-2Note
High Risk
Breaking change to realtime media types, subscribe token format, and connection protocol; touches core connect/reconnect and credential flows used for all live sessions.
Overview
This PR replaces the realtime media stack from aiortc/WebRTC (SDP offers, ICE,
MediaStreamTrack) with LiveKit (rtc.Room,LocalVideoTrack/RemoteVideoTrack). The control channel over WebSocket is largely preserved (prompts,set_image, generation events), but negotiation now useslivekit_join/livekit_room_info(and optionalqueue_position) instead of offer/answer and ICE messages.RealtimeClient.connectstill exposes the same lifecycle helpers (set_prompt,set_image,disconnect, events), but callers must passlivekit.rtc.LocalVideoTrackand handleRemoteVideoTrackinon_remote_stream. Connect URLs gainlivekit_early_room_info=true;preferred_video_codec(h264/vp9) replacescustomize_offer. Session/subscribe tokens are derived fromroom_nameviaon_session_started, not legacysession_id+ server IP/port.Subscribe decodes a room-only token, calls
POST …/watch-stream/{room}for LiveKit credentials, and joins the room without reusing the stream WebSocket. Legacy subscribe tokens are rejected.Examples, playground, and
decart[realtime]deps switch from aiortc/av to livekit (OpenCV +VideoSource.capture_frame; remote consumption viartc.VideoStream). Unit tests are refocused on LiveKit connection ordering, codec publish options, and watch-stream HTTP behavior.Reviewed by Cursor Bugbot for commit e6d7b92. Bugbot is set up for automated code reviews on this repo. Configure here.