Simli WebRTC Client

3.0.1 · active · verified Wed Apr 22

SimliClient is a WebRTC frontend client designed for real-time interaction with AI-powered facial recognition and avatar services. It enables developers to integrate live audio and video streaming capabilities into their web applications, specifically for scenarios involving AI-driven avatars or face-based interactions. The current stable version is 3.0.1. While a specific release cadence isn't explicitly stated, the package follows semantic versioning, with major version changes (like the jump to v3) indicating significant updates and potential breaking changes. Its primary differentiator is its focus on streamlining the integration of WebRTC with Simli's AI backend for facial analysis and avatar control, abstracting much of the low-level WebRTC API complexity for these specialized use cases.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize the SimliClient, set up event listeners for connection status, and establish a WebRTC connection. It includes an example of sending dummy audio data after connection and highlights secure API key handling.

import { SimliClient } from 'simli-client';
import type { SimliClientConfig } from 'simli-client';

async function setupSimliConnection() {
  // In a real application, ensure these values are loaded securely (e.g., environment variables)
  const SIMLI_API_KEY = process.env.SIMLI_API_KEY ?? 'your-simli-api-key-here';
  const SIMLI_SERVER_URL = process.env.SIMLI_SERVER_URL ?? 'wss://your.simli.server.com/ws';

  if (SIMLI_API_KEY === 'your-simli-api-key-here') {
    console.warn("WARNING: Please replace 'your-simli-api-key-here' with your actual Simli API key.");
  }
  if (SIMLI_SERVER_URL === 'wss://your.simli.server.com/ws') {
    console.warn("WARNING: Please replace 'your.simli.server.com' with your actual Simli server URL.");
  }

  const config: SimliClientConfig = {
    apiKey: SIMLI_API_KEY,
    serverUrl: SIMLI_SERVER_URL,
    // Optional: avatarId: 'default-avatar',
    // Optional: logLevel: 'info' // 'debug', 'warn', 'error'
  };

  const client = new SimliClient();

  // Attach event listeners for connection status
  client.on('connected', () => {
    console.log('SimliClient: Successfully connected to the server.');
    // You can start sending data here
    // For demonstration, let's send dummy audio for 5 seconds
    const dummyAudio = new Uint8Array(1024).fill(0);
    let sendCount = 0;
    const interval = setInterval(() => {
      if (sendCount < 50) { // Send for 50 * 100ms = 5 seconds
        client.sendAudioData(dummyAudio);
        sendCount++;
      } else {
        clearInterval(interval);
        console.log('SimliClient: Finished sending dummy audio data.');
      }
    }, 100);
  });
  client.on('disconnected', () => console.log('SimliClient: Disconnected from the server.'));
  client.on('failed', (error: Error) => console.error('SimliClient: Connection failed:', error));

  try {
    console.log('SimliClient: Initializing with provided configuration...');
    await client.Initialize(config);
    console.log('SimliClient: Initialization complete. Attempting to start connection...');
    await client.start(); // This establishes the WebRTC connection
    console.log('SimliClient: Connection process initiated.');

    // In a real application, you might acquire a MediaStream from getUserMedia
    // and then use client.listenToMediastreamTrack(audioTrack);

  } catch (error) {
    console.error('SimliClient: Fatal error during setup or connection:', error);
    client.close(); // Ensure resources are cleaned up on failure
  }
}

// Execute the setup function
setupSimliConnection();

view raw JSON →