11 KiB
@suaveplan/network-transport-webrtc - WebRTC transport plugin for mesh networking: RTCPeerConnection data-channel transport with injectable constructors
Summary
WebRTC transport plugin for mesh networking.
Documentation tree
- data-channel — (no submodules)
- data-channel-manager — (no submodules)
- ice — (no submodules)
- ice-manager — (no submodules)
- mesh — (no submodules)
- webrtc-mesh — (no submodules)
- ping — (no submodules)
- ping-manager — (no submodules)
- plugin — (no submodules)
- plugin — (no submodules)
- signaling-client — Defines the structural contract for any signaling channel used by the WebRTC plugin to exchange offers, answers, and IC…
- websocket-signaling-client — Concrete
SignalingClientimplementation backed by a WebSocket. Handles the boring-but-load-bearing pieces of any sign… - transport — (no submodules)
- transport — (no submodules)
- types — (no submodules)
- types — (no submodules)
- error-codes — Defines the stable error-code registry for the
@suaveplan/network-transport-webrtcpackage. All runtime failures with…
- websocket-signaling-client — Concrete
SignalingClientimplementation backed by a WebSocket. Handles the boring-but-load-bearing pieces of any sign… - transport — (no submodules)- transport — (no submodules)- types — (no submodules)- types — (no submodules)- error-codes — Defines the stable error-code registry for the
@suaveplan/network-transport-webrtcpackage. All runtime failures with… - data-channel-manager — (no submodules)- ice — (no submodules)- ice-manager — (no submodules)- mesh — (no submodules)- webrtc-mesh — (no submodules)- ping — (no submodules)- ping-manager — (no submodules)- plugin — (no submodules)- plugin — (no submodules)- signaling-client — Defines the structural contract for any signaling channel used by the WebRTC plugin to exchange offers, answers, and IC…
- websocket-signaling-client — Concrete
SignalingClientimplementation backed by a WebSocket. Handles the boring-but-load-bearing pieces of any sign… - transport — (no submodules)- transport — (no submodules)- types — (no submodules)- types — (no submodules)- error-codes — Defines the stable error-code registry for the
@suaveplan/network-transport-webrtcpackage. All runtime failures with… - data-channel-manager — (no submodules)- ice — (no submodules)- ice-manager — (no submodules)- mesh — (no submodules)- webrtc-mesh — (no submodules)- ping — (no submodules)- ping-manager — (no submodules)- plugin — (no submodules)- plugin — (no submodules)- signaling-client — Defines the structural contract for any signaling channel used by the WebRTC plugin to exchange offers, answers, and IC…
- websocket-signaling-client — Concrete
SignalingClientimplementation backed by a WebSocket. Handles the boring-but-load-bearing pieces of any sign… - transport — (no submodules)- transport — (no submodules)- types — (no submodules)- types — (no submodules)- error-codes — Defines the stable error-code registry for the
@suaveplan/network-transport-webrtcpackage. All runtime failures with… - data-channel-manager — (no submodules)- ice — (no submodules) - ice-manager — (no submodules)- mesh — (no submodules) - webrtc-mesh — (no submodules)- ping — (no submodules) - ping-manager — (no submodules)- plugin — (no submodules) - plugin — (no submodules)- signaling-client — Defines the structural contract for any signaling channel used by the WebRTC plugin to exchange offers, answers, and IC…
- websocket-signaling-client — Concrete
SignalingClientimplementation backed by a WebSocket. Handles the boring-but-load-bearing pieces of any sign… - transport — (no submodules) - transport — (no submodules)- types — (no submodules) - types — (no submodules)- error-codes — Defines the stable error-code registry for the
@suaveplan/network-transport-webrtcpackage. All runtime failures with…
Purpose
Provides a WebRTC data-channel transport implementation for the @suaveplan/network mesh system. This plugin enables peer-to-peer messaging without requiring a central relay server for data. The transport implements the universal Transport interface and is fully mockable for Node.js testing.
Features
- WebRTCTransport — full
Transportinterface viaRTCPeerConnection+RTCDataChannel - Injectable factories — mockable
PeerConnectionLikefor unit testing - WebRTCPlugin —
NetworkPluginintegration with lifecycle management - JSON serialization — uses
@suaveplan/serializefor envelope encoding - Peer events — automatic connected/disconnected notifications
Usage
Basic Example
import { WebRTCPlugin } from "@suaveplan/network-transport-webrtc";
const plugin = new WebRTCPlugin();
node.use(plugin);
await node.start();
await plugin.transport.connect("peer-1", "signal-address");
Advanced Example
import { WebRTCPlugin } from "@suaveplan/network-transport-webrtc";
const plugin = new WebRTCPlugin({
dataChannelLabel: "mesh",
});
node.use(plugin);
plugin.transport.onMessage((peerId, envelope) => {
console.log("From", peerId, envelope);
});
API Reference
See per-module documentation in src/:
src/transport/—WebRTCTransportsrc/plugin/—WebRTCPluginsrc/types/— mockable interfaces and configuration typessrc/error-codes.ts—NetworkWebRTCError,NETWORK_WEBRTC_CODES
Implementation Notes
The transport is designed for testability. In a browser environment, you provide a factory that creates real RTCPeerConnection instances. In Node.js tests, you provide mock implementations of PeerConnectionLike and DataChannelLike. This decouples the transport logic from the browser WebRTC stack, making the package suitable for universal use despite WebRTC being a browser API.