React Native SDK
Overview
Apps written with the React Native SDK 2.28+ can interoperate with Vonage apps written with version 2.26+ of the client SDKs:
- OpenTok.js
- Android SDK
- iOS SDK
- Windows SDK
- macOS SDK
- Linux SDK
The React Native SDK is built on top of the Android SDK and iOS SDK. For details, see the following:
Prerequisites
Install node.js
Install and update Xcode (you will need a Mac). (See the React Native iOS installation instructions.)
Install and update Android Studio. (See the React Native Android installation instructions.)
System requirements
See the system requirements for the Android SDK and iOS SDK. (The React Native SDK has the same requirements for Android and iOS.)
Installation
- In your terminal, change into your React Native project's directory.
- Add the library using
npmoryarn:npm install @vonage/client-sdk-video-react-nativeyarn add @vonage/client-sdk-video-react-native
iOS Installation
Install the iOS pods:
For React Native versions prior to 0.60:
- Add this to your Podfile:
- Run
react-native link @vonage/client-sdk-video-react-native.
These steps are not necessary in React Native version 0.60 and later.
- Ensure you have enabled both camera and microphone usage by adding the following entries to the
Info.plistfile:
When you create an archive of your app, the privacy manifest settings required by Apple's App store are added automatically with this version of the React Native SDK.
If you try to archive the app and it fails, please do the following:
- Go to Target.
- Click Build Phases.
- Under the Link Binary With Libraries section, remove
libOpenTokReactNative.aand add it again.
Android Installation
- In your terminal, change into your project directory.
- For React Native versions prior to 0.60: - Run
react-native link @vonage/client-sdk-video-react-nativeThis step is not necessary in React Native version 0.60 and later. - Run
bundle install. - Make sure the following in your app's gradle
compileSdkVersion,buildToolsVersion,minSdkVersion, andtargetSdkVersionare greater than or equal to versions specified in the React Native library. - For older Android devices, add the following permissions to the
AndroidManifest.xmlfile: *android.permission.BLUETOOTH-- The default audio device supports Bluetooth audio. If your app does not use the default audio device and does not use Bluetooth, you can remove this permission. *android.permission.BLUETOOTH_CONNECT-- You need to enable this for API level 31 and above. If you want to use the Bluetooth device with Android SDK DefaultAudioDevice targeting API level 31 and above, please ask for runtime permissions in the app or enable the ("Nearby devices/Bluetooth") permission manually in the app settings *android.permission.BROADCAST_STICKY-- We have determined that this is unused by the Android SDK, and we will remove this permission from an upcoming release. *android.permission.CAMERA-- If your app does not use the default video capturer and does not access the camera, you can remove this permission.android.permission.INTERNET-- Required.android.permission.MODIFY_AUDIO_SETTINGS-- If your app does not use the default audio device and does not access the microphone, you can remove this permission.android.permission.READ_PHONE_STATE-- The Android SDK requests this permission in API level 22 and lower, and 31 and above.android.permission.RECORD_AUDIO-- If your app does not use the default audio device and does not access the microphone, you can remove this permission.
For newer versions of Android — API Level 23 (Android 6.0) and later — you do not need to add these to your app manifest. The React Native SDK adds them automatically. However, if you use Android 21+, certain permissions require you to prompt the user.
Your app can remove any of these permissions that will not be required. See this post and this Android documentation. For example, this removes the android.permission.CAMERA permission:
Bintray sunset
Bintray support has ended (official announcement: https://jfrog.com/blog/into-the-sunset-bintray-jcenter-gocenter-and-chartcenter/). In your app build.gradle file you need to remove reference to jcenter and replace it with mavenCentral. Example:
Basic sample
This simplest use of these opentok-react-native components:
Replace your-app-id, your-session-id, and your-token with your app ID, a session ID, and a token for the session respectively.
Note that you add the OTPublisher and OTSubscriber components and children of the OTSession component. Use the style and className properties to use CSS to adjust publisher and subscriber layout.
Unsupported features
The React Native library provides a React interface for using the Android and iOS client SDKs. The following advanced features of the Android and iOS client SDKs are unsupported in the React Native library:
Custom audio drivers -- An application using React Native use the device microphone to capture audio to transmit to a published stream. And it uses the device speakers (or headphones) to play back audio from subscribed streams. However, you can set the enableStereoOutput property of the OTSession object to enable stereo output.
Custom video capturers -- (BaseVideoCapturer) -- The React Native OTPublisher uses the standard video capturer that uses video directly from the device's camera. However, you can set the videoSource property of an OTPublisher component to "screen" to publish a screen-sharing stream.
Custom video renderers -- The OTSubscriber and OTPublisher components implement a standard video renderer that renders streams and provides user interface controls for displaying the stream name and muting the microphone or camera. Publishers and subscribers use
mPublisher.setStyle(BaseVideoRenderer.STYLE_VIDEO_SCALE, BaseVideoRenderer.STYLE_VIDEO_FILL)iOS delegate callback queue -- For iOS, you cannot assign the delegate callback queue (the GCD queue). See the docs for the OTSession.apiQueue property in the iOS SDK.
To build Android and iOS apps that use these features, use the Android SDK and the iOS SDK.
More samples
To see this library in action, check out the opentok-react-native-samples repo.