react-liowebrtc
A React component library that makes it easy to add p2p communication into components via LioWebRTC.
Install
npm i react-liowebrtc --save
Or
yarn add react-liowebrtc
Demo
https://react-liowebrtc.netlify.com
Usage
Example Component (Data Channels only)
import React Component from 'react';import LioWebRTC from 'react-liowebrtc'import MyComponent from './MyComponent'; { if type === 'event-label' console; } { return <LioWebRTC = = = = = > <MyComponent /> </LioWebRTC> }
MyComponent
import React Component from 'react';import withWebRTC from 'react-liowebrtc'; thispropswebrtc; { return <div> <button => Click Me </button> </div> ; } MyComponent;
Video Chat Example
import React Component from 'react';import LioWebRTC LocalVideo RemoteVideo from 'react-liowebrtc' { ; thisstate = peers: ; } webrtc; { this; } { this; } thisstatepeers; { return <LioWebRTC = = = = > <LocalVideo /> thisstatepeers && this </LioWebRTC> } ;
Component Props
LioWebRTC Component
LioWebRTCpropTypes = options: PropTypesobject // Initializing options passed into the liowebrtc library onReady: PropTypesfunc // Event listeners onJoinedRoom: PropTypesfunc // When we successfully join a room onReceivedPeerData: PropTypesfunc // When we receive a shout or whisper from a peer onChannelOpen: PropTypesfunc // When a new data channel is established with a peer onConnectionReady: PropTypesfunc // When the signaling connection is ready onCreatedPeer: PropTypesfunc // When a new peer connects onPeerStreamAdded: PropTypesfunc // When a peer media stream is added onPeerStreamRemoved: PropTypesfunc // When a peer media stream is removed onIceConnectionStateChange: PropTypesfunc // When the connection state with a peer changes onSignalingStateChange: PropTypesfunc // When the connection to the signaling server changes onLeftRoom: PropTypesfunc // When exited the room onPeerMute: PropTypesfunc // When a peer mutes themselves onReceivedSignalData: PropTypesfunc // When we get a message via the signaling server from a peer onPeerUnmute: PropTypesfunc // When a peer unmutes themselves onRemovedPeer: PropTypesfunc // When a peer disconnects from us onConnectionError: PropTypesfunc // When an error occurs in connecting to a peer;
All event emitters pass a webrtc session manager object to the listener functions. For example, the onReceivedPeerData
event passes the following objects: (webrtc, type, data, peer)
. The onCreatedPeer
event passes (webrtc, peer)
. Take a look at the LioWebRTC docs for more information on LioWebRTC's events and methods. All events emitted by LioWebRTC will have a preceding webrtc object when using react-liowebrtc.
LocalVideo Component
LocalVideopropTypes = videoProps: PropTypesobject // props passed to the inner video element;
RemoteVideo Component
RemoteVideopropTypes = videoProps: PropTypesobject // props passed to the inner video element peer: PropTypes // the Peer instance;
These props are needed to initialize and set event listeners for the liowebrtc library. Take a look at the liowebrtc docs for more info.
For more info, please take a look at this tutorial showing how to build a chat room with react-liowebrtc.
License
MIT © lazorfuzz