npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@thrivereflections/realtime-transport-webrtc

v0.1.0

Published

WebRTC transport for the Thrive Realtime Voice Platform

Readme

@thrive/realtime-transport-webrtc

WebRTC transport implementation for the Thrive Realtime Voice Platform.

Overview

This package provides a WebRTC-based transport for real-time voice communication using OpenAI's Realtime API. It handles peer-to-peer audio streaming and data channel communication.

Features

  • WebRTC Audio Streaming: Direct peer-to-peer audio communication
  • Data Channel Events: Bidirectional event communication
  • Microphone Access: Automatic microphone setup and management
  • Audio Playback: Real-time audio output
  • Connection Management: Automatic reconnection and error handling
  • ICE Servers: Built-in STUN servers for NAT traversal

Installation

pnpm add @thrive/realtime-transport-webrtc

Usage

Basic Setup

import { createWebRTCTransport } from "@thrive/realtime-transport-webrtc";

const config = {
  voice: "alloy",
  persona: "You are a helpful AI assistant.",
  instructions: "You are a helpful AI assistant.",
  capabilities: ["text", "audio", "tools"],
  featureFlags: {
    memory: "off"
  },
  tools: [
    {
      type: "function",
      name: "echo",
      description: "Echoes back the provided arguments",
      parameters: {
        type: "object",
        properties: {
          message: { type: "string", description: "Message to echo back" }
        },
        required: ["message"]
      }
    }
  ]
};

const deps = {
  getSessionToken: async () => {
    const response = await fetch("/api/realtime/session", {
      method: "POST",
      headers: { "Content-Type": "application/json" },
      body: JSON.stringify(config)
    });
    return response.json();
  }
};

const transport = createWebRTCTransport(config, deps);

// Connect to the transport
await transport.connect({
  token: "your-token",
  onEvent: (event) => console.log("Event:", event)
});

// Send events
transport.send({
  type: "conversation.item.create",
  item: {
    type: "message",
    role: "user",
    content: "Hello!"
  }
});

// Close connection
await transport.close();

Configuration

The transport accepts the following configuration:

interface WebRTCTransportConfig {
  voice?: string;                    // Voice model (e.g., "alloy")
  persona?: string;                  // AI persona description
  instructions?: string;             // System instructions
  capabilities?: string[];           // Supported capabilities
  featureFlags?: {                   // Feature flags
    memory?: string;
  };
  tools?: Array<{                    // Available tools
    type: string;
    name: string;
    description: string;
    parameters: Record<string, unknown>;
  }>;
}

Dependencies

The transport requires a session token provider:

interface WebRTCTransportDeps {
  getSessionToken: () => Promise<{
    client_secret: { value: string; expires_at: string };
    session_id: string;
    model: string;
  }>;
}

API Reference

createWebRTCTransport(config, deps)

Creates a WebRTC transport instance.

Parameters:

  • config: Transport configuration
  • deps: Required dependencies

Returns: Transport instance

Transport Methods

The transport implements the Transport interface:

  • connect(opts): Establish WebRTC connection
  • send(event): Send event through data channel
  • close(): Close connection and cleanup resources

Connection Options

interface ConnectOptions {
  token: string;                     // Authentication token
  onEvent: (event: unknown) => void; // Event handler
}

WebRTC Features

Audio Streaming

  • Input: 24kHz mono audio from microphone
  • Output: Real-time audio playback
  • Codec: PCM audio format
  • Quality: High-quality voice communication

Data Channel

  • Protocol: Reliable ordered data channel
  • Events: JSON-serialized event messages
  • Reconnection: Automatic reconnection on channel close
  • Error Handling: Comprehensive error management

ICE Servers

The transport uses Google's public STUN servers:

  • stun:stun.l.google.com:19302
  • stun:stun1.l.google.com:19302

For production use, consider using your own TURN servers for better connectivity.

Browser Support

The transport requires modern browsers with WebRTC support:

  • Chrome 56+
  • Firefox 52+
  • Safari 11+
  • Edge 79+

Required APIs

  • RTCPeerConnection
  • RTCDataChannel
  • MediaDevices.getUserMedia
  • AudioContext (for audio processing)

Error Handling

The transport includes comprehensive error handling:

  • Connection Failures: Automatic retry and fallback
  • Microphone Access: Graceful handling of permission denials
  • Network Issues: Connection state monitoring
  • Data Channel Errors: Automatic reconnection

Performance

Audio Latency

  • Target: <400ms time-to-first-audio
  • Optimization: Direct peer-to-peer connection
  • Buffering: Minimal audio buffering

Resource Usage

  • Memory: Efficient audio buffer management
  • CPU: Optimized audio processing
  • Network: Minimal bandwidth usage

Development

Scripts

  • pnpm build: Build the package
  • pnpm typecheck: Run TypeScript type checking
  • pnpm lint: Run ESLint
  • pnpm clean: Clean build artifacts

Testing

# Run tests
pnpm test

# Run tests in browser
pnpm test:browser

Dependencies

  • @thrive/realtime-contracts: Shared type definitions

License

MIT