PeerJS wraps WebRTC with a simple JavaScript API for encrypted peer-to-peer data channels and video or audio calls between browsers.
Overview
PeerJS builds on the browser WebRTC stack to offer a configurable peer-to-peer API for both data and media. Developers create a peer identity, connect to remote peers, send serializable payloads, and place calls without hand-rolling signaling and ICE wiring for common cases.
Data connections can carry strings, JSON, ArrayBuffers, and Blobs, which suits files, game state, or structured messages. Media APIs support streaming audio and video for chat-style applications or screen sharing scenarios described in the project examples.
Connections use WebRTC encryption with DTLS by default so payload traffic stays direct between peers rather than through application servers. You can tune ICE servers, debug levels, and serialization formats, and rely on the project cloud signaling server or operate a separate PeerServer.
The library installs via npm or yarn and is tested against recent Chrome, Edge, Firefox, and Safari versions. Beta support exists for Node.js, Bun, and Deno beyond the browser targets.
Key features
- Event-driven peer connection API
- Data channels for multiple payload types
- Video and audio media calls
- DTLS-encrypted WebRTC transport
- Configurable ICE and serialization
- Optional self-hosted PeerServer
- npm and yarn package distribution
- Cross-browser compatibility testing
Use cases
- Browser-to-browser file or data transfer
- Simple video chat prototypes
- Real-time multiplayer game state sync
- P2P apps without relaying payload data