Skip to content

Commit 9c45e96

Browse files
session created tweaks; readme
1 parent 1ffe9eb commit 9c45e96

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

index.html

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,12 @@ <h1>Chat with GPT-4 Realtime with WebRTC</h1>
250250
const itemId = message.item_id;
251251

252252
switch (message.type) {
253+
case "session.created":
254+
const expiresAt = new Date(message?.session?.expires_at * 1000);
255+
console.log(`Session created and will expire at ${expiresAt}`, message);
256+
toggleSessionButtons(true);
257+
break;
258+
253259
case "input_audio_buffer.speech_started":
254260
userMessages[itemId] = {message: ""};
255261
appendOrUpdateLog(`User: ...`, "user-message", itemId);
@@ -300,6 +306,7 @@ <h1>Chat with GPT-4 Realtime with WebRTC</h1>
300306
console.log("start_session");
301307
startButtonEl.disabled = true;
302308

309+
// API Key required
303310
const apiKey = keyEl.value;
304311
if (!apiKey || apiKey === "Your OPENAI_API_KEY from platform.openai.com") {
305312
console.error("No OpenAI API Key provided");
@@ -308,7 +315,6 @@ <h1>Chat with GPT-4 Realtime with WebRTC</h1>
308315
return;
309316
}
310317

311-
312318
// Capture the local mic
313319
// technically optional for the API, but required in this example
314320
let stream;
@@ -370,13 +376,13 @@ <h1>Chat with GPT-4 Realtime with WebRTC</h1>
370376
pc.addEventListener("connectionstatechange", () => {
371377
if (pc.connectionState === "connected") {
372378
clearTimeout(timeout);
379+
console.log("Peer connection established!");
373380
resolve();
374381
}
375382
});
376383
});
377384

378-
toggleSessionButtons(true);
379-
console.log("Realtime session started!");
385+
// toggleSessionButtons(true);
380386
} catch (err) {
381387
console.error("Error starting session:", err);
382388
appendOrUpdateLog("Error starting session. Please try again.", "system-message");

0 commit comments

Comments
 (0)