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

@vibe-rtc/rtc-core

v0.4.0

Published

[![npm version](https://img.shields.io/npm/v/@vibe-rtc/rtc-core)](https://www.npmjs.com/package/@vibe-rtc/rtc-core)

Downloads

22

Readme

@vibe-rtc/rtc-core

npm version

Core WebRTC signaling/transport package with reconnect behavior and typed errors.

Install

pnpm add @vibe-rtc/rtc-core

Main API

  • RTCSignaler
  • RTCError, RTCErrorCode, toRTCError, isRTCError
  • withDefaultIceServers, DEFAULT_ICE_SERVERS
  • SignalDB interface for custom signaling backends

SignalDB Contract

Implement SignalDB from src/types.tsx with methods for:

  • room lifecycle: createRoom, joinRoom(role?), getRoom, endRoom
  • SDP exchange: getOffer, setOffer, clearOffer, setAnswer, clearAnswer
  • ICE exchange: add/subscribe for caller/callee candidate streams
  • cleanup: clearCallerCandidates, clearCalleeCandidates

For multi-tab safety, adapters should also expose room slot ownership in RoomDoc.slots:

  • slots.caller.participantId/sessionId/...
  • slots.callee.participantId/sessionId/...

Quick Example

import { RTCSignaler } from '@vibe-rtc/rtc-core'

const signaler = new RTCSignaler('caller', signalDb, {
  debug: true,
  waitReadyTimeoutMs: 10000,
  rtcConfiguration: {
    iceServers: [
      { urls: ['stun:stun1.l.google.com:19302', 'stun:stun2.l.google.com:19302'] },
    ],
  },
})

const roomId = await signaler.createRoom()
await signaler.joinRoom(roomId)
await signaler.connect()

await signaler.sendReliable('hello')
await signaler.reconnectSoft()
await signaler.reconnectHard({ awaitReadyMs: 15000 })

await signaler.endRoom()

Runtime Options

  • debug: enables internal console logs (console.log/console.error).
    By default logs are enabled only in test runtime.
  • waitReadyTimeoutMs: default timeout for waitReady() and reconnectHard() if no timeout is passed explicitly.
  • connectionStrategy: "LAN_FIRST" (default), "DEFAULT" or "BROWSER_NATIVE".
    • "LAN_FIRST" starts with host-only LAN candidates and no STUN/TURN, then falls back to STUN on timeout.
    • "DEFAULT" creates RTCPeerConnection with regular STUN behavior immediately.
    • "BROWSER_NATIVE" passes full ICE config (stun/turn) to browser and lets WebRTC choose route natively.
  • lanFirstTimeoutMs: LAN-first fallback timeout in milliseconds (default 1800).
  • stunServers: STUN servers used in fallback/default STUN mode.
    Defaults to [{ urls: "stun:stun.l.google.com:19302" }].
  • rtcConfiguration: optional RTCPeerConnection config.
    If omitted (or if iceServers is empty), rtc-core injects default STUN servers.

LAN-first Strategy

With connectionStrategy: "LAN_FIRST":

  • Phase LAN: RTCPeerConnection starts with iceServers: [] and only typ host candidates are sent/accepted.
  • Phase STUN: if not connected before lanFirstTimeoutMs, the current peer is closed and rebuilt with STUN enabled.
  • Signaling payload format is backward-compatible. Signaling messages include sessionId and stale messages from old sessions are ignored.
  • Debug snapshots (onDebug) include strategy phase, candidate counters by type (host/srflx/relay) and selected ICE route from getStats() (transport.selectedCandidatePairId / nominated fallback).

Browser-native Strategy

With connectionStrategy: "BROWSER_NATIVE":

  • RTCPeerConnection is created with the full configured iceServers list (no STUN/TURN split).
  • ICE candidates are not filtered by transport phase (only stale-session safety checks remain).
  • Path selection is delegated to browser ICE agent (native WebRTC behavior).

Takeover / Session Isolation

rtc-core supports "last tab wins" for the same role in the same room:

  • adapter marks each role slot with participantId + sessionId
  • any incoming offer/answer/candidate with foreign sessionId is ignored as stale
  • if current role slot owner changes (participantId mismatch) active signaler stops with INVALID_STATE (takeover detected)
  • if role slot keeps same participant but sessionId changes, it is also treated as takeover (stale tab / old session)
  • during takeover shutdown hangup() skips best-effort signalDb.leaveRoom() write to avoid stale-tab writes

This prevents old tabs from corrupting signaling state after takeover/reload.

Error Handling

Use RTCErrorCode for stable UI/test handling:

  • ROOM_NOT_SELECTED
  • ROOM_NOT_FOUND
  • AUTH_REQUIRED
  • DB_UNAVAILABLE
  • SIGNAL_TIMEOUT
  • WAIT_READY_TIMEOUT
  • SIGNALING_FAILED
  • INVALID_STATE
  • UNKNOWN

Development

pnpm --filter @vibe-rtc/rtc-core build
pnpm --filter @vibe-rtc/rtc-core test