NOTE: This repository is not maintained anymore, feel free to fork it and modify for your own convinience. If you are interested in maintaining this reposiotry, please reach out to us on Discord:
React Native OpenTok is wrapper over native TokBox OpenTok SDK. The OpenTok platform, developed by TokBox, makes it easy to embed high-quality interactive video, voice, messaging, and screen sharing into web and mobile apps. OpenTok uses WebRTC for audio-video communications ππ§. For more info on how OpenTok works, check out OpenTok Basics.
react-native
>=0.49.3Supported OpenTok SDK version:
OpenTok SDK
2.13.+React native OpenTok SDK depends on native OpenTok SDK implementations. You need to integrate OpenTok SDK into your existing application. Following steps needs to be done in order to have library working correctly:
Add library using yarn
π¦ (or npm
):
yarn add react-native-opentok
ios/
directory please run pod init
.Podfile
with:
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '9.0'
target '
pod 'yoga', path: "#{node_modules_path}/react-native/ReactCommon/yoga/yoga.podspec" pod 'React', path: "#{node_modules_path}/react-native"
pod 'RNOpenTok', path: "#{node_modules_path}/react-native-opentok/ios" end
post_install do |installer| installer.pods_project.targets.each do |target| if target.name == "React" target.remove_from_project end end end
4. Run `pod install`.
5. Open <YOUR_PROJECT_NAME>.xcworkspace file (you'll need to use it as a starting file from now on).
6. Add `OPENTOK_API_KEY` key to your `Info.plist`:
```xml
<key>OPENTOK_API_KEY</key>
<string>YOUR_API_KEY</string>
<key>NSCameraUsageDescription</key>
<string>${PRODUCT_NAME} Camera Usage</string>
<key>NSMicrophoneUsageDescription</key>
<string>${PRODUCT_NAME} Microphone Usage</string>
react-native link
.android/build.gradle
file and update allprojects section:
allprojects {
repositories {
...
// -------------------------------------------------
// Add this below the existing maven property above
// -------------------------------------------------
maven {
url "http://tokbox.bintray.com/maven"
}
}
}
OPENTOK_API_KEY
to your AndroidManifest.xml
(within <application>
tag):
<meta-data android:name="OPENTOK_API_KEY" android:value="YOUR_OPENTOK_API_KEY" />
Override Api key.
OpenTok.setApiKey('YOUR_API_KEY');
Connects to choosen session.
const connectToSession = async () => {
try {
await OpenTok.connect('YOUR_SESSION_ID', 'YOUR_TOKEN');
} catch (e) {
console.log(e)
}
}
Disconnects from chosen session.
OpenTok.disconnect('YOUR_SESSION_ID');
Disconnects all available sessions.
OpenTok.disconnectAll();
Send signal to chosen session.
const connectToSession = async () => {
try {
await OpenTok.connect('YOUR_SESSION_ID', 'YOUR_TOKEN');
} catch (e) {
console.log(e)
}
}
Constants for events thrown in app. Available values:
Event listener, for events listed above.
OpenTok.on(OpenTok.events.ON_SIGNAL_RECEIVED, e => console.log(e));
Removes listener.
OpenTok.removeListener(OpenTok.events.ON_SIGNAL_RECEIVED);
Component used for publishing the video to the stream.
Available props:
sessionId: string
- ID of the session (you need to connect it before using this component).onPublishStart?: Function
- Invoked when publishing starts. Optional.onPublishStop?: () => void
- Invoked when publishing stops. Optional.onPublishError?: () => void
- Invoked when publish error occurs. Optional.mute?: boolean
- This props tells Publisher if should publish audio as well or not. Optional. Defaults to false.video?: boolean
- This props tells Publisher if should publish video as well or not. Optional. Defaults to true.videoScale?: string
- Whether the video should scale to fill
the frame or fit
into the frame.zOrderMediaOverlay?: boolean
- On android, calls SurfaceView.setZOrderMediaOverlay. Optional. Defaults to true.cameraDirection?: string
- Whether the camera should face front
(towards screen) or back
(away from screen).screenCapture?: boolean
- Stream screen if true
instead of camera.screenCaptureSettings?: { fps?: number }
- Screen sharing settings.
fps?: number
- Specify frames per second for a stream (default: 15
).Available methods:
switchCamera()
: switches to the next camera. Goes back to first one when out of cameras. Calling this will overwrite cameraDirection
.import { Publisher } from 'react-native-opentok'
<Publisher
style={{ height: 100, width: 200 }}
sessionId={sessionId}
onPublishStart={() => { console.log('started')}}
/>
Component used for subscribing to the stream.
Available props:
sessionId: string
- ID of the session (you need to connect it before using this component).onSubscribeStart?: Function
- Invoked when stream starts. Optional.onSubscribeStop?: () => void
- Invoked when stream stops. Optional.onSubscribeError?: () => void
- Invoked when subscribing error occurs. Optional.mute?: boolean
- This props tells Subscriber if should subscribe audio as well or not. Optional. Defaults to false.video?: boolean
- This props tells Subscriber if should subscribe video as well or not. Optional. Defaults to true.videoScale?: string
- Whether the video should scale to fill
the frame or fit
into the frame.zOrderMediaOverlay?: boolean
- On android, calls SurfaceView.setZOrderMediaOverlay. Optional. Defaults to true.import { Subscriber } from 'react-native-opentok'
<Subscriber
style={{ height: 100, width: 200 }}
sessionId={sessionId}
onSubscribeStart={() => { console.log('started')}}
/>
Component used for capturing a stream of it's children for screen sharing.
Everything inside this component will be streamed as long as <Publisher>
has screenCapture
prop set to true
.
Available props:
nativeID
.import { Publisher, ScreenCapture } from 'react-native-opentok';
<ScreenCapture>
{/* some children */}
</ScreenCapture>
<Publisher screenCapture>
Simply import the library and use methods/components listed above.
import OpenTok from 'react-native-opentok';
Check out example project.
MichaΕ Chudziak π» |
Drapich Piotr π» |
Mike Grabowski π» |
Jakub BeneΕ‘ π» |
Radek Czemerys π» |
Jacob Caban-Tomski π» |
damiantw π» |
---|
Thanks to TokBox for native SDKs development.
This project follows the all-contributors specification. Contributions of any kind welcome!