Hooks
The React Native SDK exports a single primary hook: useOrgaAI().
It provides session control, device management, media streams, and AI state within your React Native components.
useOrgaAI()
Access Orga SDK methods and session state anywhere in your app.
import { useOrgaAI } from "@orga-ai/react-native";
const {
startSession,
endSession,
enableMic,
disableMic,
toggleMic,
enableCamera,
disableCamera,
toggleCamera,
flipCamera,
connectionState,
aiAudioStream,
userVideoStream,
userAudioStream,
conversationItems,
isCameraOn,
isMicOn,
conversationId,
model,
voice,
temperature,
instructions,
modalities,
updateParams,
} = useOrgaAI();useOrgaAI() must be used within an <OrgaAIProvider>.
Returns
| Name | Type | Description |
|---|---|---|
startSession | (config?: SessionConfig) => Promise<void> | Starts a real‑time AI session, requesting tokens and beginning WebRTC negotiation. |
endSession | () => Promise<void> | Ends the current session and releases all media and network resources. |
enableMic / disableMic / toggleMic | () => Promise<void> | Enable, disable, or toggle microphone state. |
enableCamera / disableCamera / toggleCamera | () => Promise<void> | Enable, disable, or toggle camera visibility. |
flipCamera | () => Promise<void> | Switches between front and back cameras (uses native camera switching). |
connectionState | ConnectionState | Connection lifecycle state: "disconnected", "connecting", "connected". |
aiAudioStream | MediaStream | null | AI audio stream (for playback via react‑native‑webrtc). |
userVideoStream | MediaStream | null | Local video stream for preview and camera view components. |
userAudioStream | MediaStream | null | Local audio stream from mic capture. |
conversationItems | ConversationItem[] | Conversation messages and transcriptions in the current session. |
isCameraOn / isMicOn | boolean | True when each device is currently active. |
conversationId | string | null | Unique ID of the active conversation. |
model / voice / temperature / instructions / modalities | Various | Current AI configuration values. |
updateParams | (params) => void | Dynamically updates session parameters while active. |
Example Usage
app/index.tsx
'use client'
import { useOrgaAI, OrgaAICameraView, OrgaAIControls } from "@orga-ai/react-native";
export default function Home() {
const {
startSession,
endSession,
toggleMic,
toggleCamera,
flipCamera,
connectionState,
userVideoStream,
isMicOn,
isCameraOn,
updateParams,
} = useOrgaAI();
const handleStart = async () => {
await startSession({
onSessionConnected: () => console.log("Connected!"),
});
updateParams({ model: "orga-1-beta", voice: "alloy" });
};
return (
<>
<OrgaAICameraView streamURL={userVideoStream?.toURL()}>
<OrgaAIControls
connectionState={connectionState}
isCameraOn={isCameraOn}
isMicOn={isMicOn}
onStartSession={handleStart}
onEndSession={endSession}
onToggleCamera={toggleCamera}
onToggleMic={toggleMic}
onFlipCamera={flipCamera}
/>
</OrgaAICameraView>
</>
);
}This snippet:
- Starts a real-time AI session.
- Streams camera and microphone to Orga AI via WebRTC.
- Displays the built‑in control overlay through
<OrgaAIControls>. - Allows toggling and flipping the camera natively.
Notes
- ✅ Permission flow – iOS/Android devices must grant camera/mic permissions before the session starts.
- 🪄 Debugging – Use
logLevel: 'debug'inOrgaAI.init()to log detailed connection events to Metro. - 📲 Physical device testing – Video streams require actual hardware; emulators often lack camera support.
Next Steps
- Components → UI primitives such as
<OrgaAICameraView>and<OrgaAIControls>for live video and media control. - Types → TypeScript types and enums exported by the SDK, including React Native–specific additions.
- Troubleshooting → Troubleshooting guide.
Last updated on