[React Native] Add serverUrl param for in-VPC WebRTC deployments - #814
[React Native] Add serverUrl param for in-VPC WebRTC deployments#814a1anfan wants to merge 8 commits into
Conversation
…oyments Adds a `serverUrl` field to `BaseSessionConfig` that lets callers point the React Native SDK at a self-hosted LiveKit bridge with a single URL instead of configuring `origin` and `livekitUrl` separately. When set, `serverUrl` derives the token-fetch origin (HTTP/HTTPS) and the LiveKit WebSocket URL (WS/WSS) automatically. Explicit `origin` or `livekitUrl` values always take precedence. The example app picks up `EXPO_PUBLIC_SERVER_URL` from the environment so VPC deployments can be tested without code changes. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Tests all four cases: https→wss derivation, http→ws derivation, explicit origin precedence, and explicit livekitUrl precedence. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Use the `Mock` type from vitest instead of `ReturnType<typeof Room>` (class constructors don't satisfy the ReturnType constraint). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
The ws:// → http:// handling was not needed for serverUrl (which only accepts http/https inputs per docs) and changed pre-existing behavior of a shared helper outside this PR's scope. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…kitUrl Add convertToHttps (symmetric with convertToWss) to handle both wss:// and ws:// → https:///http:// when deriving the token endpoint origin from serverUrl. Previously ws:// passed through convertWssToHttps unchanged, producing an invalid ws:// fetch URL. Revert resolvedLivekitUrl fallback to || so empty-string livekitUrl still falls back to the default rather than passing "" to room.connect. Add test for ws:// serverUrl input. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.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 98e08d3. Configure here.
Replace != null guard with truthy check so serverUrl: "" falls through to the same defaults as no serverUrl, consistent with the || fallback already used for resolvedLivekitUrl. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
Adds a serverUrl?: string convenience configuration for React Native WebRTC sessions so self-hosted / in-VPC deployments can configure both the token-fetch origin and LiveKit WebSocket URL from a single base URL, while keeping explicit origin / livekitUrl overrides as highest precedence.
Changes:
- Add
serverUrltoBaseSessionConfig(documented as WebRTC-only). - Derive
resolvedOriginandresolvedLivekitUrlinsideWebRTCConnection.create()fromserverUrlwhen explicit values aren’t provided. - Update the React Native Expo example + env template, and add unit tests for
serverUrlresolution/precedence.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/client/src/utils/WebRTCConnection.ts | Derives token origin + LiveKit URL from serverUrl and applies them during token fetch / room connect. |
| packages/client/src/utils/WebRTCConnection.test.ts | Adds tests for serverUrl resolution and precedence rules. |
| packages/client/src/utils/BaseConnection.ts | Extends shared session config with documented serverUrl option. |
| examples/react-native-expo/App.tsx | Reads EXPO_PUBLIC_SERVER_URL and passes it into session config. |
| examples/react-native-expo/.env.example | Documents EXPO_PUBLIC_SERVER_URL for the Expo example. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…tc guard - Use convertToHttps instead of convertWssToHttps for token fetch origin so ws:// origins are also correctly normalized to http:// - Add wss:// serverUrl test case (token→https://, LiveKit→wss://) - Only pass serverUrl in Expo example when connectionType is webrtc - Clarify .env.example comment that serverUrl is WebRTC-only Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
convertToHttps supersedes it for token fetch normalization. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

Summary
Adds a serverUrl param to the SDK — point it at your bridge (e.g. "https://bridge.vpc.example.com") and it derives both the token fetch and LiveKit URL automatically. Can proceed in parallel with WebRTC <> WebSockets bridge; Pelago will need this published before deploying the bridge in their VPC.
serverUrl?: stringtoBaseSessionConfig— a single URL that simultaneously configures the token-fetch origin and the LiveKit WebSocket URL for self-hosted / in-VPC bridgesWebRTCConnection.create()derivesresolvedOrigin(HTTP/HTTPS) andresolvedLivekitUrl(WS/WSS) fromserverUrlvia symmetric helpersconvertToHttps/convertToWss; explicitorigin/livekitUrlalways take precedencehttps://→wss://,http://→ws://,wss://→https://(token) + pass-through (LiveKit),ws://→http://(token) + pass-through (LiveKit)examples/react-native-expo/App.tsxto pick upEXPO_PUBLIC_SERVER_URLso VPC deployments can be tested without code changesserverUrlis WebRTC-only (WebSocket sessions useorigindirectly)Motivation
Pelago Health (in-VPC customer) uses the React Native SDK with a self-hosted LiveKit bridge. Previously they had to configure
origin(token endpoint) andlivekitUrl(LiveKit WS URL) separately.serverUrlderives both from one base URL.Test plan
Automated (CI) — all passing:
https://serverUrl → token fetched fromhttps://, LiveKit connects towss://http://serverUrl → token fetched fromhttp://, LiveKit connects tows://ws://serverUrl → token fetched fromhttp://(not a brokenws://fetch URL), LiveKit connects tows://originoverridesserverUrlfor token fetchlivekitUrloverridesserverUrlfor LiveKit connectionManual — no regression:
EXPO_PUBLIC_SERVER_URLset → cloud session connects as beforeVPC E2E — deferred to Step 3 (requires bridge from Step 2):
EXPO_PUBLIC_SERVER_URL=https://<bridge-host>, confirm token fetched from that origin and LiveKit connects towss://<bridge-host>Plan
This is Step 1 of 3 for WebRTC / React Native in-VPC support (customer: Pelago Health).
Step 1 — this PR: Add
serverUrlto the SDK so the React Native app can point at a self-hosted LiveKit bridge.Step 2 — extend the SIP bridge for WebRTC:
/v1/convai/conversation/tokenHTTP endpoint toelevenlabs-agents-on-prem-sip-connectorso the SDK can mint LiveKit JWTsAGENT_CONFIG)Step 3 — Pelago E2E:
serverUrlpointing at their EC2 bridgeNote
Medium Risk
Changes WebRTC connection URL resolution and token fetch origins; mistakes could misroute VPC traffic, though defaults and explicit overrides preserve existing cloud behavior.
Overview
Adds optional
serverUrlon session config so WebRTC clients can target a self-hosted / in-VPC bridge with one base URL instead of settingoriginandlivekitUrlseparately.WebRTCConnection.create()now resolves token HTTP(S) origin and LiveKit WS(S) URL fromserverUrlviaconvertToHttps/convertToWss, with explicitorigin/livekitUrlstill winning. Token fetch normalization covers http(s) and ws(s) inputs (replacing the older wss→https-only helper).The React Native Expo example documents
EXPO_PUBLIC_SERVER_URLand passesserverUrlintostartSessiononly for WebRTC. New unit tests lock in protocol mapping and override precedence.Reviewed by Cursor Bugbot for commit d7d8081. Bugbot is set up for automated code reviews on this repo. Configure here.