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

@webrtc2/types

v1.0.0

Published

WebRTC2 Types - Comprehensive TypeScript definitions for WebRTC cross-platform development including React Native, Web, and Electron type definitions

Readme

@webrtc2/types - WebRTC TypeScript Definitions

npm version TypeScript WebRTC

Comprehensive TypeScript definitions for WebRTC cross-platform development - Complete type safety for React Native, Web, and Electron WebRTC applications.

🎯 WebRTC TypeScript Made Simple

@webrtc2/types provides complete TypeScript definitions for:

  • 🔗 RTCPeerConnection Types: Full WebRTC API coverage
  • 🎥 Media Stream Types: Video, audio, and screen sharing
  • 🧊 ICE & Signaling Types: Connection establishment
  • 📱 Cross-Platform Types: React Native, Web, Electron
  • ⚡ Event Types: Type-safe event handling
  • 🏠 Room & Participant Types: Multi-user communication

📦 Installation

npm install @webrtc2/types

🎯 Type Definitions

Core WebRTC Types

import {
  RTCConnectionConfig,
  ConnectionState,
  WebRTCError,
  ICEConnectionState
} from '@webrtc2/types';

// WebRTC configuration with type safety
const config: RTCConnectionConfig = {
  iceServers: [
    { urls: 'stun:stun.l.google.com:19302' },
    {
      urls: 'turn:your-turn-server.com:3478',
      username: 'user',
      credential: 'password'
    }
  ],
  iceCandidatePoolSize: 10,
  bundlePolicy: 'max-bundle'
};

// Connection state management
const handleStateChange = (state: ConnectionState) => {
  switch (state) {
    case 'connecting':
      console.log('Establishing connection...');
      break;
    case 'connected':
      console.log('Connected successfully!');
      break;
    case 'disconnected':
      console.log('Connection lost');
      break;
    case 'failed':
      console.error('Connection failed');
      break;
  }
};

Media Stream Types

import {
  MediaStreamConstraints,
  MediaDeviceInfo,
  VideoConstraints,
  AudioConstraints
} from '@webrtc2/types';

// Type-safe media constraints
const videoConstraints: VideoConstraints = {
  width: { ideal: 1280, max: 1920 },
  height: { ideal: 720, max: 1080 },
  frameRate: { ideal: 30, max: 60 },
  facingMode: 'user'
};

const audioConstraints: AudioConstraints = {
  echoCancellation: true,
  noiseSuppression: true,
  autoGainControl: true,
  sampleRate: 48000
};

const mediaConstraints: MediaStreamConstraints = {
  video: videoConstraints,
  audio: audioConstraints
};

// Device enumeration with types
const handleDevices = (devices: MediaDeviceInfo[]) => {
  const cameras = devices.filter(d => d.kind === 'videoinput');
  const microphones = devices.filter(d => d.kind === 'audioinput');
  const speakers = devices.filter(d => d.kind === 'audiooutput');
};

Signaling Types

import {
  SignalingMessage,
  OfferMessage,
  AnswerMessage,
  ICECandidateMessage,
  SignalingEvent
} from '@webrtc2/types';

// Type-safe signaling messages
const handleSignalingMessage = (message: SignalingMessage) => {
  switch (message.type) {
    case 'offer':
      const offer = message as OfferMessage;
      console.log('Received offer from:', offer.from);
      break;
    
    case 'answer':
      const answer = message as AnswerMessage;
      console.log('Received answer from:', answer.from);
      break;
    
    case 'ice-candidate':
      const candidate = message as ICECandidateMessage;
      console.log('Received ICE candidate:', candidate.candidate);
      break;
  }
};

// Event handling with types
const signaling = {
  on: <T extends SignalingEvent>(
    event: T,
    handler: (data: SignalingEventData[T]) => void
  ) => {
    // Type-safe event handling
  }
};

Room & Participant Types

import {
  Room,
  Participant,
  RoomSettings,
  ParticipantRole,
  RoomEvent
} from '@webrtc2/types';

// Room configuration
const roomSettings: RoomSettings = {
  maxParticipants: 50,
  enableVideo: true,
  enableAudio: true,
  enableScreenShare: true,
  enableChat: true,
  recordSession: false
};

// Participant management
const participant: Participant = {
  id: 'user-123',
  name: 'John Doe',
  role: 'participant',
  isVideoEnabled: true,
  isAudioEnabled: true,
  isScreenSharing: false,
  joinedAt: new Date(),
  lastSeen: new Date()
};

// Room state
const room: Room = {
  id: 'room-456',
  name: 'Team Meeting',
  settings: roomSettings,
  participants: [participant],
  createdAt: new Date(),
  isActive: true
};

// Type-safe room events
const handleRoomEvent = (event: RoomEvent) => {
  switch (event.type) {
    case 'participant-joined':
      console.log('User joined:', event.participant.name);
      break;
    case 'participant-left':
      console.log('User left:', event.participant.name);
      break;
    case 'media-state-changed':
      console.log('Media state changed:', event.mediaState);
      break;
  }
};

🌐 Cross-Platform Types

React Native Types

import {
  ReactNativeMediaStream,
  ReactNativeRTCView,
  ReactNativeMediaConstraints
} from '@webrtc2/types';

// React Native specific constraints
const rnConstraints: ReactNativeMediaConstraints = {
  video: {
    width: 640,
    height: 480,
    frameRate: 30,
    facingMode: 'user'
  },
  audio: true
};

// RTCView component props
interface RTCViewProps extends ReactNativeRTCView {
  streamURL: string;
  mirror?: boolean;
  objectFit?: 'contain' | 'cover';
}

Electron Types

import {
  ElectronWebRTCConfig,
  ElectronMediaAccess,
  DesktopCapturerSource
} from '@webrtc2/types';

// Electron-specific configuration
const electronConfig: ElectronWebRTCConfig = {
  webSecurity: false,
  nodeIntegration: true,
  contextIsolation: false,
  enableRemoteModule: true
};

// Desktop screen capture
const screenSources: DesktopCapturerSource[] = [
  {
    id: 'screen:0',
    name: 'Entire Screen',
    thumbnail: Buffer.from('...'),
    display_id: '0'
  }
];

Web Browser Types

import {
  WebRTCBrowserSupport,
  BrowserCapabilities,
  WebRTCAdapter
} from '@webrtc2/types';

// Browser compatibility
const browserSupport: WebRTCBrowserSupport = {
  webrtc: true,
  getUserMedia: true,
  getDisplayMedia: true,
  dataChannels: true,
  rtcStats: true
};

// Feature detection
const capabilities: BrowserCapabilities = {
  video: {
    codecs: ['VP8', 'VP9', 'H264'],
    maxResolution: { width: 1920, height: 1080 },
    maxFrameRate: 60
  },
  audio: {
    codecs: ['OPUS', 'G722', 'PCMU'],
    echoCancellation: true,
    noiseSuppression: true
  }
};

🔧 Utility Types

Generic WebRTC Types

import {
  WebRTCEvent,
  WebRTCEventHandler,
  WebRTCPromise,
  WebRTCCallback
} from '@webrtc2/types';

// Event handling utilities
type EventMap = {
  'connected': void;
  'disconnected': void;
  'stream': MediaStream;
  'error': WebRTCError;
};

class WebRTCEventEmitter {
  on<K extends keyof EventMap>(
    event: K,
    handler: WebRTCEventHandler<EventMap[K]>
  ): void;
  
  emit<K extends keyof EventMap>(
    event: K,
    data: EventMap[K]
  ): void;
}

// Promise-based API types
type ConnectResult = WebRTCPromise<{
  peerId: string;
  connectionState: ConnectionState;
}>;

type MediaResult = WebRTCPromise<{
  stream: MediaStream;
  devices: MediaDeviceInfo[];
}>;

Configuration Types

import {
  WebRTCConfig,
  STUNConfig,
  TURNConfig,
  SignalingConfig
} from '@webrtc2/types';

// Complete configuration interface
interface AppWebRTCConfig extends WebRTCConfig {
  stun: STUNConfig;
  turn: TURNConfig;
  signaling: SignalingConfig;
}

const config: AppWebRTCConfig = {
  stun: {
    urls: ['stun:stun.l.google.com:19302']
  },
  turn: {
    urls: 'turn:your-server.com:3478',
    username: 'user',
    credential: 'pass'
  },
  signaling: {
    url: 'wss://signaling.example.com',
    reconnectInterval: 5000,
    maxReconnectAttempts: 10
  }
};

📚 Type Exports

// Core WebRTC types
export * from './webrtc';
export * from './peer-connection';
export * from './media-stream';
export * from './ice';

// Platform-specific types
export * from './react-native';
export * from './electron';
export * from './web';

// Application types
export * from './room';
export * from './participant';
export * from './signaling';

// Utility types
export * from './events';
export * from './config';
export * from './errors';

🔍 Type Checking Examples

import { WebRTCConnection } from '@webrtc2/types';

// Type-safe WebRTC usage
const connection: WebRTCConnection = {
  async connect(peerId: string) {
    // TypeScript ensures correct parameter types
    return Promise.resolve();
  },
  
  on(event, handler) {
    // Event names and handler signatures are type-checked
  },
  
  addStream(stream) {
    // MediaStream type is enforced
  }
};

📚 Related Packages

🤝 Contributing

We welcome contributions! Please see our Contributing Guide for details.

📄 License

MIT License - see LICENSE for details.


Keywords: WebRTC TypeScript, WebRTC types, RTCPeerConnection types, WebRTC definitions, TypeScript WebRTC, React Native WebRTC types, Electron WebRTC types, WebRTC interfaces, type safety WebRTC