Skip to content

Commit

Permalink
feat: support native 4.0.0-rc.1
Browse files Browse the repository at this point in the history
  • Loading branch information
LichKing-2234 committed Sep 13, 2022
1 parent d4f408f commit e1d11fd
Show file tree
Hide file tree
Showing 110 changed files with 18,298 additions and 9,142 deletions.
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ Remember to add tests for your change if possible. Run the unit tests by:
yarn test
```

To edit the Objective-C files, open `example/ios/ReactNativeAgoraRtcNgExample.xcworkspace` in XCode and find the source files at `Pods > Development Pods > react-native-agora-rtc-ng`.
To edit the Objective-C files, open `example/ios/ReactNativeAgoraRtcNgExample.xcworkspace` in XCode and find the source files at `Pods > Development Pods > react-native-agora`.

To edit the Kotlin files, open `example/android` in Android studio and find the source files at `io/agora/rtc/ng/react` under `Android`.

Expand Down
128 changes: 124 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,133 @@
# react-native-agora-rtc-ng
# react-native-agora

react-native-agora-rtc-ng.
[![npm](https://img.shields.io/npm/v/react-native-agora.svg)](https://www.npmjs.com/package/react-native-agora)
[![npm](https://img.shields.io/npm/dm/react-native-agora.svg)](https://www.npmjs.com/package/react-native-agora)
[![npm](https://img.shields.io/npm/dt/react-native-agora.svg)](https://www.npmjs.com/package/react-native-agora)
[![npm](https://img.shields.io/npm/l/react-native-agora.svg)](LICENSE)

This SDK takes advantage of React Native and Agora RTC Video SDK on Android && iOS.

## Community Contributor

The community developer [Syanbo](https://github.com/syanbo) developed 1.0 version React Native SDK based on the Agora
Native SDK from 2016 to 2017. As the community's demand for React Native SDK keeps growing, Agora has achieved official
cooperation with Syanbo, this project now is officially maintained by Agora. Thanks to Syanbo for his long-term
contributions to React Native SDK.

## Release Note

[Changelog](CHANGELOG.md)

## Installation

```sh
npm install react-native-agora-rtc-ng
### Installing (React Native >= 0.60.0)

Install `react-native-agora`(^4.0.0):

```shell script
yarn add react-native-agora
```

or

```shell script
npm i --save react-native-agora
```

Go to your **ios** folder and run:

```shell script
pod install
```

## General Usage

```typescript
import {createAgoraRtcEngine} from 'react-native-agora';

const engine = createAgoraRtcEngine();
engine.initialize({appId: 'YOUR APP ID'});
```

or

```javascript
const createAgoraRtcEngine = require('react-native-agora');
const engine = createAgoraRtcEngine();
engine.initialize({appId: 'YOUR APP ID'});
```

## Using TypeScript

We suggest you use TypeScript to develop, or use TypeScript eslint to lint your code.

* [Getting Started with TypeScript](https://reactnative.dev/docs/typescript#getting-started-with-typescript)
* [Adding TypeScript to an Existing Project](https://reactnative.dev/docs/typescript#adding-typescript-to-an-existing-project)

## Troubleshooting

### Pod install failed (React Native >= 0.62.0)

The error log:

```
[!] The 'xxx' target has libraries with conflicting names: libcrypto.a.
```

You should disable Flipper, you can found it in the Podfile, and comment the code about Flipper in AppDelegate.

```
# Enables Flipper.
#
# Note that if you have use_frameworks! enabled, Flipper will not work and
# you should disable these next few lines.
add_flipper_pods!
post_install do |installer|
flipper_post_install(installer)
end
```

### RCT_EXTERN_MODULE Swift modules broken in Xcode 10.2

The error log:

```
Swift class extensions and categories on Swift classes are not allowed to have +load methods
```

Fixed in React Native 0.59.3.

Source: https://github.com/facebook/react-native/issues/24139

### XCode 11 Beta App Launch Crash

The error log:

```
Exception '*** -[__NSArrayM objectAtIndexedSubscript:]: index 1 beyond bounds [0 .. 0]' was thrown while invoking getCurrentAppState on target AppState with params (
2,
3
)
```

Fixed in React Native 0.59.9.

Source: https://github.com/facebook/react-native/issues/25154

## API

* [React Native API](https://agoraio-community.github.io/react-native-agora/globals.html)
* [Android API](https://docs.agora.io/en/Video/API%20Reference/java/index.html)
* [iOS API](https://docs.agora.io/en/Video/API%20Reference/oc/docs/headers/Agora-Objective-C-API-Overview.html)

## Resources

* Complete [API Doc](https://docs.agora.io/en/) at the Developer Center
* [Changelog](CHANGELOG.md)
* [Release Notes](https://docs.agora.io/en/video-call-4.x/release_electron_ng?platform=ReactNative)
* [File bugs about this sample](https://github.com/AgoraIO-Community/react-native-agora/issues)
* [React Native Getting Started](https://facebook.github.io/react-native/docs/getting-started.html)

## Contributing

See the [contributing guide](CONTRIBUTING.md) to learn how to contribute to the repository and the development workflow.
Expand Down
8 changes: 5 additions & 3 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ android {
compileSdkVersion safeExtGet('ReactNativeAgoraRtcNg_compileSdkVersion', 29)
buildToolsVersion safeExtGet('ReactNativeAgoraRtcNg_buildToolsVersion', '29.0.2')
defaultConfig {
minSdkVersion safeExtGet('ReactNativeAgoraRtcNg_minSdkVersion', 16)
minSdkVersion safeExtGet('ReactNativeAgoraRtcNg_minSdkVersion', 21)
targetSdkVersion safeExtGet('ReactNativeAgoraRtcNg_targetSdkVersion', 29)
versionCode 1
versionName "1.0"
Expand Down Expand Up @@ -56,6 +56,8 @@ dependencies {
//noinspection GradleDynamicVersion
implementation "com.facebook.react:react-native:+" // From node_modules
implementation fileTree(include: ['*.jar', '*.aar'], dir: 'libs')
api 'io.agora.rtc:agora-special-full:3.8.201.2.2'
implementation 'io.agora.rtc:iris-rtc:3.8.201'
api 'io.agora.rtc:agora-special-full:4.0.0.5'
implementation 'io.agora.rtc:full-screen-sharing:4.0.0.5'
implementation 'io.agora.rtc:iris-rtc:4.0.0-rc.1'
// implementation project(':iris')
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
import com.facebook.react.module.annotations.ReactModule;
import com.facebook.react.modules.core.DeviceEventManagerModule;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

Expand All @@ -40,6 +43,7 @@ public String getName() {
@ReactMethod(isBlockingSynchronousMethod = true)
public void newIrisApiEngine() {
if (irisApiEngine == null) {
IrisApiEngine.enableUseJsonArray(true);
irisApiEngine = new IrisApiEngine(getReactApplicationContext());
irisApiEngine.setEventHandler(this);
}
Expand All @@ -55,7 +59,7 @@ public void destroyIrisApiEngine() {
}

@ReactMethod(isBlockingSynchronousMethod = true)
public String callApi(ReadableMap arguments) {
public String callApi(ReadableMap arguments) throws JSONException {
String funcName = arguments.getString("funcName");
String params = arguments.getString("params");
List<byte[]> buffers = null;
Expand All @@ -72,15 +76,10 @@ public String callApi(ReadableMap arguments) {
return irisApiEngine.callIrisApi(funcName, params, buffers);
} catch (Exception e) {
e.printStackTrace();
return null;
return new JSONObject().put("result", e.getMessage()).toString();
}
}

@ReactMethod(isBlockingSynchronousMethod = true)
public void loadExtensionProvider(String path) {
System.loadLibrary(path);
}

@ReactMethod
public void addListener(String eventName) {
// Keep: Required for RN built in Event Emitter Calls.
Expand All @@ -99,7 +98,8 @@ public void OnEvent(String event, String data, List<byte[]> buffers) {
if (buffers != null) {
WritableArray array = Arguments.createArray();
for (byte[] buffer : buffers) {
array.pushString(Base64.encodeToString(buffer, 0, buffer.length, Base64.NO_WRAP));
String base64 = Base64.encodeToString(buffer, Base64.DEFAULT);
array.pushString(base64);
}
map.putArray("buffers", array);
}
Expand Down
100 changes: 100 additions & 0 deletions example/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
# API-Example-ReactNative

*__其他语言版本:__ [__简体中文__](README.zh.md)*

## Overview

The API-Example-ReactNative project is an open-source demo that will show you different scenes on how to integrate Agora SDK APIs into your project.

Any scene of this project can run successfully alone.

![example.jpg](example.jpg)

## Project structure

* **Basic demos:**

| Demo | Description |
| ------------------------------------------------------------ | -------------------------------------------------- |
| [JoinChannelAudio](./src/examples/basic/JoinChannelAudio) | Audio live streaming |
| [JoinChannelVideo](./src/examples/basic/JoinChannelVideo) | Video live streaming |
| [StringUid](./src/examples/basic/StringUid) | String user ID |

* **Advanced demos:**

| Demo | Description |
| ------------------------------------------------------------ | ------------------------------------------------------------ |
| [AudioMixing](./src/examples/advanced/AudioMixing) | Starts playing the music file |
| [AudioSpectrum](./src/examples/advanced/AudioSpectrum) | Turn on audio spectrum monitoring |
| [BeautyEffect](./src/examples/advanced/BeautyEffect) | Sets the image enhancement options |
| [ChannelMediaRelay](./src/examples/advanced/ChannelMediaRelay) | Starts relaying media streams across channels. This method can be used to implement scenarios such as co-host across channels |
| [ContentInspect](./src/examples/advanced/ContentInspect) | Content inspect |
| [DirectCdnStreaming](./src/examples/advanced/DirectCdnStreaming) | Direct CDN streaming |
| [EncodedVideoFrame](./src/examples/advanced/EncodedVideoFrame) | Encoded video frame |
| [Encryption](./src/examples/advanced/Encryption) | Enables/Disables the built-in encryption |
| [Extension](./src/examples/advanced/Extension) | Enables/Disables extensions |
| [JoinMultipleChannel](./src/examples/advanced/JoinMultipleChannel) | Joins a channel with the connection ID |
| [LocalSpatialAudioEngine](./src/examples/advanced/LocalSpatialAudioEngine) | Local spatial audio engine |
| [MediaPlayer](./src/examples/advanced/MediaPlayer) | This class provides media player functions and supports multiple instances |
| [MediaRecorder](./src/examples/advanced/MediaRecorder) | Media recorder |
| [PlayEffect](./src/examples/advanced/PlayEffect) | Plays the specified local or online audio effect file |
| [PushVideoFrame](./src/examples/advanced/PushVideoFrame) | Pushes the external raw video frame to the SDK |
| [RhythmPlayer](./src/examples/advanced/RhythmPlayer) | Enables the virtual metronome |
| [RTMPStreaming](./src/examples/advanced/RTMPStreaming) | Starts pushing media streams to a CDN without transcoding & Starts Media Push and sets the transcoding configuration |
| [ScreenShare](./src/examples/advanced/ScreenShare) | Starts screen sharing |
| [SendMetadata](./src/examples/advanced/SendMetadata) | Send data stream |
| [SendMultiVideoStream](./src/examples/advanced/SendMultiVideoStream) | Send camera & media player stream |
| [SpatialAudio](./src/examples/advanced/SpatialAudio) | Spatial audio |
| [StreamMessage](./src/examples/advanced/StreamMessage) | Sends data stream messages |
| [TakeSnapshot](./src/examples/advanced/TakeSnapshot) | Takes a snapshot of a video stream |
| [VideoEncoderConfiguration](./src/examples/advanced/VideoEncoderConfiguration) | Sets the video encoder configuration |
| [VirtualBackground](./src/examples/advanced/VirtualBackground) | Enables/Disables the virtual background (beta feature) |
| [VoiceChanger](./src/examples/advanced/VoiceChanger) | Sets the local voice changer option |

## How to run the sample project

#### Developer Environment Requirements

- [React Native](https://reactnative.dev/docs/environment-setup)

#### Steps to run

*Steps from cloning the code to running the project*

1. Open the [CONTRIBUTING.md](../CONTRIBUTING.md).
2. Read the [Development workflow](../CONTRIBUTING.md#development-workflow).
3. Open [agora.config.json](./src/config/agora.config.ts) file and specify your App ID and Token.

> See [Set up Authentication](https://docs.agora.io/en/Agora%20Platform/token) to learn how to get an App ID and access token. You can get a temporary access token to quickly try out this sample project.
>
> The Channel name you used to generate the token must be the same as the channel name you use to join a channel.
> To ensure communication security, Agora uses access tokens (dynamic keys) to authenticate users joining a channel.
>
> Temporary access tokens are for demonstration and testing purposes only and remain valid for 24 hours. In a production environment, you need to deploy your own server for generating access tokens. See [Generate a Token](https://docs.agora.io/en/Interactive%20Broadcast/token_server) for details.
4. Make the project and run the app in the simulator or connected physical device.

You are all set! Feel free to play with this sample project and explore features of the Agora RTC SDK.


## Feedback

If you have any problems or suggestions regarding the sample projects, feel free to file an issue.

## Reference

- [Product Overview](https://docs.agora.io/en/Interactive%20Broadcast/product_live?platform=React%20Native)
- [API Reference](https://docs.agora.io/en/Interactive%20Broadcast/API%20Reference/react_native/index.html)

## Related resources

- Check our [FAQ](https://docs.agora.io/en/faq) to see if your issue has been recorded.
- Dive into [Agora SDK Samples](https://github.com/AgoraIO) to see more tutorials
- Take a look at [Agora Use Case](https://github.com/AgoraIO-usecase) for more complicated real use case
- Repositories managed by developer communities can be found at [Agora Community](https://github.com/AgoraIO-Community)
- If you encounter problems during integration, feel free to ask questions in [Stack Overflow](https://stackoverflow.com/questions/tagged/agora.io)

## License

The sample projects are under the MIT license.
2 changes: 1 addition & 1 deletion example/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ dependencies {
implementation jscFlavor
}

implementation project(':react-native-agora-rtc-ng')
implementation project(':react-native-agora')
}

// Run this once to be able to run the application with BUCK
Expand Down
7 changes: 5 additions & 2 deletions example/android/settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,8 @@ rootProject.name = 'ReactNativeAgoraRtcNgExample'
apply from: file("../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesSettingsGradle(settings)
include ':app'

include ':react-native-agora-rtc-ng'
project(':react-native-agora-rtc-ng').projectDir = new File(rootProject.projectDir, '../../android')
include ':react-native-agora'
project(':react-native-agora').projectDir = new File(rootProject.projectDir, '../../android')

// include ':iris'
// project(':iris').projectDir = new File('/Users/lxh/Agora/iris/dcg/android/app')
Binary file added example/example.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 6 additions & 1 deletion example/ios/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ target 'ReactNativeAgoraRtcNgExample' do
:hermes_enabled => false
)

pod 'react-native-agora-rtc-ng', :path => '../..'
pod 'react-native-agora', :path => '../..'
# pod 'AgoraRtcWrapper', :path => '../../ios'

# Enables Flipper.
#
Expand All @@ -24,3 +25,7 @@ target 'ReactNativeAgoraRtcNgExample' do
react_native_post_install(installer)
end
end

target 'ScreenShare' do
pod 'AgoraIrisRTC_iOS', '4.0.0-rc.1'
end
Loading

0 comments on commit e1d11fd

Please sign in to comment.