Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions packages/react/src/lib/VoiceProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,17 @@ export const VoiceProvider: FC<VoiceProviderProps> = ({
toolStatus,
],
),
onSessionSettings: useCallback(
(sessionSettings: Hume.empathicVoice.SessionSettings) => {
if (checkIsDisconnecting() || checkIsDisconnected()) {
// disconnection in progress, and resources are being cleaned up.
// ignore the message
return;
}
messageStore.createSessionSettingsMessage(sessionSettings);
},
[checkIsDisconnected, checkIsDisconnecting, messageStore],
),
onClientError,
onToolCallError: useCallback(
(message: string, err?: Error) => {
Expand Down
6 changes: 6 additions & 0 deletions packages/react/src/lib/connection-message.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { Hume } from 'hume';
import type { CloseEvent } from 'hume/core';

export type ConnectionMessage =
Expand All @@ -10,4 +11,9 @@ export type ConnectionMessage =
code: CloseEvent['code'];
reason: CloseEvent['reason'];
receivedAt: Date;
}
| {
type: 'session_settings';
sessionSettings: Hume.empathicVoice.SessionSettings;
receivedAt: Date;
};
17 changes: 17 additions & 0 deletions packages/react/src/lib/useMessages.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { Hume } from 'hume';
import type { CloseEvent } from 'hume/core';
import { useCallback, useState } from 'react';

Expand Down Expand Up @@ -49,6 +50,21 @@ export const useMessages = ({
);
}, []);

const createSessionSettingsMessage = useCallback(
(sessionSettings: Hume.empathicVoice.SessionSettings) => {
setMessages((prev) =>
prev.concat([
{
type: 'session_settings',
sessionSettings,
receivedAt: new Date(),
},
]),
);
},
[],
);

const createDisconnectMessage = useCallback((event: CloseEvent) => {
setMessages((prev) =>
prev.concat([
Expand Down Expand Up @@ -221,6 +237,7 @@ export const useMessages = ({
return {
createConnectMessage,
createDisconnectMessage,
createSessionSettingsMessage,
onMessage,
onPlayAudio,
clearMessages,
Expand Down
6 changes: 6 additions & 0 deletions packages/react/src/lib/useVoiceClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@
export const useVoiceClient = (props: {
onAudioMessage?: (message: AudioOutputMessage) => void;
onMessage?: (message: JSONMessage) => void;
onSessionSettings?: (sessionSettings: Hume.empathicVoice.SessionSettings) => void;

Check failure on line 91 in packages/react/src/lib/useVoiceClient.ts

View workflow job for this annotation

GitHub Actions / pr-check

Replace `sessionSettings:·Hume.empathicVoice.SessionSettings` with `⏎····sessionSettings:·Hume.empathicVoice.SessionSettings,⏎··`
onToolCall?: ToolCallHandler;
onToolCallError?: (message: string, error?: Error) => void;
onClientError?: (message: string, error?: Error) => void;
Expand All @@ -112,6 +113,9 @@
const onMessage = useRef<typeof props.onMessage>(props.onMessage);
onMessage.current = props.onMessage;

const onSessionSettings = useRef<typeof props.onSessionSettings>(props.onSessionSettings);

Check failure on line 116 in packages/react/src/lib/useVoiceClient.ts

View workflow job for this annotation

GitHub Actions / pr-check

Replace `props.onSessionSettings` with `⏎····props.onSessionSettings,⏎··`
onSessionSettings.current = props.onSessionSettings;

const onToolCall = useRef<typeof props.onToolCall>(props.onToolCall);
onToolCall.current = props.onToolCall;

Expand Down Expand Up @@ -198,6 +202,7 @@
signal.removeEventListener('abort', abortHandler);
if (postConnectSettings) {
socket.sendSessionSettings(postConnectSettings);
onSessionSettings.current?.(postConnectSettings);
}
resolve(VoiceReadyState.OPEN);
}
Expand Down Expand Up @@ -320,6 +325,7 @@
return;
}
client.current?.sendSessionSettings(sessionSettings);
onSessionSettings.current?.(sessionSettings);
},
[readyState],
);
Expand Down
Loading