Quickstart
This quickstart shows how to use RealtimeKit's UI Kit prebuilt components to add live video and audio to your React application with minimal coding and a variety of meeting UI customization options.
Before Getting Started
-
Make sure you've read the Getting Started with RealtimeKit topic and completed the following steps:
- Create a developer account
- Create a RealtimeKit Meeting
- Add Participant to the meeting
Step 1: Installation
Since the UI Kit uses the RealtimeKit Core SDK, you must install the
@cloudflare/realtimekit-react-native
package along with the @cloudflare/realtimekit-react-native-ui
.
@cloudflare/realtimekit-react-native-ui | |
@cloudflare/realtimekit-react-native |
- React Native
- Expo
npm install @cloudflare/realtimekit-react-native-ui @cloudflare/realtimekit-react-native
Install the required native dependencies
npm install @cloudflare/react-native-webrtc @react-native-documents/picker react-native-file-viewer react-native-fs react-native-sound-player react-native-webview
Install these required dependencies as per your react-native
version
-
react-native-safe-area-context
- react-native (0.64 - 0.74) :
npm install react-native-safe-area-context@^4.0.0
- react-native (>= 0.74) :
npm install react-native-safe-area-context@^5.0.0
- react-native (0.64 - 0.74) :
-
react-native-svg
- Follow the installation instructions for react-native-svg.
-
npm install react-native-svg@<compatible-version>
Additional steps for interactive livestream product
Install the following dependencies only if you need livestream.
npm install amazon-ivs-react-native-player
- Android
- iOS
The below instructions are for the release builds, debug builds should work without any additional steps.
- Edit your
android/gradle.properties
and add the following line
newArchEnabled=false
android.useFullClasspathForDexingTransform=true
- Create / append to the file
android/app/proguard-rules.pro
-keep class io.webrtc.** { *; }
-dontwarn org.chromium.build.BuildHooksAndroid
- In your
android/app/build.gradle
edit the release configuration and add the following line importing the proguard configuration
buildTypes {
release {
...
...
...
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
We support minimum OS version 14.0
for our iOS SDK.
- Open your podfile and make sure your platform is set to ios 14
platform :ios, '14.0'
- Add the fonts and permission entries in
info.plist
<key>NSCameraUsageDescription</key>
<string>For people to see you during meetings, we need access to your camera.</string>
<key>NSMicrophoneUsageDescription</key>
<string>For people to hear you during meetings, we need access to your microphone.</string>
<key>NSPhotoLibraryUsageDescription</key>
<string>For people to share, we need access to your photos.</string>
<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>
npx expo install @cloudflare/realtimekit-react-native-ui @cloudflare/realtimekit-react-native
Install the required native dependencies
npm install @cloudflare/react-native-webrtc @react-native-documents/picker react-native-file-viewer react-native-fs react-native-sound-player react-native-webview
Install these required dependencies as per your react-native
version
-
react-native-safe-area-context
- react-native (0.64 - 0.74) :
npm install react-native-safe-area-context@^4.0.0
- react-native (>= 0.74) :
npm install react-native-safe-area-context@^5.0.0
- react-native (0.64 - 0.74) :
-
react-native-svg
- Follow the installation instructions for react-native-svg.
-
npm install react-native-svg@<compatible-version>
Install expo's config-plugins if it is not installed already
npx expo install @expo/config-plugins
Additional steps for interactive livestream product
Install the following dependencies only if you need livestream.
npx expo install amazon-ivs-react-native-player
Configure Expo Config Plugins
In app.json
, add these to plugins:
{
expo: {
...
"plugins": [
"@cloudflare/realtimekit-react-native",
"@cloudflare/react-native-webrtc"
],
...
}
}
Setup Native Modules with Config Plugins in Expo
npx expo prebuild
Additional Steps for Screenshare
- Android
- iOS
- In AndroidManifest.xml, Add this service
<application>
...
<service
android:enabled="true"
android:foregroundServiceType="mediaProjection|camera|microphone"
android:name="com.reactnativecore.ForegroundService">
</service>
...
</application>
- Add these permissions
<manifest ...>
...
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_CAMERA" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_MICROPHONE" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_MEDIA_PROJECTION" />
...
</manifest>
- In
Xcode
, Go to Targets -> Add a target -> ChooseBroadcast Upload Extension
(Choose Swift as Language) - Go to
Targets Signing & Capabilities
, and enableApp Groups
for both App target and Broadcast Upload Extension target - In the app's target, add the following in
Info.plist
:<key>RTCAppGroupIdentifier</key>
<string>YOUR_APP_GROUP</string>
<key>RTCAppScreenSharingExtension</key>
<string>BUNDLE_IDENTIFIER_FOR_BROADCAST_UPLOAD_EXTENSION</string> - Add these changes to your iOS folder's Podfile:
target 'YOUR_APP_TARGET_NAME'
...
post_install do |installer|
...
# Add these for RealtimeKit iOS Screenshare
installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
config.build_settings['APPLICATION_EXTENSION_API_ONLY'] = 'No'
config.build_settings['ENABLE_USER_SCRIPT_SANDBOXING'] = 'No'
end
end
...
end
...
end
# Add this at the end of Podfile
pod 'YOUR_BROADCAST_EXTENSION_TARGET_NAME'
config = use_native_modules!
use_react_native!(:path => config["reactNativePath"], :hermes_enabled => false)
# Support RealtimeKitCore Pod in the Broadcast Upload Extension
pod 'RealtimeKitCore', :path => '../node_modules/@cloudflare/realtimekit-react-native'
end - Replace the
SampleHandler
in Broadcast Upload Extension with the following:import RealtimeKitCore
class SampleHandler: RTKScreenshareHandler {
override init() {
super.init(appGroupIdentifier: "YOUR_APP_GROUP", bundleIdentifier: "BUNDLE_IDENTIFIER_FOR_BROADCAST_UPLOAD_EXTENSION")
}
}Note: Replace
YOUR_APP_GROUP
with your App Group Name andBUNDLE_IDENTIFIER_FOR_BROADCAST_UPLOAD_EXTENSION
with Bundle Identifier of Screnshare Extension. - Go to Broadcast Extension target ->
Build Settings
Build Options
-> SetUser Script Sandboxing
toNo
Signing
->Enable App Sandbox
toNo
- Now enable the screenshare pop up handle and then enable RealtimeKit's screenshare API:
// To enable screenshare
await meeting.self.enableScreenShare();
// To disable screenshare
await meeting.self.disableScreenShare();
Step 2: Get Started with RealtimeKit Prebuilt Components
Here's a series of steps that you need to perform:
- Set up
RealtimeKitProvider
. This provides the context that provides meeting object and other data to all the child components. - Set up
RtkUIProvider
. This provides design system to child components. - Initialize the RealtimeKit client. Use the
useRealtimeKitClient()
hook andinitMeeting
to initialize a client.
authToken | After you've created the meeting, add each participant to the meeting using the Add Participant API. The API response contains the authToken. |
- Pass the meeting object to UI Kit, which will use it to retrieve meeting information and display it on the user interface.
import React, { useEffect } from 'react';
import { RealtimeKitProvider, useRealtimeKitClient } from '@cloudflare/realtimekit-react-native';
import { RtkUIProvider, RtkMeeting, RtkWaitingScreen } from '@cloudflare/realtimekit-react-native-ui';
export default function App() {
const [meeting, initMeeting] = useRealtimeKitClient();
useEffect(() => {
const init = async () => {
initMeeting({
authToken: '<auth-token>',
defaults: {
audio: true,
video: true,
},
});
};
init();
}, []);
return (
<RealtimeKitProvider value={meeting}>
<RtkUIProvider>
{ !meeting ?
<RtkWaitingScreen /> :
<RtkMeeting meeting={meeting} showSetupScreen={true} iOSScreenshareEnabled={true} />
}
</RtkUIProvider>
</RealtimeKitProvider>
);
}
Example: Using Prebuilt RtkMeeting
Component
In the following example, a meeting is created using the useRealtimeKitMeeting
component. useRealtimeKitMeeting
essentially returns the meeting object you passed to
the RealtimeKitProvider
.
RtkMeeting
renders the entire meeting UI. It loads your preset and renders
the UI based on it. With this component, you don't have to handle all the
states, dialogs, and other smaller bits of managing the application.
For more information on the other props of RtkMeeting
, see
RtkMeeting.
function YourCustomMeetingComponent() {
const { meeting } = useRealtimeKitMeeting();
return <RtkMeeting meeting={meeting} />;
}