You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat: The "session request" is no longer managed by the client. The hosting application is expected to manage the session request. This has presented a cleaner and more reliable API for us in production.
BREAKING CHANGE: The sessionRequest argument is no longer part of the constructor. The sessionRequested argument is no longe provided to the getRealtimeEphemeralAPIKey callback. The host application should know what session it wants and can always request whatever session it wants in the getRealtimeEphemeralAPIKey. See the WebRTC example for how to do this.
* A TypeScript client for the OpenAI Realtime API using WebRTC in the browser.
61
58
*/
@@ -78,16 +75,12 @@ export class RealtimeClient {
78
75
/**
79
76
* Create a new client.
80
77
* @param getRealtimeEphemeralAPIKey This is a function that you should implement to return the Ephemeral OpenAI API key that is used to authenticate with the OpenAI Realtime API. It should be an ephemeral key as described at https://platform.openai.com/docs/guides/realtime-webrtc#creating-an-ephemeral-token. You will probably need to make a call to your server here to fetch the key.
81
-
* @param sessionRequested The session parameters you want from the Realtime API. If these are found to be different it will re-request them to try to match this session.
// Listen for server-sent events on the data channel
275
266
this.dataChannel.addEventListener(
276
267
"message",
277
-
this.receiveServerMessage.bind(this)
268
+
this.receiveServerMessage.bind(this),
278
269
)
279
270
this.dataChannel.addEventListener("error",(e)=>{
280
271
log.error("Data channel error from server: %o",e.error)
@@ -308,7 +299,7 @@ export class RealtimeClient {
308
299
this.session=undefined
309
300
this.emitter.dispatchTypedEvent(
310
301
"sessionUpdated",
311
-
newSessionUpdatedEvent(this.session)
302
+
newSessionUpdatedEvent(this.session),
312
303
)
313
304
}
314
305
}
@@ -323,7 +314,7 @@ export class RealtimeClient {
323
314
324
315
this.emitter.dispatchTypedEvent(
325
316
"serverEvent",
326
-
newRealtimeServerEventEvent(parsedEvent)
317
+
newRealtimeServerEventEvent(parsedEvent),
327
318
)
328
319
}
329
320
@@ -383,49 +374,15 @@ export class RealtimeClient {
383
374
client.session=sessionEvent.session
384
375
client.emitter.dispatchTypedEvent(
385
376
"sessionCreated",
386
-
newSessionCreatedEvent(sessionEvent.session)
377
+
newSessionCreatedEvent(sessionEvent.session),
387
378
)
388
-
389
-
if(!client.sessionRequested){
390
-
thrownewError("No session request")
391
-
}
392
-
393
-
// NOTE: When we create a session with OpenAI, it ignores things like input_audio_transcription?.model !== "whisper-1"; So we update it again if it doesn't match the session.
0 commit comments