Code Monkey home page Code Monkey logo

react-native-webrtc's Introduction

react-native-webrtc

npm version npm downloads

A WebRTC module for React Native.

Support

  • Currently support for iOS and Android.
  • Support video and audio communication.
  • Supports data channels.
  • You can use it to build an iOS/Android app that can communicate with web browser.
  • The WebRTC Library is based on webrtc-build-scripts

WebRTC Revision

Since 0.53, we use same branch version number like in webrtc native. please see wiki page about revision history

format:

${branch_name} stable (${branched_from_revision})(+${Cherry-Picks-Num}-${Last-Cherry-Picks-Revision})

  • the webrtc revision in brackets is extracting frrom Cr-Branched-From instead Cr-Commit-Position
  • the number follows with + is the additional amount of cherry-picks since Branched-From revision.

note:

the order of commit revision is nothing to do with the order of cherry-picks, for example, the earlier committed cherry-pick-#2 may have higher revision than cherry-pick-#3 and vice versa.

| react-native-webrtc | WebRTC(ios) | WebRTC(android) | npm published | note | | :-------------: | :-------------:| :-----: | :-----: | :-----: | :-----: | | 0.53.2 | 53 stable
(13317)
(+6-13855)
32/64 | 53 stable
(13317)
(+6-13855)
32 | ✔️ | | | 0.54.4 | 54 stable
(13869)
(+6-14091)
32/64 | 54 stable
(13869)
(+6-14091)
32 | ✔️ | | | master | 54 stable
(13869)
(+6-14091)
32/64 | 54 stable
(13869)
(+6-14091)
32 | ⚠️ | |

Installation

react-native-webrtc:

note: 0.10.0~0.12.0 required git-lfs, see: git-lfs-installation

Usage

Now, you can use WebRTC like in browser. In your index.ios.js/index.android.js, you can require WebRTC to import RTCPeerConnection, RTCSessionDescription, etc.

var WebRTC = require('react-native-webrtc');
var {
  RTCPeerConnection,
  RTCMediaStream,
  RTCIceCandidate,
  RTCSessionDescription,
  RTCView,
  MediaStreamTrack,
  getUserMedia,
} = WebRTC;

Anything about using RTCPeerConnection, RTCSessionDescription and RTCIceCandidate is like browser.
Support most WebRTC APIs, please see the Document.

var configuration = {"iceServers": [{"url": "stun:stun.l.google.com:19302"}]};
var pc = new RTCPeerConnection(configuration);
MediaStreamTrack.getSources(sourceInfos => {
  var videoSourceId;
  for (var i = 0; i < sourceInfos.length; i++) {
    var sourceInfo = sourceInfos[i];
    if(sourceInfo.kind == "video" && sourceInfo.facing == "front") {
      videoSourceId = sourceInfo.id;
    }
  }
  getUserMedia({
    "audio": true,
    "video": {
      optional: [{sourceId: videoSourceId}]
    }
  }, function (stream) {
    pc.addStream(stream);
  }, logError);
});

pc.createOffer(function(desc) {
  pc.setLocalDescription(desc, function () {
    // Send pc.localDescription to peer
  }, function(e) {});
}, function(e) {});
pc.onicecandidate = function (event) {
  // send event.candidate to peer
};
// also support setRemoteDescription, createAnswer, addIceCandidate, onnegotiationneeded, oniceconnectionstatechange, onsignalingstatechange, onaddstream

However, render video stream should be used by React way.

Rendering RTCView.

var container;
var RCTWebRTCDemo = React.createClass({
  getInitialState: function() {
    return {videoURL: null};
  },
  componentDidMount: function() {
    container = this;
  },
  render: function() {
    return (
      <View>
        <RTCView streamURL={this.state.videoURL}/>
      </View>
    );
  }
});

And set stream to RTCView

container.setState({videoURL: stream.toURL()});

Demo

The demo project is https://github.com/oney/RCTWebRTCDemo
And you will need a signaling server. I have written a signaling server https://react-native-webrtc.herokuapp.com/ (the repository is https://github.com/oney/react-native-webrtc-server).
You can open this website in browser, and then set it as signaling server in the app, and run the app. After you enter the same room ID, the video stream will be connected.

Native control

Use react-native-incall-manager to keep screen on, mute microphone, etc.

Sponsorship

This repository doesn't have a plan to get sponsorship.(This can be discussed afterwards by collaborators). If you would like to pay bounty to fix some bugs or get some features, be free to open a issue that adds [BOUNTY] category in title. Add other bounty website link like this will be better.

react-native-webrtc's People

Contributors

oney avatar zxcpoiu avatar philikon avatar lyubomir avatar paweldomas avatar markthom-as avatar stwiname avatar kensakukomatsu avatar ianlin avatar dguillamot avatar snoronha avatar sagivo avatar rub8n avatar mrap avatar micronxd avatar maxhawkins avatar vespakoen avatar jakkra avatar

Watchers

Mohammad Rajib 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.