Skip to content

[React Native] Add serverUrl param for in-VPC WebRTC deployments - #814

Open
a1anfan wants to merge 8 commits into
mainfrom
af/in-vpc-webrtc-server-url
Open

[React Native] Add serverUrl param for in-VPC WebRTC deployments#814
a1anfan wants to merge 8 commits into
mainfrom
af/in-vpc-webrtc-server-url

Conversation

@a1anfan

@a1anfan a1anfan commented May 26, 2026

Copy link
Copy Markdown

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.

  • Adds serverUrl?: string to BaseSessionConfig — a single URL that simultaneously configures the token-fetch origin and the LiveKit WebSocket URL for self-hosted / in-VPC bridges
  • WebRTCConnection.create() derives resolvedOrigin (HTTP/HTTPS) and resolvedLivekitUrl (WS/WSS) from serverUrl via symmetric helpers convertToHttps / convertToWss; explicit origin / livekitUrl always take precedence
  • Handles all four input protocols: https://wss://, http://ws://, wss://https:// (token) + pass-through (LiveKit), ws://http:// (token) + pass-through (LiveKit)
  • Updates examples/react-native-expo/App.tsx to pick up EXPO_PUBLIC_SERVER_URL so VPC deployments can be tested without code changes
  • Documents in JSDoc that serverUrl is WebRTC-only (WebSocket sessions use origin directly)

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) and livekitUrl (LiveKit WS URL) separately. serverUrl derives both from one base URL.

Test plan

Automated (CI) — all passing:

  • https:// serverUrl → token fetched from https://, LiveKit connects to wss://
  • http:// serverUrl → token fetched from http://, LiveKit connects to ws://
  • ws:// serverUrl → token fetched from http:// (not a broken ws:// fetch URL), LiveKit connects to ws://
  • Explicit origin overrides serverUrl for token fetch
  • Explicit livekitUrl overrides serverUrl for LiveKit connection

Manual — no regression:

  • Run Expo example app without EXPO_PUBLIC_SERVER_URL set → cloud session connects as before

VPC E2E — deferred to Step 3 (requires bridge from Step 2):

  • Set EXPO_PUBLIC_SERVER_URL=https://<bridge-host>, confirm token fetched from that origin and LiveKit connects to wss://<bridge-host>

Plan

This is Step 1 of 3 for WebRTC / React Native in-VPC support (customer: Pelago Health).

Step 1 — this PR: Add serverUrl to the SDK so the React Native app can point at a self-hosted LiveKit bridge.

Step 2 — extend the SIP bridge for WebRTC:

  • Add a /v1/convai/conversation/token HTTP endpoint to elevenlabs-agents-on-prem-sip-connector so the SDK can mint LiveKit JWTs
  • Make agent config dynamic from LiveKit room metadata (Pelago has 4+ agents; the current bridge uses a single static AGENT_CONFIG)
  • One shared bridge instance handles all agents via per-session dynamic variables in the system prompt

Step 3 — Pelago E2E:

  • Publish updated SDK package
  • Pelago integrates serverUrl pointing at their EC2 bridge
  • End-to-end call test: mobile app → LiveKit bridge (EC2) → VPC orchestrator

Note

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 serverUrl on session config so WebRTC clients can target a self-hosted / in-VPC bridge with one base URL instead of setting origin and livekitUrl separately.

WebRTCConnection.create() now resolves token HTTP(S) origin and LiveKit WS(S) URL from serverUrl via convertToHttps / convertToWss, with explicit origin / livekitUrl still 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_URL and passes serverUrl into startSession only 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.

Alan Fan and others added 4 commits May 26, 2026 13:47
…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>
Comment thread packages/client/src/utils/WebRTCConnection.ts Outdated
Comment thread packages/client/src/utils/WebRTCConnection.ts Outdated
…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>

@cursor cursor Bot left a comment

Copy link
Copy Markdown

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.

Fix All in Cursor

❌ 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.

Comment thread packages/client/src/utils/WebRTCConnection.ts Outdated
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>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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 serverUrl to BaseSessionConfig (documented as WebRTC-only).
  • Derive resolvedOrigin and resolvedLivekitUrl inside WebRTCConnection.create() from serverUrl when explicit values aren’t provided.
  • Update the React Native Expo example + env template, and add unit tests for serverUrl resolution/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.

Comment thread packages/client/src/utils/WebRTCConnection.ts Outdated
Comment thread examples/react-native-expo/.env.example Outdated
Comment thread packages/client/src/utils/WebRTCConnection.test.ts
Comment thread examples/react-native-expo/App.tsx Outdated
…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>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.

Comment thread packages/client/src/utils/WebRTCConnection.ts Outdated
Comment thread packages/client/src/utils/WebRTCConnection.test.ts
Comment thread examples/react-native-expo/.env.example Outdated

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.

Comment thread packages/client/src/utils/WebRTCConnection.ts Outdated
Comment thread packages/client/src/utils/WebRTCConnection.test.ts
Comment thread examples/react-native-expo/.env.example Outdated
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.

2 participants