From 69f4aa82c974ab0fd8752e93331e1791397a3dbd Mon Sep 17 00:00:00 2001 From: Adir Amsalem Date: Mon, 23 Feb 2026 16:22:17 +0200 Subject: [PATCH] feat(realtime): add realtimeBaseUrl option to createDecartClient Allow overriding the default wss://api3.decart.ai WebSocket base URL for realtime connections via a new realtimeBaseUrl option on createDecartClient(). Useful for self-hosted or custom deployments. - Add realtimeBaseUrl to Zod schema, TypeScript types, and JSDoc - Wire through to realtime client with fallback to default URL - Add validation error handling for invalid realtimeBaseUrl - Add unit tests for invalid URL and custom URL scenarios - Add realtimeBaseUrl input to test page (index.html) - Add usage example (examples/sdk-core/realtime/custom-base-url.ts) --- examples/sdk-core/README.md | 1 + examples/sdk-core/realtime/custom-base-url.ts | 47 +++++++++++++++++++ packages/sdk/index.html | 9 ++++ packages/sdk/src/index.ts | 13 +++-- packages/sdk/tests/unit.test.ts | 12 +++++ 5 files changed, 77 insertions(+), 5 deletions(-) create mode 100644 examples/sdk-core/realtime/custom-base-url.ts diff --git a/examples/sdk-core/README.md b/examples/sdk-core/README.md index aca4517..92b3a42 100644 --- a/examples/sdk-core/README.md +++ b/examples/sdk-core/README.md @@ -58,6 +58,7 @@ See `examples/nextjs-realtime` or `examples/react-vite` for runnable demos. - `realtime/connection-events.ts` - Handling connection state and errors - `realtime/prompt-update.ts` - Updating prompt dynamically - `realtime/custom-model.ts` - Using a custom model definition (e.g., preview/experimental models) +- `realtime/custom-base-url.ts` - Using a custom WebSocket base URL for realtime connections ## API Reference diff --git a/examples/sdk-core/realtime/custom-base-url.ts b/examples/sdk-core/realtime/custom-base-url.ts new file mode 100644 index 0000000..2d76ff5 --- /dev/null +++ b/examples/sdk-core/realtime/custom-base-url.ts @@ -0,0 +1,47 @@ +/** + * Browser-only example - requires WebRTC APIs + * Demonstrates using a custom realtimeBaseUrl for WebSocket connections + * See examples/nextjs-realtime or examples/react-vite for runnable demos + */ + +import { createDecartClient, models } from "@decartai/sdk"; + +async function main() { + const model = models.realtime("mirage_v2"); + + // Get webcam stream with model-specific settings + const stream = await navigator.mediaDevices.getUserMedia({ + audio: true, + video: { + frameRate: model.fps, + width: model.width, + height: model.height, + }, + }); + + // Create a client with a custom realtime WebSocket base URL + // This overrides the default wss://api3.decart.ai endpoint + const client = createDecartClient({ + apiKey: process.env.DECART_API_KEY!, + realtimeBaseUrl: "wss://custom-ws.example.com", + }); + + const realtimeClient = await client.realtime.connect(stream, { + model, + onRemoteStream: (transformedStream) => { + const video = document.getElementById("output") as HTMLVideoElement; + video.srcObject = transformedStream; + }, + initialState: { + prompt: { + text: "Studio Ghibli animation style", + enhance: true, + }, + }, + }); + + console.log("Session ID:", realtimeClient.sessionId); + console.log("Connected:", realtimeClient.isConnected()); +} + +main(); diff --git a/packages/sdk/index.html b/packages/sdk/index.html index fe1fd0d..0b1b184 100644 --- a/packages/sdk/index.html +++ b/packages/sdk/index.html @@ -228,6 +228,10 @@

Configuration

+
+ + +