Skip to Content
🚀 Orga AI is in open beta.

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');
ParameterTypeDescription
endpointstringURL 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:

  1. Create the RTCPeerConnection
  2. Gather ICE candidates
  3. Create the offer
  4. 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);
ParameterTypeDescription
ephemeralTokenstringToken issued by fetchSessionConfig.
peerConnection{ localDescription: { sdp?: string; type?: string } | null }Object with local description (sdp and type).
gatheredRTCIceCandidateInit[]ICE candidates collected during offer creation.
Last updated on