simpleWebRTCWrapper
Installation
Using npm:
$ npm i --save simple-webrtc-wrapper
; const connection = maxChunkSize: 16384 stunServers: 'stun.l.google.com:19302' 'stun1.l.google.com:19302' 'stun2.l.google.com:19302' 'stun3.l.google.com:19302' 'stun4.l.google.com:19302' 'stun.services.mozilla.com' sdpConstraints: optional: ;
Options
maxChunkSize
- (number) The maximum amount of data sent over the connection at once. Defaults to 16kbstunServers
- (array) An array of stun servers, a random one out of these will be picked when the class is constructedsdpConstraints
API
createRoom()
- Returns a promise which resolves an object with anoffer
which needs to be sent to the peer and a functionfinishCreatingRoom
which needs the peer's response passed into it.joinRoom(hostOffer)
- Returns a promise which resolves to a string which needs to be given to the host to finish creating the connectionsendObject(object)
- Returns a promise which resolves when everything in enqued to send over the connectionsendFile(file)
- Returns a promise which resolves when everything in enqued to send over the connectiondisconnect()
- Closes the connection
Events
connected
- Fired when the connected to the peerdisconnected
- Fired when the connection is closederror
- Fired when an error event is fired from the data channelmessage
- Fired when an object is recieved from the peerfileChunk
- Fired when a file chunk is recieved from the peer
Example
Host
async { const connection = ; const createdRoom = await connection; const HOST_OFFER = createdRoomoffer; // send this to the peer createdRoom; connection ;};
Peer
async { const connection = ; const PEER_OFFER = await connection; // send this to the host connection ;};
Dev Commands
npm run watch
- Starts a browser sync instance which restarts on any changes.npm run build
- Generates minified files and places them in thedist
folder