Utilities
logger
Log utility that respects the logLevel configured via OrgaAI.init.
import { logger } from '@orga-ai/core';
logger.debug('Preparing to connect', { roomId });
logger.error('Media capture failed', error);Methods: debug, info, warn, error.
fetchSessionConfig(endpoint)
Fetches session credentials from your backend.
const { ephemeralToken, iceServers } = await fetchSessionConfig('/api/orga/session');| Parameter | Type | Description |
|---|---|---|
endpoint | string | URL returning { ephemeralToken, iceServers }. |
Throws when the response is non-2xx or missing required fields. If you prefer custom logic, supply fetchSessionConfig in OrgaAI.init instead.
getMediaConstraints(config?)
Converts session configuration to getUserMedia constraints.
const constraints = getMediaConstraints({
videoQuality: 'high',
facingMode: 'environment',
});
const stream = await navigator.mediaDevices.getUserMedia(constraints);Defaults:
videoQuality→'medium'facingMode→'user'- Audio disabled (
false) — enable audio by adding tracks manually.
connectToRealtime({ ephemeralToken, peerConnection, gathered })
Sends your WebRTC offer and ICE candidates to Orga’s realtime API, returning the answer and conversation ID.
Important: This function does NOT create the peer connection or offer. You (or your client SDK) must:
- Create the RTCPeerConnection
- Gather ICE candidates
- Create the offer
- Set local description
Then call this function to send the offer to Orga.
// You must create the peer connection and offer first
const pc = new RTCPeerConnection({ iceServers });
const offer = await pc.createOffer();
await pc.setLocalDescription(offer);
const candidates = await gatherIceCandidates(pc);
// Then send via Core
const { answer, conversation_id } = await connectToRealtime({
ephemeralToken,
peerConnection: {
localDescription: {
sdp: pc.localDescription?.sdp,
type: pc.localDescription?.type,
},
},
gathered: candidates,
});
// You must set the remote description
await pc.setRemoteDescription(answer);| Parameter | Type | Description |
|---|---|---|
ephemeralToken | string | Token issued by fetchSessionConfig. |
peerConnection | { localDescription: { sdp?: string; type?: string } | null } | Object with local description (sdp and type). |
gathered | RTCIceCandidateInit[] | ICE candidates collected during offer creation. |
Last updated on