npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-liowebrtc

v1.2.9

Published

A React component library that makes it easy to add p2p communication into components via LioWebRTC.

Downloads

43

Readme

react-liowebrtc

A React component library that makes it easy to add p2p communication into components via LioWebRTC.

NPM

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';

class Example extends Component {

  handlePeerData = (webrtc, type, payload, peer) => {
    if (type === 'event-label') {
      console.log(payload);
    }
  }

  render () {
    return (
      <LioWebRTC
        options={{ dataOnly: true }}
        onReady={this.joinRoom}
        onCreatedPeer={this.handleCreatedPeer}
        onReceivedPeerData={this.handlePeerData}
        onRemovedPeer={this.handlePeerLeft}
      >
        <MyComponent />
      </LioWebRTC>
    )
  }
}

MyComponent

import React, { Component } from 'react';
import { withWebRTC } from 'react-liowebrtc';

class MyComponent extends Component {

  handleClick = () => this.props.webrtc.shout('event-label', 'payload');

  render() {
    return (
      <div>
        <button onClick={this.handleClick}>
          Click Me
        </button>
      </div>
    );
  }
}

export default withWebRTC(MyComponent);

Video Chat Example

import React, { Component } from 'react';
import { LioWebRTC, LocalVideo, RemoteVideo } from 'react-liowebrtc'

class ExampleVideoChat extends Component {

  constructor(props) {
    super(props);
    this.state = {
      peers: []
    };
  }

  join = (webrtc) => webrtc.joinRoom('video-chat-room-arbitrary-name');

  handleCreatedPeer = (webrtc, peer) => {
    this.setState({ peers: [...this.state.peers, peer] });
  }

  handleRemovedPeer = () => {
    this.setState({ peers: this.state.peers.filter(p => !p.closed) });
  }

  generateRemotes = () => this.state.peers.map((peer) => (
    <RemoteVideo key={`remote-video-${peer.id}`} peer={peer} />
  ));

  render () {
    return (
      <LioWebRTC
        options={{ debug: true }}
        onReady={this.join}
        onCreatedPeer={this.handleCreatedPeer}
        onRemovedPeer={this.handleRemovedPeer}
      >
        <LocalVideo />
        {
          this.state.peers &&
          this.generateRemotes()
        }
      </LioWebRTC>
    )
  }
}

export default ExampleVideoChat;

Component Props

LioWebRTC Component

LioWebRTC.propTypes = {
  options: PropTypes.object, // Initializing options passed into the liowebrtc library
  onReady: PropTypes.func, // Event listeners
  onJoinedRoom: PropTypes.func, // When we successfully join a room
  onReceivedPeerData: PropTypes.func, // When we receive a shout or whisper from a peer
  onChannelOpen: PropTypes.func, // When a new data channel is established with a peer
  onConnectionReady: PropTypes.func, // When the signaling connection is ready
  onCreatedPeer: PropTypes.func, // When a new peer connects
  onPeerStreamAdded: PropTypes.func, // When a peer media stream is added
  onPeerStreamRemoved: PropTypes.func, // When a peer media stream is removed
  onIceConnectionStateChange: PropTypes.func, // When the connection state with a peer changes
  onSignalingStateChange: PropTypes.func, // When the connection to the signaling server changes
  onLeftRoom: PropTypes.func, // When exited the room
  onPeerMute: PropTypes.func, // When a peer mutes themselves
  onReceivedSignalData: PropTypes.func, // When we get a message via the signaling server from a peer
  onPeerUnmute: PropTypes.func, // When a peer unmutes themselves
  onRemovedPeer: PropTypes.func, // When a peer disconnects from us
  onConnectionError: PropTypes.func // 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

LocalVideo.propTypes = {
  videoProps: PropTypes.object, // props passed to the inner video element
};

RemoteVideo Component

RemoteVideo.propTypes = {
  videoProps: PropTypes.object, // props passed to the inner video element
  peer: PropTypes.instanceOf(Peer) // 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