# Live video browser transport example

Copy `video-client.js` and `avatar-audio.js` into your browser application and
install `@anam-ai/js-sdk@4.20.0`. This is an integration example, not a complete
customer authentication or billing system.

Your authenticated backend must:

1. Call `POST https://locallanguagelab.com/api/v1/company/agents/{id}/sessions`
   with its secret `X-API-Key`, `{mode:"video",transcript_consent:false}` and
   `Content-Type: application/json`. Return the resulting session to that user.
2. Proxy `POST /lab-avatar/v1/engine/session` to the fixed Lab endpoint
   `https://locallanguagelab.com/api/anam-session/v1/engine/session`, preserving
   the local `Authorization` credential sent by the SDK and the bounded JSON
   body. Authenticate the user, limit request size/rate, preserve status/JSON,
   disable retries, and set `Cache-Control: no-store`. Do not proxy arbitrary URLs.

After a user clicks your Start button and you have explained transcript consent:

```js
import { connectVideoAgent } from './video-client.js';
const controller = new AbortController();
// Wire Hang up/navigation to controller.abort() BEFORE starting, including
// while the browser is waiting for microphone permission.
const response = await fetch('/your-backend/create-session', {
  method: 'POST', signal: controller.signal, headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({ transcript_consent: false }),
});
if (!response.ok) throw new Error('Session could not be created');
const session = await response.json();
const call = await connectVideoAgent(
  session, 'agent-video', `${location.origin}/lab-avatar`, console.log, controller.signal,
);
// Hangup and navigation cleanup:
// await call.stop();
```

Render `<video id="agent-video" autoplay playsinline></video>` on the page.
Use HTTPS (localhost is permitted for development). Microphone permission and
an explicit user gesture are required. Display connection/error/closed states
and provide a hangup button. Do not retry session creation automatically.
The sample preserves WAV source rates for avatar speech and sends resampled
24 kHz mono PCM16 microphone frames to the voice gateway.
