You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Integrated WebSocket Client & Server Implementation
This project is Node.js bindings for libdatachannel library.
Install
npm install node-datachannel
Supported Platforms
node-datachannel targets N-API version 8 and supports Node.js v18.20 and above. It is tested on Linux, Windows and MacOS. For N-API compatibility please check here.
importnodeDataChannelfrom'node-datachannel';// Log LevelnodeDataChannel.initLogger('Debug');// Integrated WebSocket available and can be used for signaling etc// const ws = new nodeDataChannel.WebSocket();letdc1=null;letdc2=null;letpeer1=newnodeDataChannel.PeerConnection('Peer1',{iceServers: ['stun:stun.l.google.com:19302'],});peer1.onLocalDescription((sdp,type)=>{peer2.setRemoteDescription(sdp,type);});peer1.onLocalCandidate((candidate,mid)=>{peer2.addRemoteCandidate(candidate,mid);});letpeer2=newnodeDataChannel.PeerConnection('Peer2',{iceServers: ['stun:stun.l.google.com:19302'],});peer2.onLocalDescription((sdp,type)=>{peer1.setRemoteDescription(sdp,type);});peer2.onLocalCandidate((candidate,mid)=>{peer1.addRemoteCandidate(candidate,mid);});peer2.onDataChannel((dc)=>{dc2=dc;dc2.onMessage((msg)=>{console.log('Peer2 Received Msg:',msg);});dc2.sendMessage('Hello From Peer2');});dc1=peer1.createDataChannel('test');dc1.onOpen(()=>{dc1.sendMessage('Hello from Peer1');});dc1.onMessage((msg)=>{console.log('Peer1 Received Msg:',msg);});