Coder Social home page Coder Social logo

react-native-peerjs's Introduction

React Native PeerJS

react-native-webrtc has brought WebRTC to React Native. PeerJS is a simple API to work with WebRTC in the Browser.

I made it so that PeerJS works with react-native-webrtc in a React Native application.

Install

Install react-native-webrtc according to their install guide. Then add react-native-peerjs:

yarn add react-native-peerjs

Usage

Just refer to the PeerJS documentation. Here is an example:

import Peer from 'react-native-peerjs';

const localPeer = new Peer();
localPeer.on('error', console.log);

localPeer.on('open', localPeerId => {
  console.log('Local peer open with ID', localPeerId);

  const remotePeer = new Peer();
  remotePeer.on('error', console.log);
  remotePeer.on('open', remotePeerId => {
    console.log('Remote peer open with ID', remotePeerId);

    const conn = remotePeer.connect(localPeerId);
    conn.on('error', console.log);
    conn.on('open', () => {
      console.log('Remote peer has opened connection.');
      console.log('conn', conn);
      conn.on('data', data => console.log('Received from local peer', data));
      console.log('Remote peer sending data.');
      conn.send('Hello, this is the REMOTE peer!');
    });
  });
});

localPeer.on('connection', conn => {
  console.log('Local peer has received connection.');
  conn.on('error', console.log);
  conn.on('open', () => {
    console.log('Local peer has opened connection.');
    console.log('conn', conn);
    conn.on('data', data => console.log('Received from remote peer', data));
    console.log('Local peer sending data.');
    conn.send('Hello, this is the LOCAL peer!');
  });
});

react-native-peerjs's People

Contributors

zemke avatar alejinho avatar sergeymikhryakov avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.