Skip to content

Commit

Permalink
Merge pull request #238 from apivideo/reactnative-live-stream-feature…
Browse files Browse the repository at this point in the history
…/new_arch_support

[SDK README - api.video-reactnative-live-stream] feat(*): add support for new architecture
  • Loading branch information
ThibaultBee committed Jun 5, 2024
2 parents 86cad46 + e0ddadb commit 5248c48
Showing 1 changed file with 17 additions and 30 deletions.
47 changes: 17 additions & 30 deletions sdks/livestream/react-native-livestream-component.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,10 @@ meta:

## Project description

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

## Getting started

:warning: **The React Native Live Stream SDK is designed for 0.69.1 version of React Native. Using the SDK with >0.69.1 of React Native can cause unexpected behaviour**


### Installation

```sh
Expand All @@ -30,33 +27,25 @@ 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

```sh
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](https://github.com/apivideo/api.video-reactnative-live-stream/blob/main/docs/install_swift_dependency.md)

### Permissions

To be able to broadcast, you must:
#### Android

Permissions `android.permission.RECORD_AUDIO`, `android.permission.CAMERA` and `android.permission.INTERNET` are in the library manifest and will be requested by this library at runtime. You don't have to request them in your application.

1. On Android: ask for internet, camera and microphone permissions:
For the PlayStore, your application might declare this in its `AndroidManifest.xml`

```xml

<manifest>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-feature android:name="android.hardware.camera" android:required="true" />
<uses-feature android:name="android.hardware.camera.autofocus" android:required="false" />
</manifest>
```

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

2. On iOS: update Info.plist with a usage description for camera and microphone
Update `Info.plist` with a usage description for camera and microphone

```xml
<key>NSCameraUsageDescription</key>
Expand All @@ -66,30 +55,28 @@ Your application must dynamically require android.permission.CAMERA and android.
<string>Your own description of the purpose</string>
```

3. 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


```jsx
import React, { useRef, useState } from 'react';
import { View, TouchableOpacity } from 'react-native';
import { LiveStreamView } from '@api.video/react-native-livestream';
import { ApiVideoLiveStreamView } 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
<ApiVideoLiveStreamView
style={{ flex: 1, backgroundColor: 'black', alignSelf: 'stretch' }}
ref={ref}
camera="back"
enablePinchedZoom={true}
video={{
fps: 30,
resolution: '720p',
resolution: '720p', // Alternatively, you can specify the resolution in pixels: { width: 1280, height: 720 }
bitrate: 2*1024*1024, // # 2 Mbps
gopDuration: 1, // 1 second
}}
Expand Down Expand Up @@ -140,16 +127,16 @@ export default App;
### Props & Methods
```ts
type LiveStreamProps = {
type ApiVideoLiveStreamProps = {
// 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';
// resolution.
resolution: Resolution | PredefinedResolution;
// video bitrate. depends on resolutions.
bitrate: number;
// duration between 2 key frames in seconds
Expand All @@ -175,7 +162,7 @@ type LiveStreamProps = {
onDisconnect?: () => void;
};

type LiveStreamMethods = {
type ApiVideoLiveStreamMethods = {
// Start the stream
// streamKey: your live stream RTMP key
// url: RTMP server url, default: rtmp://broadcast.api.video/s
Expand Down

0 comments on commit 5248c48

Please sign in to comment.