Skip to content

Commit b5476a8

Browse files
authored
catch all message types (#245)
1 parent e54da14 commit b5476a8

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

packages/react/src/lib/useVoiceClient.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ import { useCallback, useRef, useState } from 'react';
44

55
import { type AuthStrategy } from './auth';
66

7+
const isNever = (_n: never) => {
8+
return;
9+
};
10+
711
export type SocketConfig = {
812
auth: AuthStrategy;
913
hostname?: string;
@@ -95,6 +99,7 @@ export const useVoiceClient = (props: {
9599
if (message.type === 'audio_output') {
96100
const messageWithReceivedAt = { ...message, receivedAt: new Date() };
97101
onAudioMessage.current?.(messageWithReceivedAt);
102+
return;
98103
}
99104

100105
if (
@@ -109,6 +114,7 @@ export const useVoiceClient = (props: {
109114
) {
110115
const messageWithReceivedAt = { ...message, receivedAt: new Date() };
111116
onMessage.current?.(messageWithReceivedAt);
117+
return;
112118
}
113119

114120
if (message.type === 'tool_call') {
@@ -157,7 +163,12 @@ export const useVoiceClient = (props: {
157163
onError.current?.('Invalid response from tool call');
158164
}
159165
});
166+
return;
160167
}
168+
169+
// asserts that all message types are handled
170+
isNever(message);
171+
return;
161172
});
162173

163174
client.current.on('close', (event) => {

0 commit comments

Comments
 (0)