Hooks

Documentation for useOrgaAI, including return values and usage examples.

useOrgaAI

Access Orga SDK methods and state in your components

Import

import { useOrgaAI } from '@orga-ai/react';

Returns

Name

Type

Description

startSession

(config?: SessionConfig) => Promise<void>

Starts a new session with optional configuration. Use to initiate an AI conversation.

endSession

() => Promise<void>

Ends the current session, stopping all media streams and connections.

enableMic

() => Promise<void>

Enables the microphone for audio input.

disableMic

() => Promise<void>

Disables the microphone, muting audio input.

toggleMic

() => Promise<void>

Toggles the microphone’s state (on/off).

enableCamera

() => Promise<void>

Enables the camera for video input.

disableCamera

() => Promise<void>

Disables the camera, stopping video input.

toggleCamera

() => Promise<void>

Toggles the camera’s state (on/off).

connectionState

ConnectionState

The current connection state (e.g., "disconnected", "connecting", "connected").

aiAudioStream

MediaStream | null

The AI’s audio stream, or null if not available.

userVideoStream

MediaStream | null

The user’s video stream, or null if not available.

conversationItems

ConversationItem[]

Array of conversation items, including user speech and AI responses.

isCameraOn

boolean

Indicates whether the camera is currently enabled.

isMicOn

boolean

Indicates whether the microphone is currently enabled.

conversationId

string | null

The unique ID of the current conversation, or null if no conversation is active.

model

OrgaAIModel | null

The selected AI model, or default model if not set.

voice

OrgaAIVoice | null

The selected voice for AI responses, or default voice if not set.

temperature

number | null

The sampling temperature for AI responses, or null if not set.

instructions

string | null

Custom instructions for the AI, or null if not set.

modalities

Modality[]

Array of enabled modalities (e.g., audio, video).

updateParams

(params: { model?: OrgaAIModel; voice?: OrgaAIVoice; temperature?: number; instructions?: string; modalities?: Modality[] }) => void

Updates session parameters (e.g., model, voice, temperature).

Usage

const { startSession, endSession, videoStream } = useOrgaAI();

export default function HomeScreen() { 
  const {
    startSession,
    endSession,
    userVideoStream,
    connectionState,
    isMicOn,
    toggleMic,
    toggleCamera,
    updateParams,
  } = useOrgaAI();

  const handleStart = async () => {
    await startSession({
      onSessionConnected: () => console.log('Connected!'),
    });
    updateParams({ model: 'orga-1-beta', voice: 'alloy' });
  };

   return (
    <div>
      <p>Connection: {connectionState}</p>
      <p>Mic: {isMicOn ? 'On' : 'Off'}</p>
      <button onClick={toggleMic}>Toggle Mic</button>
      <button onClick={handleStart}>Start Session</button>
      <button onClick={endSession}>End Session</button>
    </div>
  );
}