{"library":"node-datachannel","title":"node-datachannel: WebRTC Data Channels for Node.js and Electron","description":"The `node-datachannel` package provides Node.js and Electron bindings for the lightweight `libdatachannel` WebRTC data channel library. It offers a streamlined API for establishing and managing peer-to-peer data communication without the complexity of a full WebRTC stack implementation. Currently at version `0.32.2`, the project demonstrates an active release cadence, frequently incorporating updates from the underlying `libdatachannel` and introducing new features or fixes. Key differentiators include its small binary footprint (around 8MB for Linux x64), comprehensive TypeScript type definitions, and an integrated WebSocket client and server for flexible signaling. It specifically targets N-API version 8, requiring Node.js v18.20.0 or newer, and supports Linux, Windows, and macOS across various architectures. This makes it a suitable choice for applications needing robust, cross-platform WebRTC data channel capabilities in a server-side or Electron environment.","language":"javascript","status":"active","last_verified":"Sun Apr 19","install":{"commands":["npm install node-datachannel"],"cli":null},"imports":["import nodeDataChannel from 'node-datachannel';","import { PeerConnection } from 'node-datachannel';","import { initLogger } from 'node-datachannel';","import { WebSocket } from 'node-datachannel';"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import { PeerConnection, initLogger } from 'node-datachannel';\n\ninitLogger('Debug');\n\nlet dc1 = null;\nlet dc2 = null;\n\nlet peer1 = new PeerConnection('Peer1', {\n  iceServers: ['stun:stun.l.google.com:19302']\n});\n\npeer1.onLocalDescription((sdp, type) => {\n  peer2.setRemoteDescription(sdp, type);\n});\npeer1.onLocalCandidate((candidate, mid) => {\n  peer2.addRemoteCandidate(candidate, mid);\n});\n\nlet peer2 = new PeerConnection('Peer2', {\n  iceServers: ['stun:stun.l.google.com:19302']\n});\n\npeer2.onLocalDescription((sdp, type) => {\n  peer1.setRemoteDescription(sdp, type);\n});\npeer2.onLocalCandidate((candidate, mid) => {\n  peer1.addRemoteCandidate(candidate, mid);\n});\npeer2.onDataChannel((dc) => {\n  dc2 = dc;\n  dc2.onMessage((msg) => {\n    console.log('Peer2 Received Msg:', msg);\n  });\n  dc2.sendMessage('Hello From Peer2');\n});\n\ndc1 = peer1.createDataChannel('test');\n\ndc1.onOpen(() => {\n  dc1.sendMessage('Hello from Peer1');\n});\n\ndc1.onMessage((msg) => {\n  console.log('Peer1 Received Msg:', msg);\n});","lang":"typescript","description":"This quickstart demonstrates how to establish two `PeerConnection` instances, exchange ICE candidates and SDP descriptions, and then create and communicate over a `DataChannel` between them, logging messages in both directions.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}