rtcdc
A modernized wrapper for WebRTC data channels.
Features
- Simple API for creating WebRTC data channel.
- Works in Chrome & Firefox, some workarounds are required for Safari support (Due to buggy data channel implementation in Safari 12).
- Binary & text data.
- RxJs-based messaging interface.
- Native TypeScript support.
- Use vanilla ICE for signalling.
- Native Promise-based interface.
Install
npm install rtcdc --save
Usage
You might need a web bundler (e.g. Rollup, Webpack, Browserify) for it to work.
; { const offerer = ; const offer = await Offerer; // Create WebRTC offer. // Now send your offer to another peer (answerer). const answerer = ; const answer = await answerer; // Get WebRTC answer based on the offer we got. // Send answer back to the offerer. await offerer; // Get data channels. const answererDataChannel = await answerer; const offererDataChannel = await offerer; // Test the data channel. answererDataChannelmessages offererDataChannelmessages await answererDataChannel; // Offerer got: ping. await offererDataChannel; // Answerer got: pong.};
You can also override the configuration to suit your needs, e.g. you will need to configure TURN server to connect peers behind symmetric NAT. Reference: https://developer.mozilla.org/en-US/docs/Web/API/RTCConfiguration
const config = iceServers: urls: "stun:stun.services.mozilla.com" username: "louis@mozilla.com" credential: "webrtcdemo" urls: "stun:stun.example.com" "stun:stun-1.example.com" ;const offerer = config;