Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion packages/sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
"test": "vitest unit",
"test:e2e": "vitest e2e",
"test:e2e:realtime": "vitest --config vitest.config.e2e-realtime.ts",
"test:e2e:turn-tcp": "vitest --config vitest.config.e2e-turn-tcp.ts",
"typecheck": "tsc --noEmit",
"format": "biome format --write",
"format:check": "biome check",
Expand Down
6 changes: 1 addition & 5 deletions packages/sdk/src/realtime/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,6 @@ const realTimeClientConnectOptionsSchema = z.object({
});
export type RealTimeClientConnectOptions = Omit<z.infer<typeof realTimeClientConnectOptionsSchema>, "model"> & {
model: ModelDefinition | CustomModelDefinition;
iceServers?: RTCIceServer[];
iceTransportPolicy?: "tcp" | "udp" | "all";
};

export type Events = {
Expand Down Expand Up @@ -174,7 +172,7 @@ export const createRealTimeClient = (opts: RealTimeClientOptions) => {
const { emitter: eventEmitter, emitOrBuffer, flush, stop } = createEventBuffer<Events>();

webrtcManager = new WebRTCManager({
webrtcUrl: `${url}?api_key=${encodeURIComponent(apiKey)}&model=${encodeURIComponent(options.model.name)}${options.iceTransportPolicy ? `&ice_transport_policy=${encodeURIComponent(options.iceTransportPolicy)}` : ""}`,
webrtcUrl: `${url}?api_key=${encodeURIComponent(apiKey)}&model=${encodeURIComponent(options.model.name)}`,
integration,
logger,
onDiagnostic: (name, data) => {
Expand All @@ -196,8 +194,6 @@ export const createRealTimeClient = (opts: RealTimeClientOptions) => {
modelName: options.model.name,
initialImage,
initialPrompt,
iceServers: options.iceServers,
expectTurnConfig: !!options.iceTransportPolicy,
});

const manager = webrtcManager;
Expand Down
10 changes: 1 addition & 9 deletions packages/sdk/src/realtime/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,6 @@ export type SessionIdMessage = {
server_port: number;
};

export type TurnConfigMessage = {
type: "turn_config";
urls: string[];
username: string;
credential: string;
};

export type ConnectionState = "connecting" | "connected" | "generating" | "disconnected" | "reconnecting";

// Incoming message types (from server)
Expand All @@ -92,8 +85,7 @@ export type IncomingWebRTCMessage =
| GenerationStartedMessage
| GenerationTickMessage
| GenerationEndedMessage
| SessionIdMessage
| TurnConfigMessage;
| SessionIdMessage;

// Outgoing message types (to server)
export type OutgoingWebRTCMessage =
Expand Down
36 changes: 2 additions & 34 deletions packages/sdk/src/realtime/webrtc-connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,9 @@ import type {
PromptAckMessage,
SessionIdMessage,
SetImageAckMessage,
TurnConfigMessage,
} from "./types";

const DEFAULT_ICE_SERVERS: RTCIceServer[] = [{ urls: "stun:stun.l.google.com:19302" }];
const ICE_SERVERS: RTCIceServer[] = [{ urls: "stun:stun.l.google.com:19302" }];
const AVATAR_SETUP_TIMEOUT_MS = 30_000; // 30 seconds

interface ConnectionCallbacks {
Expand All @@ -29,16 +28,13 @@ interface ConnectionCallbacks {
initialPrompt?: { text: string; enhance?: boolean };
logger?: Logger;
onDiagnostic?: DiagnosticEmitter;
iceServers?: RTCIceServer[];
expectTurnConfig?: boolean;
}

type WsMessageEvents = {
promptAck: PromptAckMessage;
setImageAck: SetImageAckMessage;
sessionId: SessionIdMessage;
generationTick: GenerationTickMessage;
turnConfig: TurnConfigMessage;
};

const noopDiagnostic: DiagnosticEmitter = () => {};
Expand All @@ -50,7 +46,6 @@ export class WebRTCConnection {
private connectionReject: ((error: Error) => void) | null = null;
private logger: Logger;
private emitDiagnostic: DiagnosticEmitter;
private turnServers: RTCIceServer[] = [];
state: ConnectionState = "disconnected";
websocketMessagesEmitter = mitt<WsMessageEvents>();
constructor(private callbacks: ConnectionCallbacks = {}) {
Expand Down Expand Up @@ -164,22 +159,6 @@ export class WebRTCConnection {
});
}

// Phase 2.5: Wait for turn_config if not yet received.
// Only wait when the server is expected to send TURN config (iceTransportPolicy was set).
// turn_config arrives during Phase 2 but may race with set_image_ack.
if (this.callbacks.expectTurnConfig && this.turnServers.length === 0) {
let turnHandler: (() => void) | null = null;
await Promise.race([
new Promise<void>((resolve) => {
turnHandler = () => resolve();
this.websocketMessagesEmitter.on("turnConfig", turnHandler);
}),
new Promise<void>((resolve) => setTimeout(resolve, 2000)),
connectAbort,
]);
if (turnHandler) this.websocketMessagesEmitter.off("turnConfig", turnHandler);
}

// Phase 3: WebRTC handshake
const handshakeStart = performance.now();
await this.setupNewPeerConnection();
Expand Down Expand Up @@ -275,12 +254,6 @@ export class WebRTCConnection {
return;
}

if (msg.type === "turn_config") {
this.turnServers = [{ urls: msg.urls, username: msg.username, credential: msg.credential }];
this.websocketMessagesEmitter.emit("turnConfig", msg);
return;
}

// All other messages require peer connection
if (!this.pc) return;

Expand Down Expand Up @@ -438,11 +411,7 @@ export class WebRTCConnection {
});
this.pc.close();
}
const iceServers: RTCIceServer[] = [
...(this.callbacks.iceServers ?? DEFAULT_ICE_SERVERS),
...this.turnServers,
];
this.pc = new RTCPeerConnection({ iceServers });
this.pc = new RTCPeerConnection({ iceServers: ICE_SERVERS });
this.setState("connecting");

if (this.localStream) {
Expand Down Expand Up @@ -588,7 +557,6 @@ export class WebRTCConnection {
this.ws?.close();
this.ws = null;
this.localStream = null;
this.turnServers = [];
this.setState("disconnected");
}

Expand Down
4 changes: 0 additions & 4 deletions packages/sdk/src/realtime/webrtc-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ export interface WebRTCConfig {
modelName?: string;
initialImage?: string;
initialPrompt?: { text: string; enhance?: boolean };
iceServers?: RTCIceServer[];
expectTurnConfig?: boolean;
}

const PERMANENT_ERRORS = [
Expand Down Expand Up @@ -68,8 +66,6 @@ export class WebRTCManager {
initialPrompt: config.initialPrompt,
logger: this.logger,
onDiagnostic: config.onDiagnostic,
iceServers: config.iceServers,
expectTurnConfig: config.expectTurnConfig,
});
}

Expand Down
176 changes: 0 additions & 176 deletions packages/sdk/tests/e2e-turn-tcp.test.ts

This file was deleted.

18 changes: 0 additions & 18 deletions packages/sdk/vitest.config.e2e-turn-tcp.ts

This file was deleted.

2 changes: 1 addition & 1 deletion packages/sdk/vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ import { defineConfig } from "vitest/config";

export default defineConfig({
test: {
exclude: ["tests/e2e-realtime.test.ts", "tests/e2e-turn-tcp.test.ts"],
exclude: ["tests/e2e-realtime.test.ts"],
},
});
Loading