• Stars
    star
    177
  • Rank 215,125 (Top 5 %)
  • Language
    Kotlin
  • License
    MIT License
  • Created over 3 years ago
  • Updated 25 days ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

React Native RTMP live stream client. Made with ♥ by api.video

badge   badge   badge

npm ts

React Native RTMP live stream client

api.video is the video infrastructure for product builders. Lightning fast video APIs for integrating, scaling, and managing on-demand & low latency live streaming features in your app.

Table of contents

Project description

This module is made for broadcasting rtmp live stream from smartphone camera

Getting started

Installation

npm install @api.video/react-native-livestream

or

yarn add @api.video/react-native-livestream

Note: if you are on iOS, you will need two extra steps:

  1. Don't forget to install the native dependencies with Cocoapods
cd ios && pod install
  1. This project contains swift code, and if it's your first dependency with swift code, you need to create an empty swift file in your project (with the bridging header) from XCode. Find how to do that

Permissions

To be able to broadcast, you must:

  1. On Android: ask for internet, camera and microphone permissions:
<manifest>
  <uses-permission android:name="android.permission.INTERNET" />
  <uses-permission android:name="android.permission.RECORD_AUDIO" />
  <uses-permission android:name="android.permission.CAMERA" />
</manifest>

Your application must dynamically require android.permission.CAMERA and android.permission.RECORD_AUDIO.

  1. On iOS: update Info.plist with a usage description for camera and microphone
<key>NSCameraUsageDescription</key>
<string>Your own description of the purpose</string>

<key>NSMicrophoneUsageDescription</key>
<string>Your own description of the purpose</string>
  1. On react-native you must handle the permissions requests before starting your livestream. If permissions are not accepted you will not be able to broadcast.

Code sample

import React, { useRef, useState } from 'react';
import { View, TouchableOpacity } from 'react-native';
import { LiveStreamView } from '@api.video/react-native-livestream';

const App = () => {
  const ref = useRef(null);
  const [streaming, setStreaming] = useState(false);

  return (
    <View style={{ flex: 1, alignItems: 'center' }}>
      <LiveStreamView
        style={{ flex: 1, backgroundColor: 'black', alignSelf: 'stretch' }}
        ref={ref}
        camera="back",
        video={{
          fps: 30,
          resolution: '720p',
          bitrate: '2*1024*1024', // # 2 Mbps
          gopDuration: 1, // 1 second
        }}
        audio={{
          bitrate: 128000,
          sampleRate: 44100,
          isStereo: true,
        }}
        isMuted={false}
        onConnectionSuccess={() => {
          //do what you want
        }}
        onConnectionFailed={(e) => {
          //do what you want
        }}
        onDisconnect={() => {
          //do what you want
        }}
      />
      <View style={{ position: 'absolute', bottom: 40 }}>
        <TouchableOpacity
          style={{
            borderRadius: 50,
            backgroundColor: streaming ? 'red' : 'white',
            width: 50,
            height: 50,
          }}
          onPress={() => {
            if (streaming) {
              ref.current?.stopStreaming();
              setStreaming(false);
            } else {
              ref.current?.startStreaming('YOUR_STREAM_KEY');
              setStreaming(true);
            }
          }}
        />
      </View>
    </View>
  );
}

export default App;

Documentation

Props & Methods

type LiveStreamProps = {
  // Styles for the view containing the preview
  style: ViewStyle;
  // camera facing orientation
  camera?: 'front' | 'back';
  video: {
    // frame rate
    fps: number;
    // resolution
    resolution: '240p' | '360p' | '480p' | '720p' | '1080p';
    // video bitrate. depends on resolutions.
    bitrate: number;
    // duration between 2 key frames in seconds
    gopDuration: number;
  };
  audio: {
    // sample rate. Only for Android. Recommended: 44100
    sampleRate: 44100;
    // true for stereo, false for mono. Only for Android. Recommended: true
    isStereo: true;
    // audio bitrate. Recommended: 128000
    bitrate: number;
  };
  // Mute/unmute microphone
  isMuted: false;
  // Enables/disables the zoom gesture handled natively
  enablePinchedZoom?: boolean;
  // will be called when the connection is successful
  onConnectionSuccess?: () => void;
  // will be called when connection failed
  onConnectionFailed?: (code: string) => void;
  // will be called when the live-stream is stopped
  onDisconnect?: () => void;
};

type LiveStreamMethods = {
  // Start the stream
  // streamKey: your live stream RTMP key
  // url: RTMP server url, default: rtmp://broadcast.api.video/s
  startStreaming: (streamKey: string, url?: string) => void;
  // Stops the stream
  stopStreaming: () => void;
  // Sets the zoomRatio
  // Intended for use with React Native Gesture Handler, a slider or similar.
  setZoomRatio: (zoomRatio) => void;
};

Example App

You can try our example app, feel free to test it.

Setup

Be sure to follow the React Native installation steps before anything.

  1. Open a new terminal
  2. Clone the repository and go into it
git clone https://github.com/apivideo/api.video-reactnative-live-stream.git livestream_example_app && cd livestream_example_app

Android

Install the packages and launch the application

yarn && yarn example android

iOS

  1. Install the packages
yarn install
  1. Go into /example/ios and install the Pods
cd /example/ios && pod install
  1. Sign your application

Open Xcode, click on "Open a project or file" and open the Example.xcworkspace file.
You can find it in YOUR_PROJECT_NAME/example/ios.
Click on Example, go in Signin & Capabilities tab, add your team and create a unique bundle identifier.

  1. Launch the application, from the root of your project
yarn example ios

Plugins

api.video live stream library is using external native library for broadcasting

Plugin README
StreamPack StreamPack
HaishinKit HaishinKit

FAQ

If you have any questions, ask us here: https://community.api.video . Or use Issues.

More Repositories

1

browserLiveStream

Use webcam, browser and Node to stream live video. From api.video (https://api.video)
JavaScript
196
star
2

api.video-flutter-live-stream

Flutter RTMP live stream client. Made with ♥ by api.video
Dart
64
star
3

api.video-nodejs-client

The official Node.js client library for api.video
TypeScript
62
star
4

api.video-android-live-stream

Android RTMP live stream client. Made with ♥ by api.video
Kotlin
52
star
5

api.video-player-sdk

SDK to control and interact with the api.video HTML5 Player
TypeScript
49
star
6

api.video-php-client

The official PHP client library for api.video
PHP
40
star
7

recordavideo

A demo app to record or stream your camera or desktop - right from your browser! uses api.video (https://api.video).
TypeScript
40
star
8

api.video-typescript-media-stream-composer

Easily upload videos to api.video using progressive upload from a composition of several media streams
TypeScript
39
star
9

api.video-python-client

The official Python client library for api.video
Python
36
star
10

api.video-go-client

The official Go client library for api.video
Go
36
star
11

blobUpload

Uses file slice to upload large files. Newer version https://github.com/apivideo/uploadavideoApps. From api.video (https://api.video)
HTML
34
star
12

api.video-swift-live-stream

Swift RTMP live stream client for iOS. Made with ♥ by api.video
Swift
31
star
13

youtube-clone-next

Rebuilding YouTube with api.video and Next.js 🎥
JavaScript
26
star
14

api.video-desktop-synchronizer

Desktop application to synchronize a folder containing video files with api.video
TypeScript
26
star
15

api.video-typescript-uploader

The official typescript video uploader for api.video (https://api.video)
TypeScript
25
star
16

api.video-rtmpdroid

librtmp wrapper for Android. Made with ♥ by api.video
Kotlin
25
star
17

api.video-csharp-client

The official C# client library for api.video
C#
25
star
18

api.video-swift-player

The official iOS player for api.video
Swift
25
star
19

api.video-strapi-plugin

A Strapi plugin for managing uploads to api.video.
TypeScript
24
star
20

api.video-android-upstream

Record your camera and microphone. Upload your video at the same time.
Kotlin
24
star
21

api.video-flutter-player

The official Flutter player for api.video
Dart
24
star
22

api.video-flutter-uploader

The official Flutter video uploader for api.video
Dart
24
star
23

api.video-api-client-generator

Tool used to generate api.video's API clients, based on OpenAPI codegen
Mustache
24
star
24

api.video-react-player

api.video React player component
TypeScript
22
star
25

api.video-java-client

The official Java client library for api.video
Java
22
star
26

api.video-api-specification

Open API Specification of the api.video API.
21
star
27

api.video-typescript-media-recorder

Typescript library to easily upload data from a MediaStream to api.video. It can be used to upload a video to api.video from the user's webcam with ease, as well as from a screen recording.
TypeScript
21
star
28

api.video-browser-to-rtmp

Easily publish a webcam stream from browsers to a RTMP server
TypeScript
20
star
29

api.video-swift-uploader

The official iOS, macOS, tvOS video uploader for api.video
Swift
20
star
30

tiktok_clone

Rebuilding TikTok with api.video, PWA, Next.js and Typescript 🎵
TypeScript
20
star
31

videoModeration

Using HiveAI to moderate videos uploaded to api.video. From api.video (https://api.video)
JavaScript
20
star
32

api.video-hlsjs-analytics

api.video player analytics plugin for hls.js based players
TypeScript
20
star
33

api.video-react-packages

The official mono-repository for api.video ReactJS packages
TypeScript
19
star
34

upload.a.video

A demo app featuring several ways to upload video into your api.video - https://api.video account.
HTML
19
star
35

ffprobeavideo

Online version of FFprobe. Uses NodeJS to host ffmpeg and FFprobe. From api.video (https://api.video)
JavaScript
19
star
36

shareavideo

Share a video with your friends to watch together! This demo app streams a video over a live stream connection. From api.video (https://api.video)
JavaScript
19
star
37

video-platform-bench

This app aims to benchmark several video/live streaming OTT platforms. From api.video (https://api.video)
PHP
19
star
38

udemy-clone-next-typescript

Rebuilding Udemy with api.video, Next.js and Typescript 🎓
TypeScript
18
star
39

api.video-swift-client

The official iOS, macOS, tvOS client library for api.video
Swift
18
star
40

ingest.new

A simple demo application for uploading, ingesting, embedding videos and converting them to mp4s. From api.video (https://api.video)
JavaScript
18
star
41

bash-upload

Bash script for create and upload to api.video
Shell
17
star
42

python-examples

Code samples for working with api.video in Python
JavaScript
17
star
43

api.video-player-analytics

api.video player analytics module
TypeScript
17
star
44

api.video-reactnative-uploader

The official ReactNative video uploader for api.video
Kotlin
17
star
45

api.video-android-player

The official Android player for api.video
Kotlin
17
star
46

api.video-videojs-analytics

api.video player analytics plugin for videojs
TypeScript
17
star
47

api.video-reactnative-player

React Native video player
TypeScript
17
star
48

bumperavideo

A demo app that automatically add bumpers and a watermark to your video, using Shotstack.io and api.video (https://api.video)
JavaScript
17
star
49

api.video-android-client

The official Android client library for api.video
Java
17
star
50

watermarkavideo

App to add a watermark to a video being recorded. From api.video (https://api.video)
HTML
16
star
51

api.video-wordpress-plugin

The official api.video plugin for WordPress
PHP
16
star
52

privatedelegatedtoken

video upload demo - uses delegated tokens (public api key) for video upload with just HTML and JavaScript. From api.video (https://api.video)
HTML
16
star
53

LocalTV

A super light template for creating your own TV station!
HTML
15
star
54

api.video-android-uploader

The official Android video uploader for api.video
Java
15
star
55

api.video-readmeio-document-sync-action

Synchronize a readme.io documentation from the readme of a Github repository. From api.video (https://api.video)
JavaScript
15
star
56

cometchatvideo

A demo integrating live streaming video & an embedded chat app. Built with cometchat and api.video (https://api.video).
HTML
15
star
57

Next.js_Starters-

Setup ESLint, Prettier, and Husky with TypeScript
JavaScript
14
star
58

videoPlaylist

Create and watch a video playlist. Now combined into https://github.com/apivideo/watchavideoapps for easier publishing. From api.video (https://api.video)
HTML
14
star
59

videoUploadToDiscord

NodeJS app to upload videos to a Discord Bot. From api.video (https://api.video)
HTML
13
star
60

chyronavideo

A chyron is the text at the bottom of a newscast. Use this app to add a chyron to your video live stream. From api.video (https://api.video)
HTML
13
star
61

videoVolume

A simple demo app that uses api.video's player SDK to warn users when the volume is too high. From api.video (https://api.video)
HTML
13
star
62

api.video-swift-player-analytics

The official iOS player analytics for api.video
Swift
13
star
63

statuspage-php

StatusPage php client by api.video.
PHP
13
star
64

helpful-scripts

Helpful scripts for massive uploads on api.video
PHP
13
star
65

watchLivestream

watch a video livestream is a demo application that displays a video lives stream, and the 5 most recent recordings. From api.video (https://api.video)
JavaScript
13
star
66

api.video-import-tool

Migrate your videos from several hosting provider to api.video
TypeScript
13
star
67

watchavideoapps

combined watch.a.video/broadcast and watch.a.video/playlist for easier deployment. From api.video (https://api.video)
JavaScript
12
star
68

webhookavideo

A demo application that listens for, and displays all the webhooks from an api.video account. From api.video (https://api.video)
JavaScript
12
star
69

livestream-with-realtime-communication

Leverage api.video API together with PubNub and a Next.js front end in order to provide real-time communication between users. Think something like instant reaction to the video like TikTok or Instagram Reels
TypeScript
12
star
70

api.video-android-player-analytics

The official Android player analytics for api.video
Kotlin
12
star
71

resumeAVideo

Use analytics and metadata to determine where a viewer "left off" in a video. restart the video at that point. From api.video (https://api.video)
JavaScript
12
star
72

storyifyAVideo

a simple application that creates "stories" of videos showing only the newest. From api.video (https://api.video)
JavaScript
12
star
73

deleteVideoDemo

A quick demo that deletes videos from your api.video account. From api.video (https://api.video)
JavaScript
12
star
74

videoAnalytics

NodeJS app to retrieve and process video analytics. From api.video (https://api.video)
JavaScript
11
star
75

php-sdk

DEPRECATED. Use https://github.com/apivideo/api.video-php-client instead.
PHP
11
star
76

caption.new

Sample app to add captions to an uploaded video. From api.video (https://api.video)
JavaScript
11
star
77

trainingavideo

training.a.video is a sample application that uses metadata to track each user's journey through a training class - unlocking each video when the previous video has been watched. From api.video (https://api.video)
JavaScript
11
star
78

duetavideo

Build a web based duet app. Sing along with your favorite movie! Built with api.video (https://api.video)
HTML
10
star
79

get-started-video-uploader

A get started example that will help you build a video uploader
TypeScript
10
star
80

go-sdk

Golang SDK for api.video web-service (video encoding, hosting and secured delivery)
Go
10
star
81

api.video-typescript-media-stream-person-segmentation

EXPERIMENTAL - Change the background and emphasize the person in media streams
TypeScript
9
star
82

private-videos-with-custom-player-sample

Demonstrate how to display private videos using a third-party player
EJS
9
star
83

api.video-get-npm-workspace-path-from-release-action

Publish npm workspace depending on published GitHub release
JavaScript
8
star
84

api.video-progressive-upload-demo

TypeScript
8
star
85

private.a.video

HTML
8
star
86

.github

Organization-wide contribution guides, assets and templates
8
star
87

private-video-videojs-node-example

JavaScript
7
star
88

api.video-release-from-workspaces-changelogs-action

Github action to automatically create draft releases depending on the CHANGELOG.md files of each npm workspace of the repo.
JavaScript
7
star
89

api.video-release-from-changelog-action

Github action to create release from changelog
JavaScript
6
star
90

api.video-documentation

api.video documentation templates
CSS
2
star
91

livestream-with-realtime-ably

A small example of how to build your own TikTok or Instagram Reels like use case. The example demostrates the use of api.video streaming and a css overlay of an emoji picker. We leverage Ably in order to create an instant emoji sharing between users.
TypeScript
1
star