Skip to content

Commit

Permalink
fix stale onMessage prop (#251)
Browse files Browse the repository at this point in the history
  • Loading branch information
yinishi authored Aug 27, 2024
1 parent 6539dbe commit 6510d05
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 7 deletions.
2 changes: 1 addition & 1 deletion packages/embed-react/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@humeai/voice-embed-react",
"version": "0.1.11",
"version": "0.1.12-beta.1",
"description": "",
"main": "./dist/index.js",
"module": "./dist/index.mjs",
Expand Down
2 changes: 1 addition & 1 deletion packages/embed/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@humeai/voice-embed",
"version": "0.1.11",
"version": "0.1.12-beta.1",
"description": "",
"main": "./dist/index.js",
"module": "./dist/index.mjs",
Expand Down
2 changes: 1 addition & 1 deletion packages/react/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@humeai/voice-react",
"version": "0.1.11",
"version": "0.1.12-beta.1",
"description": "",
"main": "./dist/index.js",
"module": "./dist/index.mjs",
Expand Down
9 changes: 7 additions & 2 deletions packages/react/src/lib/VoiceProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,9 @@ const VoiceContext = createContext<VoiceContextType | null>(null);

export type VoiceProviderProps = PropsWithChildren<SocketConfig> & {
sessionSettings?: Hume.empathicVoice.SessionSettings;
onMessage?: (message: Hume.empathicVoice.SubscribeEvent) => void;
onMessage?: (
message: Hume.empathicVoice.JsonMessage & { receivedAt: Date },
) => void;
onError?: (err: VoiceError) => void;
onOpen?: () => void;
onClose?: Hume.empathicVoice.chat.ChatSocket.EventHandlers['close'];
Expand Down Expand Up @@ -141,10 +143,13 @@ export const VoiceProvider: FC<VoiceProviderProps> = ({
const onClose = useRef(props.onClose ?? noop);
onClose.current = props.onClose ?? noop;

const onMessage = useRef(props.onMessage ?? noop);
onMessage.current = props.onMessage ?? noop;

const toolStatus = useToolStatus();

const messageStore = useMessages({
sendMessageToParent: props.onMessage,
sendMessageToParent: onMessage.current,
messageHistoryLimit,
});

Expand Down
3 changes: 1 addition & 2 deletions packages/react/src/lib/useMessages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,8 @@ export const useMessages = ({
default:
break;
}
// eslint-disable-next-line react-hooks/exhaustive-deps
},
[],
[messageHistoryLimit, sendMessageToParent],
);

const onPlayAudio = useCallback(
Expand Down

0 comments on commit 6510d05

Please sign in to comment.