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/sdk-react-native';

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).

flipCamera

() => Promise<void>

Switches between front and back cameras.

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.

cameraPosition

CameraPosition

The current camera position (e.g., "front", "back").

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 (
    <View>
      <Text>Connection: {connectionState}</Text>
      <Text>Mic: {isMicOn ? 'On' : 'Off'}</Text>
      <Button title="Toggle Mic" onPress={toggleMic} />
      <Button title="Start Session" onPress={handleStart} />
      <Button title="End Session" onPress={endSession} />
    </View>
  );
}