Spaces:
Running
Running
adding debugs
Browse files
src/components/control-tray/ControlTray.tsx
CHANGED
@@ -230,24 +230,22 @@ function ControlTray({
|
|
230 |
ref={connectButtonRef}
|
231 |
className={cn("action-button connect-toggle", { connected })}
|
232 |
onClick={async () => {
|
233 |
-
console.log('
|
234 |
try {
|
235 |
if (connected) {
|
236 |
-
console.log('๐ด
|
237 |
await disconnect();
|
238 |
-
console.log('โ
Disconnected successfully');
|
239 |
} else {
|
240 |
-
console.log('๐ Starting connection...');
|
241 |
-
console.log('๐ฑ Device info:', { isIOSDevice, isSafari });
|
242 |
|
243 |
-
|
244 |
-
console.log('๐ Calling connect()...');
|
245 |
await connect();
|
246 |
-
console.log('โ
Connected successfully');
|
247 |
}
|
248 |
} catch (err) {
|
249 |
-
console.error('โ
|
250 |
-
// Here you could add UI feedback about the error
|
251 |
}
|
252 |
}}
|
253 |
>
|
|
|
230 |
ref={connectButtonRef}
|
231 |
className={cn("action-button connect-toggle", { connected })}
|
232 |
onClick={async () => {
|
233 |
+
console.log('๐ฎ ControlTray: Connection button clicked');
|
234 |
try {
|
235 |
if (connected) {
|
236 |
+
console.log('๐ด ControlTray: Initiating disconnect...');
|
237 |
await disconnect();
|
238 |
+
console.log('โ
ControlTray: Disconnected successfully');
|
239 |
} else {
|
240 |
+
console.log('๐ ControlTray: Starting connection process...');
|
241 |
+
console.log('๐ฑ ControlTray: Device info:', { isIOSDevice, isSafari });
|
242 |
|
243 |
+
console.log('๐ ControlTray: Calling LiveAPIContext.connect()...');
|
|
|
244 |
await connect();
|
245 |
+
console.log('โ
ControlTray: Connected successfully via LiveAPIContext');
|
246 |
}
|
247 |
} catch (err) {
|
248 |
+
console.error('โ ControlTray: Connection error:', err);
|
|
|
249 |
}
|
250 |
}}
|
251 |
>
|
src/contexts/LiveAPIContext.tsx
CHANGED
@@ -28,6 +28,7 @@ export const LiveAPIProvider: FC<LiveAPIProviderProps> = ({
|
|
28 |
url = `${window.location.protocol === 'https:' ? 'wss:' : 'ws:'}//${window.location.host}/ws`,
|
29 |
children,
|
30 |
}) => {
|
|
|
31 |
const liveAPI = useLiveAPI({ url });
|
32 |
|
33 |
return (
|
@@ -38,8 +39,10 @@ export const LiveAPIProvider: FC<LiveAPIProviderProps> = ({
|
|
38 |
};
|
39 |
|
40 |
export const useLiveAPIContext = () => {
|
|
|
41 |
const context = useContext(LiveAPIContext);
|
42 |
if (!context) {
|
|
|
43 |
throw new Error("useLiveAPIContext must be used within a LiveAPIProvider");
|
44 |
}
|
45 |
return context;
|
|
|
28 |
url = `${window.location.protocol === 'https:' ? 'wss:' : 'ws:'}//${window.location.host}/ws`,
|
29 |
children,
|
30 |
}) => {
|
31 |
+
console.log('๐ LiveAPIContext: Initializing provider with URL:', url);
|
32 |
const liveAPI = useLiveAPI({ url });
|
33 |
|
34 |
return (
|
|
|
39 |
};
|
40 |
|
41 |
export const useLiveAPIContext = () => {
|
42 |
+
console.log('๐ฏ LiveAPIContext: Hook being accessed');
|
43 |
const context = useContext(LiveAPIContext);
|
44 |
if (!context) {
|
45 |
+
console.error('โ LiveAPIContext: Hook used outside of provider!');
|
46 |
throw new Error("useLiveAPIContext must be used within a LiveAPIProvider");
|
47 |
}
|
48 |
return context;
|
src/lib/multimodal-live-client.ts
CHANGED
@@ -87,18 +87,21 @@ export class MultimodalLiveClient extends EventEmitter<MultimodalLiveClientEvent
|
|
87 |
|
88 |
connect(config: LiveConfig): Promise<boolean> {
|
89 |
this.config = config;
|
|
|
90 |
|
91 |
const ws = new WebSocket(this.url);
|
92 |
|
93 |
ws.addEventListener("message", async (evt: MessageEvent) => {
|
94 |
if (evt.data instanceof Blob) {
|
|
|
95 |
this.receive(evt.data);
|
96 |
} else {
|
97 |
-
console.log("non
|
98 |
}
|
99 |
});
|
100 |
return new Promise((resolve, reject) => {
|
101 |
const onError = (ev: Event) => {
|
|
|
102 |
this.disconnect(ws);
|
103 |
const message = `Could not connect to "${this.url}"`;
|
104 |
this.log(`server.${ev.type}`, message);
|
@@ -107,9 +110,11 @@ export class MultimodalLiveClient extends EventEmitter<MultimodalLiveClientEvent
|
|
107 |
ws.addEventListener("error", onError);
|
108 |
ws.addEventListener("open", (ev: Event) => {
|
109 |
if (!this.config) {
|
|
|
110 |
reject("Invalid config sent to `connect(config)`");
|
111 |
return;
|
112 |
}
|
|
|
113 |
this.log(`client.${ev.type}`, `connected to socket`);
|
114 |
this.emit("open");
|
115 |
|
@@ -118,12 +123,13 @@ export class MultimodalLiveClient extends EventEmitter<MultimodalLiveClientEvent
|
|
118 |
const setupMessage: SetupMessage = {
|
119 |
setup: this.config,
|
120 |
};
|
|
|
121 |
this._sendDirect(setupMessage);
|
122 |
this.log("client.send", "setup");
|
123 |
|
124 |
ws.removeEventListener("error", onError);
|
125 |
ws.addEventListener("close", (ev: CloseEvent) => {
|
126 |
-
console.log(ev);
|
127 |
this.disconnect(ws);
|
128 |
let reason = ev.reason || "";
|
129 |
if (reason.toLowerCase().includes("error")) {
|
@@ -164,17 +170,20 @@ export class MultimodalLiveClient extends EventEmitter<MultimodalLiveClientEvent
|
|
164 |
blob,
|
165 |
)) as LiveIncomingMessage;
|
166 |
if (isToolCallMessage(response)) {
|
|
|
167 |
this.log("server.toolCall", response);
|
168 |
this.emit("toolcall", response.toolCall);
|
169 |
return;
|
170 |
}
|
171 |
if (isToolCallCancellationMessage(response)) {
|
|
|
172 |
this.log("receive.toolCallCancellation", response);
|
173 |
this.emit("toolcallcancellation", response.toolCallCancellation);
|
174 |
return;
|
175 |
}
|
176 |
|
177 |
if (isSetupCompleteMessage(response)) {
|
|
|
178 |
this.log("server.send", "setupComplete");
|
179 |
this.emit("setupcomplete");
|
180 |
return;
|
|
|
87 |
|
88 |
connect(config: LiveConfig): Promise<boolean> {
|
89 |
this.config = config;
|
90 |
+
console.log('๐ MultimodalLiveClient: Starting WebSocket connection to:', this.url);
|
91 |
|
92 |
const ws = new WebSocket(this.url);
|
93 |
|
94 |
ws.addEventListener("message", async (evt: MessageEvent) => {
|
95 |
if (evt.data instanceof Blob) {
|
96 |
+
console.log('๐ฉ MultimodalLiveClient: Received blob message');
|
97 |
this.receive(evt.data);
|
98 |
} else {
|
99 |
+
console.log("๐ฉ MultimodalLiveClient: Received non-blob message", evt);
|
100 |
}
|
101 |
});
|
102 |
return new Promise((resolve, reject) => {
|
103 |
const onError = (ev: Event) => {
|
104 |
+
console.error('โ MultimodalLiveClient: WebSocket connection error:', ev);
|
105 |
this.disconnect(ws);
|
106 |
const message = `Could not connect to "${this.url}"`;
|
107 |
this.log(`server.${ev.type}`, message);
|
|
|
110 |
ws.addEventListener("error", onError);
|
111 |
ws.addEventListener("open", (ev: Event) => {
|
112 |
if (!this.config) {
|
113 |
+
console.error('โ MultimodalLiveClient: Invalid config provided');
|
114 |
reject("Invalid config sent to `connect(config)`");
|
115 |
return;
|
116 |
}
|
117 |
+
console.log('โจ MultimodalLiveClient: WebSocket connection established');
|
118 |
this.log(`client.${ev.type}`, `connected to socket`);
|
119 |
this.emit("open");
|
120 |
|
|
|
123 |
const setupMessage: SetupMessage = {
|
124 |
setup: this.config,
|
125 |
};
|
126 |
+
console.log('๐ค MultimodalLiveClient: Sending setup message');
|
127 |
this._sendDirect(setupMessage);
|
128 |
this.log("client.send", "setup");
|
129 |
|
130 |
ws.removeEventListener("error", onError);
|
131 |
ws.addEventListener("close", (ev: CloseEvent) => {
|
132 |
+
console.log('๐ MultimodalLiveClient: WebSocket closed:', ev);
|
133 |
this.disconnect(ws);
|
134 |
let reason = ev.reason || "";
|
135 |
if (reason.toLowerCase().includes("error")) {
|
|
|
170 |
blob,
|
171 |
)) as LiveIncomingMessage;
|
172 |
if (isToolCallMessage(response)) {
|
173 |
+
console.log('๐ ๏ธ MultimodalLiveClient: Received tool call');
|
174 |
this.log("server.toolCall", response);
|
175 |
this.emit("toolcall", response.toolCall);
|
176 |
return;
|
177 |
}
|
178 |
if (isToolCallCancellationMessage(response)) {
|
179 |
+
console.log('๐ซ MultimodalLiveClient: Received tool call cancellation');
|
180 |
this.log("receive.toolCallCancellation", response);
|
181 |
this.emit("toolcallcancellation", response.toolCallCancellation);
|
182 |
return;
|
183 |
}
|
184 |
|
185 |
if (isSetupCompleteMessage(response)) {
|
186 |
+
console.log('๐ MultimodalLiveClient: Setup complete received');
|
187 |
this.log("server.send", "setupComplete");
|
188 |
this.emit("setupcomplete");
|
189 |
return;
|