GithubHelp home page GithubHelp logo

isabella232 / react-native-webrtc Goto Github PK

View Code? Open in Web Editor NEW

This project forked from jitsi/react-native-webrtc

0.0 0.0 0.0 301.91 MB

A WebRTC module for React Native.

License: MIT License

JavaScript 11.75% Java 29.63% Objective-C 55.53% C 0.22% Ruby 0.28% Python 2.09% Shell 0.49%

react-native-webrtc's Introduction

react-native-webrtc

npm version npm downloads

A WebRTC module for React Native.

  • Support iOS / Android.
  • Support Video / Audio / Data Channels.

NOTE for Expo users: this plugin doesn't work unless you eject.

Community

Everyone is welcome to our Discourse community to discuss any React Native and WebRTC related topics.

WebRTC Revision

react-native-webrtc WebRTC Version arch(ios) arch(android) npm published notes
1.75.0 M75 x86_64
i386
armv7
arm64
armeabi-v7a
arm64-v8a
x86
x86_64
✔️
1.69.2 M69 x86_64
i386
armv7
arm64
armeabi-v7a
arm64-v8a
x86
x86_64
✔️
1.69.1 M69
commit
(24012)
(+16-24348)
x86_64
i386
armv7
arm64
armeabi-v7a
arm64-v8a
x86
x86_64
✔️
1.69.0 M69
commit
(24012)
(+16-24348)
x86_64
i386
armv7
arm64
armeabi-v7a
x86
✔️
master M75 x86_64
i386
armv7
arm64
armeabi-v7a
arm64-v8a
x86
x86_64
⚠️ Please test!

Please see wiki page about revision history.

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.

import {
  RTCPeerConnection,
  RTCIceCandidate,
  RTCSessionDescription,
  RTCView,
  MediaStream,
  MediaStreamTrack,
  mediaDevices
} from 'react-native-webrtc';

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

const configuration = {"iceServers": [{"url": "stun:stun.l.google.com:19302"}]};
const pc = new RTCPeerConnection(configuration);

let isFront = true;
mediaDevices.enumerateDevices().then(sourceInfos => {
  console.log(sourceInfos);
  let videoSourceId;
  for (let i = 0; i < sourceInfos.length; i++) {
    const sourceInfo = sourceInfos[i];
    if(sourceInfo.kind == "videoinput" && sourceInfo.facing == (isFront ? "front" : "back")) {
      videoSourceId = sourceInfo.deviceId;
    }
  }
  mediaDevices.getUserMedia({
    audio: true,
    video: {
      mandatory: {
        minWidth: 500, // Provide your own width, height and frame rate here
        minHeight: 300,
        minFrameRate: 30
      },
      facingMode: (isFront ? "user" : "environment"),
      optional: (videoSourceId ? [{sourceId: videoSourceId}] : [])
    }
  })
  .then(stream => {
    // Got stream!
  })
  .catch(error => {
    // Log error
  });
});

pc.createOffer().then(desc => {
  pc.setLocalDescription(desc).then(() => {
    // Send pc.localDescription to peer
  });
});

pc.onicecandidate = function (event) {
  // send event.candidate to peer
};

// also support setRemoteDescription, createAnswer, addIceCandidate, onnegotiationneeded, oniceconnectionstatechange, onsignalingstatechange, onaddstream

RTCView

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

Rendering RTCView.

<RTCView streamURL={this.state.stream.toURL()}/>
Name Type Default Description
mirror boolean false Indicates whether the video specified by "streamURL" should be mirrored during rendering. Commonly, applications choose to mirror theuser-facing camera.
objectFit string 'contain' Can be contain or cover
streamURL string '' This is mandatory
zOrder number 0 Similarly to zIndex

Custom APIs

MediaStreamTrack.prototype._switchCamera()

This function allows to switch the front / back cameras in a video track on the fly, without the need for adding / removing tracks or renegotiating.

VideoTrack.enabled

Starting with version 1.67, when setting a local video track's enabled state to false, the camera will be closed, but the track will remain alive. Setting it back to true will re-enable the camera.

react-native-incall-manager

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

react-native-callkeep

Use react-native-callkeep to use callkit on iOS or connection service on Android to have native dialer with your webrtc application.

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.

Creator

This repository is originally created by Wan Huang Yang.

react-native-webrtc's People

Contributors

1mike12 avatar bbrcan avatar bighitbiker3 avatar bradleyjokinen avatar cristiantx avatar csantosm avatar danielob avatar divyanshunumrah avatar edolix avatar guusdk avatar jacklj avatar jd20 avatar jiyeyuran avatar karlosq avatar kenny-house avatar lemming avatar lyubomir avatar mahmoud-adam85 avatar markthom-as avatar maxhawkins avatar oney avatar paweldomas avatar philikon avatar ruddell avatar saghul avatar sboily avatar seeekr avatar stwiname avatar zbettenbuk avatar zxcpoiu 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.