Skip to content
This repository was archived by the owner on Mar 8, 2026. It is now read-only.

Commit cdf066d

Browse files
onDisconnect hook for websocket realtime
1 parent 5d8fc3d commit cdf066d

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/websocketAudio.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ interface StartSessionMessage {
1919
type WebSocketMessage = MediaMessage | StartSessionMessage;
2020

2121
export class WebsocketAudio {
22+
onDisconnect: () => void;
2223
private webSocketUrl: string;
2324
private socket: WebSocket | null;
2425
// audio out
@@ -33,6 +34,9 @@ export class WebsocketAudio {
3334
private bufferSize: number; // Define the buffer size for capturing chunks
3435

3536
constructor(webSocketUrl: string) {
37+
this.onDisconnect = () => {
38+
console.log('WebSocket disconnected.');
39+
};
3640
this.webSocketUrl = webSocketUrl;
3741
this.socket = null;
3842
this.outAudioContext = null;
@@ -64,7 +68,7 @@ export class WebsocketAudio {
6468
};
6569

6670
this.socket.onclose = () => {
67-
console.log('WebSocket disconnected.');
71+
this.onDisconnect();
6872
};
6973

7074
this.socket.onmessage = async (event: MessageEvent) => {

0 commit comments

Comments
 (0)