Skip to content

Commit

Permalink
Tweaks to voice assistant hook (#946)
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasIO authored Aug 20, 2024
1 parent d35dffd commit 45a95dd
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/react/etc/components-react.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -1239,7 +1239,7 @@ export interface VoiceAssistant {
export const VoiceAssistantContext: React_2.Context<VoiceAssistant | undefined>;

// @alpha (undocumented)
export type VoiceAssistantState = 'disconnected' | 'connecting' | 'listening' | 'thinking' | 'speaking';
export type VoiceAssistantState = 'disconnected' | 'connecting' | 'initializing' | 'listening' | 'thinking' | 'speaking';

// @public (undocumented)
export type WidgetState = {
Expand Down
9 changes: 7 additions & 2 deletions packages/react/src/hooks/useVoiceAssistant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { useParticipantAttributes } from './useParticipantAttributes';
export type VoiceAssistantState =
| 'disconnected'
| 'connecting'
| 'initializing'
| 'listening'
| 'thinking'
| 'speaking';
Expand Down Expand Up @@ -46,10 +47,14 @@ export function useVoiceAssistant(): VoiceAssistant {
const state: VoiceAssistantState = React.useMemo(() => {
if (connectionState === ConnectionState.Disconnected) {
return 'disconnected';
} else if (connectionState === ConnectionState.Connecting || !agent || !attributes?.state) {
} else if (
connectionState === ConnectionState.Connecting ||
!agent ||
!attributes?.['agent.state']
) {
return 'connecting';
} else {
return attributes.state as VoiceAssistantState;
return attributes['agent.state'] as VoiceAssistantState;
}
}, [attributes, agent, connectionState]);

Expand Down

0 comments on commit 45a95dd

Please sign in to comment.