diff --git a/packages/react-native-sdk/docusaurus/docs/reactnative/02-tutorials/01-video-calling.mdx b/packages/react-native-sdk/docusaurus/docs/reactnative/02-tutorials/01-video-calling.mdx index f8d968459f..ec565be47e 100644 --- a/packages/react-native-sdk/docusaurus/docs/reactnative/02-tutorials/01-video-calling.mdx +++ b/packages/react-native-sdk/docusaurus/docs/reactnative/02-tutorials/01-video-calling.mdx @@ -3,7 +3,12 @@ title: Video Call Tutorial description: How to build a video call application similar to Zoom or Google Meet --- +import Tabs from '@theme/Tabs'; +import TabItem from '@theme/TabItem'; + import { TokenSnippet } from '../../../shared/_tokenSnippet.jsx'; +import homeScreenImg from '../assets/02-tutorials/01-video-calling/home-screen.png' +import videoScreenEmpty from '../assets/02-tutorials/01-video-calling/video-empty.png' This tutorial teaches you how to build Zoom/Whatsapp style video calling for your app. @@ -12,7 +17,7 @@ This tutorial teaches you how to build Zoom/Whatsapp style video calling for you - Video quality and codecs are automatically optimized. - Powered by Stream's [Video Calling API](https://getstream.io/video/). -### Step 1 - Setup a new React Native app +## Step 1 - Setup a new React Native app Create a new React Native app using the official template, @@ -21,26 +26,31 @@ npx react-native@latest init VideoCallExample cd VideoCallExample ``` -### Step 2 - Install the SDK and declare permissions +## Step 2 - Install the SDK and declare permissions -To install the Stream Video React Native SDK, run the following command in your terminal of choice: +In order to install the Stream Video React Native SDK, run the following command in your terminal of choice: ```bash title=Terminal -yarn add @stream-io/video-react-native-sdk +yarn add @stream-io/video-react-native-sdk @stream-io/react-native-webrtc ``` The SDK requires installing some peer dependencies. You can run the following command to install them: ```bash title=Terminal -yarn add @stream-io/react-native-webrtc react-native-device-info \ - react-native-incall-manager react-native-svg \ - @react-native-community/netinfo @notifee/react-native +yarn add react-native-device-info@10.6.0 +yarn add react-native-incall-manager@4.1.0 +yarn add react-native-svg +yarn add @react-native-community/netinfo@9.3.9 +yarn add @notifee/react-native@7.7.1 + +# Install pods for iOS npx pod-install ``` #### Add Stream Video SDK's setup method -##### Android + + Add the following in your `MainApplication.java` file: @@ -60,9 +70,9 @@ public class MainApplication extends Application implements ReactApplication { } } ``` - -##### iOS + + Add the following in your `AppDelegate.m` or `AppDelegate.mm` file: @@ -81,31 +91,37 @@ Add the following in your `AppDelegate.m` or `AppDelegate.mm` file: } ``` -#### Declare permissions - -##### iOS + + -Add the following keys and values to `Info.plist` file: - -- `Privacy - Camera Usage Description` - "`VideoCallExample` requires camera access to capture and transmit video" -- `Privacy - Microphone Usage Description` - "`VideoCallExample` requires microphone access to capture and transmit audio" +#### Declare permissions -##### Android + + -In `AndroidManifest.xml` add the following permissions before the `` section. +In `AndroidManifest.xml` add the following permissions before the `application` section. ```xml - - - - - - - - - - - + + // highlight-start + + + + + + + + + + + // highlight-end + + ... + + + ``` If you plan to also support Bluetooth devices then also add the following. @@ -116,8 +132,34 @@ If you plan to also support Bluetooth devices then also add the following. ``` + + + +Add the following keys and values to `Info.plist` file, under `dict` tag. + +```plist title="Info.plist" + + + ... + CFBundleName + $(PRODUCT_NAME) + // highlight-start + NSCameraUsageDescription + $(PRODUCT_NAME) would like to use your camera + NSMicrophoneUsageDescription + $(PRODUCT_NAME) would like to use your microphone + // highlight-end + ... + + + +``` + + + + :::note -For simplicity, in this tutorial, we do not cover about managing native runtime permissions. Before starting the next step, ensure that camera and microphone permissions are given for this app by granting them in the native settings app. We have discussed a detailed solution to manage native runtime permissions in the [Manage Native Permissions](../../core/native-permissions) guide. +For simplicity, in this tutorial, we do not cover about managing native runtime permissions. Before starting the next step, ensure that microphone permissions are given for this app by granting them in the native settings app. We have discussed a detailed solution to manage native runtime permissions in the [Manage Native Permissions](../../core/native-permissions) guide. ::: #### Android Specific installation @@ -125,9 +167,14 @@ For simplicity, in this tutorial, we do not cover about managing native runtime In `android/app/build.gradle` add the following inside the `android` section: ```java -compileOptions { - sourceCompatibility JavaVersion.VERSION_1_8 - targetCompatibility JavaVersion.VERSION_11 +android { + ... + // highlight-start + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_11 + } + // highlight-end } ``` @@ -137,160 +184,413 @@ In `android/gradle.properties` add the following: android.enableDexingArtifactTransform.desugaring=false ``` -### Step 3 - Create & Join a call +#### Run the app -Open up `src/App.tsx` and replace it with this code: +To ensure the best possible experience, we highly recommend running the app on a physical device. +This is due to the limitations in audio and video device support on emulators. +You can refer to the React Native documentation for guidance on [running the app on a physical device](https://reactnative.dev/docs/running-on-device). -```tsx title="App.tsx" -import { - StreamVideoClient, - CallingState, - StreamVideo, - StreamCall, - User, - useCall, - useCallStateHooks, - StreamVideoRN, -} from '@stream-io/video-react-native-sdk'; -import React from 'react'; -import { SafeAreaView, Text } from 'react-native'; +However, if you still prefer to use an emulator, execute the following command: -// for simplicity, we assume that permission was granted through the native settings app -StreamVideoRN.setPermissions({ - isMicPermissionGranted: true, - isCameraPermissionGranted: true, -}); +```bash +# run iOS app +yarn ios -const apiKey = 'REPLACE_WITH_API_KEY'; // the API key can be found in the "Credentials" section -const token = 'REPLACE_WITH_TOKEN'; // the token can be found in the "Credentials" section -const userId = 'REPLACE_WITH_USER_ID'; // the user id can be found in the "Credentials" section -const callId = 'REPLACE_WITH_CALL_ID'; // the call id can be found in the "Credentials" section +# run Android app +yarn android +``` -// set up the user object -const user: User = { - id: userId, - name: 'Santhosh', - image: `https://getstream.io/random_png/?id=${userId}&name=Santhosh`, -}; +## Step 3 - Understand the basics + +Before we dive deep into writing code, there are two concepts you should be familiar with - `StreamVideoClient` and `Call`. + +### Client + +`StreamVideoClient` is the low level JavaScript client used by the SDK to communicate with the Stream Video service. +In the case of React Native Video SDK, you will need to provide this client instance to the top level `StreamVideo` component. +This component will then provide the client instance to all the child components using React Context. + +Using client, you can create a call, receive calls, get list of calls etc. This should be ideally done at sign in stage of the application. +```tsx const client = new StreamVideoClient({ apiKey, user, token }); -const call = client.call('default', callId); -call.join({ create: true }); +``` -export default function App() { - return ( - - - - - - - - ); -} +In this example +- `apiKey` is the API key of your Stream Video application available on [dashboard](https://dashboard.getstream.io/organization/5380/apps) +- `user` is the user object + ```json + { + "id": "john_smith", + "name": "John Smith", + "image": "https://getstream.io/random_png/?id=john_smith&name=John+Smith" + } + ``` +- and `token` is the user token generated by your server-side API. For development purpose, you can use the token generated by the [Token Generator](https://getstream.io/chat/docs/react/token_generator/). +You can read more information about client authentication on the [Client & Authentication](../../core/client-auth) guide. -const VideoCallUI = () => { - const call = useCall(); +:::info +Alternatively you can also choose to separate client creation and user connection: - const { useCallCallingState, useParticipantCount } = useCallStateHooks(); - const callingState = useCallCallingState(); - const participantCount = useParticipantCount(); +```tsx +const client = new StreamVideoClient({ apiKey }); +await client.connectUser(user, token); +``` +::: - if (callingState !== CallingState.JOINED) { - return Loading...; +### Call + +In the context of Stream video/audio service, a `call` refers to an instance of the [`Call` class](https://github.com/GetStream/stream-video-js/blob/main/packages/client/src/Call.ts#L125) and is utilized for performing call-specific actions, such as joining a call, muting participants, leaving a call, and more. +You will need to supply this `call` instance to the `StreamCall` component. + +The following example illustrates how to create a call instance of the `default` type. +Detailed information about various call types can be found in the [Call Types](../../core/configuring-call-types) guide. + +```tsx +const call = client.call('audio_room', callId); +``` + +Subsequently, the `call.join` method can be utilized to enter the call identified by the given unique case-sensitive `callId`. +For designating roles to call participants, you can specify the role through the `data.members` parameter of the `call.join` method. + +```tsx +// User joins the call +call.join({ + create: true, // create the call if it doesn't exist + data: { + members: [ + { user_id: 'john_smith' }, + { user_id: 'jane_doe' } + ], + custom: { // custom data set on call + title: 'React Native test', + description: 'Conducting a test of React Native video calls', + }, } +}); +``` + +## Step 4 - Setup Starter UI + +Lets begin by creating a basic UI for our audio room. Normally you would use a navigation library like [React Navigation](https://reactnavigation.org/) to navigate between screens. +But for this tutorial we'll keep it simple and mock the navigation using a state variable - `activeScreen`. +Within your tutorial app, create a folder named `src` and create the following files within it: + +- `src/HomeScreen.tsx` +- `src/VideoCallScreen.tsx` + +Now copy the following content into the respective files (as mentioned in header): + + + + +```tsx title="src/VideoCallScreen.tsx" +import React from 'react'; +import {Button, StyleSheet, Text, View} from 'react-native'; + +type Props = {goToHomeScreen: () => void}; + +export const VideoCallScreen = ({goToHomeScreen}: Props) => { return ( - - Call "{call?.id}" has {participantCount} participants - + + Here we will add Video Calling UI +