Skip to content

WebRTC Quick Start

@moveris/webrtc sends captured frames over a WebRTC DataChannel instead of repeated HTTPS POSTs. One peer connection carries all frames; an observer service runs inference and returns the verdict.

In plain terms

The usual SDK path uploads each batch of frames with REST. WebRTC opens a single live connection to a Moveris observer, streams PNG frames over that channel, and receives the verdict when enough frames arrive. Use it when you want lower transport overhead and your deployment includes an observer with a /kvs/config endpoint.

Observer required

WebRTC transport needs a Moveris observer that exposes GET /kvs/config (temporary AWS KVS credentials and ICE servers). This is separate from the standard https://api.moveris.com REST base URL. Contact the Moveris team for observer provisioning before integrating.

How It Works

  1. Your app calls connect() (or useWebRTCLivenessstart()).
  2. The client fetches observer config from observerConfigUrl.
  3. An RTCPeerConnection and DataChannel named liveness are established against AWS KVS signaling.
  4. Captured PNG frames are sent in 16 KB chunks over the DataChannel.
  5. The observer runs inference and returns a JSON verdict on the same channel.

Camera access is still your responsibility—pair WebRTC transport with @moveris/react capture hooks or your own pipeline.

Install

npm install @moveris/react @moveris/webrtc @moveris/shared
npm install @moveris/webrtc
pnpm add @moveris/react @moveris/webrtc @moveris/shared

React Example

import { useWebRTCLiveness } from '@moveris/react';

function WebRTCLivenessCheck() {
  const { state, result, progress, start, captureFrame, reset } = useWebRTCLiveness({
    observerConfigUrl: 'https://your-observer.example.com/kvs/config',
    model: 'mixed-30-v3_1',
    apiKey: 'sk-your-api-key',
    frameCount: 30,
    onResult: (r) => console.log('Verdict:', r.verdict),
    onError: (err) => console.error(err),
  });

  return (
    <div>
      <p>State: {state}</p>
      <p>Progress: {progress.current}/{progress.total}</p>
      <button onClick={start} disabled={state !== 'idle'}>Start</button>
      <button onClick={reset}>Reset</button>
      {result && <p>{result.verdict}  {result.scorePct}%</p>}
    </div>
  );
}

Wire captureFrame(pixels, timestampMs) to your camera pipeline—for example, call it from useSmartFrameCapture when a quality-gated frame is ready.

Framework-Agnostic Example

import { WebRTCLivenessClient } from '@moveris/webrtc';

const client = new WebRTCLivenessClient({
  observerConfigUrl: 'https://your-observer.example.com/kvs/config',
  model: 'mixed-30-v3_1',
  apiKey: 'sk-your-api-key',
  onResult: (result) => console.log(result.verdict),
  onProgress: (received, required) => console.log(`${received}/${required}`),
});

await client.connect();

const frames = capturedFrames.map((pixels, index) => ({
  index,
  timestampMs: Date.now(),
  pixels, // base64 PNG
}));

const result = await client.sendFrames(frames);
client.disconnect();

Observer Config URL

observerConfigUrl must point to the observer's /kvs/config route. The response includes the KVS channel ARN, region, temporary AWS credentials, and ICE servers. Both snake_case and camelCase response keys are accepted.

Environment Example
Deployed observer https://your-observer.example.com/kvs/config

Contact the Moveris team for observer URLs in non-production environments.

Browser Requirements

Browser Minimum version
Chrome 56+
Firefox 44+
Safari 11+
Edge 79+

Production requires HTTPS (WebRTC camera and peer connections are blocked on insecure origins).

When to Use WebRTC vs REST

Use REST (LivenessClient, useLiveness) Use WebRTC (WebRTCLivenessClient, useWebRTCLiveness)
Standard integration against api.moveris.com Dedicated observer deployment with /kvs/config
No extra infrastructure Lower per-session HTTP overhead for high frame counts
Works from any backend or browser Browser must support RTCPeerConnection + RTCDataChannel

Next Steps