### Install react-native-twilio-video-webrtc Source: https://context7.com/blackuy/react-native-twilio-video-webrtc/llms.txt Installs the react-native-twilio-video-webrtc package using npm or yarn and sets up CocoaPods dependencies for iOS. ```bash # Install with yarn yarn add react-native-twilio-video-webrtc # Or with npm npm install react-native-twilio-video-webrtc # For iOS, install CocoaPods dependencies cd ios && pod install ``` -------------------------------- ### Registering the Example Component in React Native Source: https://github.com/blackuy/react-native-twilio-video-webrtc/blob/master/README.md This code snippet demonstrates how to register the main example component for the React Native application using AppRegistry. It's a standard way to bootstrap a React Native app. ```javascript AppRegistry.registerComponent("Example", () => Example); ``` -------------------------------- ### Install Node Package with npm Source: https://github.com/blackuy/react-native-twilio-video-webrtc/blob/master/README.md Installs the react-native-twilio-video-webrtc package using the npm package manager. This is an alternative to Yarn for adding the library to your project. ```shell npm install react-native-twilio-video-webrtc ``` -------------------------------- ### Install Node Package with Yarn Source: https://github.com/blackuy/react-native-twilio-video-webrtc/blob/master/README.md Installs the react-native-twilio-video-webrtc package using the Yarn package manager. This is a prerequisite for using the library in a React Native project. ```shell yarn add react-native-twilio-video-webrtc ``` -------------------------------- ### Complete React Native Twilio Video Call Example Source: https://github.com/blackuy/react-native-twilio-video-webrtc/blob/master/README.md A full example demonstrating how to use Twilio Video in a React Native application. It covers connecting to a room, managing participant video tracks, and controlling audio/video. ```javascript import React, { Component, useRef } from "react"; import { TwilioVideoLocalView, TwilioVideoParticipantView, TwilioVideo, } from "react-native-twilio-video-webrtc"; const Example = (props) => { const [isAudioEnabled, setIsAudioEnabled] = useState(true); const [isVideoEnabled, setIsVideoEnabled] = useState(true); const [status, setStatus] = useState("disconnected"); const [participants, setParticipants] = useState(new Map()); const [videoTracks, setVideoTracks] = useState(new Map()); const [token, setToken] = useState(""); const twilioRef = useRef(null); const _onConnectButtonPress = () => { twilioRef.current.connect({ accessToken: token }); setStatus("connecting"); }; const _onEndButtonPress = () => { twilioRef.current.disconnect(); }; const _onMuteButtonPress = () => { twilioRef.current .setLocalAudioEnabled(!isAudioEnabled) .then((isEnabled) => setIsAudioEnabled(isEnabled)); }; const _onFlipButtonPress = () => { twilioRef.current.flipCamera(); }; const _onRoomDidConnect = ({ roomName, error }) => { console.log("onRoomDidConnect: ", roomName); setStatus("connected"); }; const _onRoomDidDisconnect = ({ roomName, error }) => { console.log("[Disconnect]ERROR: ", error); setStatus("disconnected"); }; const _onRoomDidFailToConnect = (error) => { console.log("[FailToConnect]ERROR: ", error); setStatus("disconnected"); }; const _onParticipantAddedVideoTrack = ({ participant, track }) => { console.log("onParticipantAddedVideoTrack: ", participant, track); setVideoTracks((originalVideoTracks) => { originalVideoTracks.set(track.trackSid, { participantSid: participant.sid, videoTrackSid: track.trackSid, }); return new Map(originalVideoTracks); }); }; const _onParticipantRemovedVideoTrack = ({ participant, track }) => { console.log("onParticipantRemovedVideoTrack: ", participant, track); setVideoTracks((originalVideoTracks) => { originalVideoTracks.delete(track.trackSid); return new Map(originalVideoTracks); }); }; return ( {status === "disconnected" && ( React Native Twilio Video setToken(text)} > )} {(status === "connected" || status === "connecting") && ( {status === "connected" && ( {Array.from(videoTracks, ([trackSid, trackIdentifier]) => { return ( ); })} )} End {isAudioEnabled ? "Mute" : "Unmute"} Flip )} { const twilioRef = useRef(null); const fetchStats = () => { if (twilioRef.current) { twilioRef.current.getStats(); } }; return ( { console.log("Connection stats:", stats); // Process stats data (bandwidth, latency, packet loss, etc.) }} /> // Button or other trigger to call fetchStats() ); }; ``` -------------------------------- ### iOS Info.plist Permissions Source: https://github.com/blackuy/react-native-twilio-video-webrtc/blob/master/README.md Configures the necessary permissions in the iOS Info.plist file for camera and microphone usage. These keys provide the descriptive text shown to the user when the app first requests access to these hardware components. ```xml NSCameraUsageDescription Your message to user when the camera is accessed for the first time NSMicrophoneUsageDescription Your message to user when the microphone is accessed for the first time ``` -------------------------------- ### Android Permissions Configuration Source: https://context7.com/blackuy/react-native-twilio-video-webrtc/llms.txt Configures required permissions in AndroidManifest.xml for camera and audio settings. These are static declarations necessary for the app to utilize hardware features. ```xml ``` -------------------------------- ### iOS Permissions Configuration Source: https://context7.com/blackuy/react-native-twilio-video-webrtc/llms.txt Adds required privacy usage descriptions to the Info.plist file for camera and microphone access on iOS. These keys inform the user why the app needs access to these sensitive resources. ```xml NSCameraUsageDescription This app requires camera access for video calls NSMicrophoneUsageDescription This app requires microphone access for audio calls ``` -------------------------------- ### CustomTwilioVideoView Component Properties Source: https://github.com/blackuy/react-native-twilio-video-webrtc/blob/master/docs/README.md This section details the properties available for the CustomTwilioVideoView component, which are used to configure its behavior and handle various events. ```APIDOC ## CustomTwilioVideoView Component Properties ### Description The `CustomTwilioVideoView` component allows for the integration of Twilio's WebRTC video functionality within a React Native application. It exposes a set of properties to manage video streams, participant interactions, and network quality reporting. ### Method N/A (Component Properties) ### Endpoint N/A (Component Properties) ### Parameters #### Properties (Props) - **onCameraSwitched** (func) - Optional - Callback that is called when camera source changes. - **onVideoChanged** (func) - Optional - Callback that is called when video is toggled. - **onAudioChanged** (func) - Optional - Callback that is called when audio is toggled. - **onRoomDidConnect** (func) - Optional - Called when the room has connected. Receives an object with `roomName`, `participants`, and `localParticipant`. - **onRoomDidFailToConnect** (func) - Optional - Callback that is called when connecting to room fails. - **onRoomDidDisconnect** (func) - Optional - Called when the user is disconnected from the room. - **onParticipantAddedDataTrack** (func) - Optional - Called when a new data track has been added. Receives `participant` and `track`. - **onParticipantRemovedDataTrack** (func) - Optional - Called when a data track has been removed. Receives `participant` and `track`. - **onDataTrackMessageReceived** (func) - Optional - Called when a dataTrack receives a message. Receives `message` and `trackSid`. - **onParticipantAddedVideoTrack** (func) - Optional - Called when a new video track has been added. Receives `participant`, `track`, and `enabled`. - **onParticipantRemovedVideoTrack** (func) - Optional - Called when a video track has been removed. Receives `participant` and `track`. - **onParticipantAddedAudioTrack** (func) - Optional - Called when a new audio track has been added. Receives `participant` and `track`. - **onParticipantRemovedAudioTrack** (func) - Optional - Called when an audio track has been removed. Receives `participant` and `track`. - **onRoomParticipantDidConnect** (func) - Optional - Callback called when a participant enters a room. - **onRoomParticipantDidDisconnect** (func) - Optional - Callback that is called when a participant exits a room. - **onParticipantEnabledVideoTrack** (func) - Optional - Called when a video track has been enabled. Receives `participant` and `track`. - **onParticipantDisabledVideoTrack** (func) - Optional - Called when a video track has been disabled. Receives `participant` and `track`. - **onParticipantEnabledAudioTrack** (func) - Optional - Called when an audio track has been enabled. Receives `participant` and `track`. - **onParticipantDisabledAudioTrack** (func) - Optional - Called when an audio track has been disabled. Receives `participant` and `track`. - **onStatsReceived** (func) - Optional - Callback that is called when stats are received (after calling `getStats`). - **onNetworkQualityLevelsChanged** (func) - Optional - Callback that is called when network quality levels are changed (only if `enableNetworkQualityReporting` in `connect` is set to true). - **onDominantSpeakerDidChange** (func) - Optional - Called when dominant speaker changes. Receives `participant` and `room`. ### Request Example ```javascript ``` ### Response #### Success Response (N/A for component properties) N/A #### Response Example N/A ``` -------------------------------- ### Configure Expo Plugin for Permissions Source: https://context7.com/blackuy/react-native-twilio-video-webrtc/llms.txt Configures the Expo plugin in app.json to set custom camera and microphone permissions for managed workflow projects. ```json { "name": "my-app", "plugins": [ [ "react-native-twilio-video-webrtc", { "cameraPermission": "Allow $(PRODUCT_NAME) to access your camera", "microphonePermission": "Allow $(PRODUCT_NAME) to access your microphone" } ] ] } ``` -------------------------------- ### Integrate TwilioPackage in MainApplication.java Source: https://github.com/blackuy/react-native-twilio-video-webrtc/blob/master/README.md Adds the `TwilioPackage` to your `MainApplication.java` file. This involves importing the package and including it in the `getPackages()` method, making the Twilio functionality available to your React Native application. ```java import com.twiliorn.library.TwilioPackage; protected List getPackages() { return Arrays.asList( ... new TwilioPackage() ); } ``` -------------------------------- ### Enable Java 8 Compatibility in Android Source: https://github.com/blackuy/react-native-twilio-video-webrtc/blob/master/README.md Configures your Android project to compile with Java 8 features. This is necessary for the library to function correctly. ```gradle android { compileOptions { sourceCompatibility 1.8 targetCompatibility 1.8 } } ``` -------------------------------- ### TwilioVideoPreview Component (Android) Source: https://github.com/blackuy/react-native-twilio-video-webrtc/blob/master/docs/README.md A component for displaying a local video preview on Android. ```APIDOC ## TwilioVideoPreview Component (Android) ### Description This component is used to display a local video preview on Android devices. ### Method N/A (Component Properties) ### Endpoint N/A (Component Properties) ### Parameters #### Properties - **scaleType** (enum('fit', 'fill')) - Optional - How the video stream should be scaled to fit its container. ### Request Example N/A ### Response N/A ``` -------------------------------- ### TwilioVideo Component Source: https://github.com/blackuy/react-native-twilio-video-webrtc/blob/master/docs/README.md The main component for managing Twilio video rooms, handling connections, and receiving various room and participant events. ```APIDOC ## TwilioVideo Component ### Description This component is used to manage Twilio video rooms. It handles room connections, disconnections, and various events related to participants and their tracks. ### Method N/A (Component Properties) ### Endpoint N/A (Component Properties) ### Parameters #### Properties - **screenShare** (boolean) - Optional - Flag that enables screen sharing RCTRootView instead of camera capture. - **onRoomDidConnect** (function) - Optional - Called when the room has connected. Parameters: `{roomName, participants, localParticipant}`. - **onRoomDidDisconnect** (function) - Optional - Called when the room has disconnected. Parameters: `{roomName, error}`. - **onRoomDidFailToConnect** (function) - Optional - Called when connection with room failed. Parameters: `{roomName, error}`. - **onRoomParticipantDidConnect** (function) - Optional - Called when a new participant has connected. Parameters: `{roomName, participant}`. - **onRoomParticipantDidDisconnect** (function) - Optional - Called when a participant has disconnected. Parameters: `{roomName, participant}`. - **onParticipantAddedVideoTrack** (function) - Optional - Called when a new video track has been added. Parameters: `{participant, track, enabled}`. - **onParticipantRemovedVideoTrack** (function) - Optional - Called when a video track has been removed. Parameters: `{participant, track}`. - **onParticipantAddedDataTrack** (function) - Optional - Called when a new data track has been added. Parameters: `{participant, track}`. - **onParticipantRemovedDataTrack** (function) - Optional - Called when a data track has been removed. Parameters: `{participant, track}`. - **onParticipantAddedAudioTrack** (function) - Optional - Called when a new audio track has been added. Parameters: `{participant, track}`. - **onParticipantRemovedAudioTrack** (function) - Optional - Called when an audio track has been removed. Parameters: `{participant, track}`. - **onParticipantEnabledVideoTrack** (function) - Optional - Called when a video track has been enabled. Parameters: `{participant, track}`. - **onParticipantDisabledVideoTrack** (function) - Optional - Called when a video track has been disabled. Parameters: `{participant, track}`. - **onParticipantEnabledAudioTrack** (function) - Optional - Called when an audio track has been enabled. Parameters: `{participant, track}`. - **onParticipantDisabledAudioTrack** (function) - Optional - Called when an audio track has been disabled. Parameters: `{participant, track}`. - **onDataTrackMessageReceived** (function) - Optional - Called when an dataTrack receives a message. Parameters: `{message, trackSid}`. - **onCameraDidStart** (function) - Optional - Called when the camera has started. - **onCameraWasInterrupted** (function) - Optional - Called when the camera has been interrupted. - **onCameraInterruptionEnded** (function) - Optional - Called when the camera interruption has ended. - **onCameraDidStopRunning** (function) - Optional - Called when the camera has stopped running with an error. Parameters: `{error}`. - **onStatsReceived** (function) - Optional - Called when stats are received (after calling getStats). - **onNetworkQualityLevelsChanged** (function) - Optional - Called when the network quality levels of a participant have changed (only if enableNetworkQualityReporting is set to True when connecting). - **onDominantSpeakerDidChange** (function) - Optional - Called when dominant speaker changes. Parameters: `{participant, room}`. - **onLocalParticipantSupportedCodecs** (function) - Optional - Always called on android with `{supportedCodecs}` after connecting to the room. ### Request Example N/A ### Response N/A ``` -------------------------------- ### Handle Twilio Video Room and Participant Events in React Native Source: https://context7.com/blackuy/react-native-twilio-video-webrtc/llms.txt This snippet demonstrates how to use various event callbacks provided by the TwilioVideo component to manage room connections, participant joins/leaves, and track status updates. It covers room connection/disconnection, participant events, and track enablement/disablement for video, audio, and data. It also includes camera events and network quality monitoring. ```jsx { console.log("Connected to room:", roomName); console.log("Room SID:", roomSid); console.log("Existing participants:", participants); console.log("Local participant:", localParticipant); }} onRoomDidDisconnect={({ roomName, roomSid, error }) => { console.log("Disconnected from room:", roomName); if (error) console.error("Disconnect error:", error); }} onRoomDidFailToConnect={({ roomName, error }) => { console.error("Failed to connect to room:", roomName, error); }} // Participant events onRoomParticipantDidConnect={({ roomName, roomSid, participant }) => { console.log("Participant joined:", participant.identity, participant.sid); }} onRoomParticipantDidDisconnect={({ roomName, roomSid, participant }) => { console.log("Participant left:", participant.identity); }} // Video track events onParticipantAddedVideoTrack={({ participant, track }) => { console.log("Video track added:", track.trackSid, "from:", participant.identity); }} onParticipantRemovedVideoTrack={({ participant, track }) => { console.log("Video track removed:", track.trackSid); }} onParticipantEnabledVideoTrack={({ participant, track }) => { console.log("Video track enabled:", track.trackSid); }} onParticipantDisabledVideoTrack={({ participant, track }) => { console.log("Video track disabled:", track.trackSid); }} // Audio track events onParticipantAddedAudioTrack={({ participant, track }) => { console.log("Audio track added from:", participant.identity); }} onParticipantRemovedAudioTrack={({ participant, track }) => { console.log("Audio track removed"); }} onParticipantEnabledAudioTrack={({ participant, track }) => { console.log("Participant unmuted:", participant.identity); }} onParticipantDisabledAudioTrack={({ participant, track }) => { console.log("Participant muted:", participant.identity); }} // Data track events onParticipantAddedDataTrack={({ participant, track }) => { console.log("Data track added from:", participant.identity); }} onParticipantRemovedDataTrack={({ participant, track }) => { console.log("Data track removed"); }} onDataTrackMessageReceived={({ message, trackSid }) => { console.log("Data message received:", message); }} // Camera events (iOS) onCameraDidStart={() => console.log("Camera started")} onCameraDidStopRunning={({ error }) => console.error("Camera stopped:", error)} onCameraWasInterrupted={() => console.log("Camera interrupted")} onCameraInterruptionEnded={() => console.log("Camera interruption ended")} // Network and speaker events onNetworkQualityLevelsChanged={({ participant, isLocalUser, quality }) => { // quality: 0 (unknown) to 5 (excellent) console.log(`Network quality for ${participant.identity}: ${quality}`); }} onDominantSpeakerDidChange={({ roomName, roomSid, participant }) => { console.log("Dominant speaker:", participant?.identity); }} // Stats onStatsReceived={(stats) => { console.log("Stats:", stats); }} // iOS only autoInitializeCamera={true} /> ``` -------------------------------- ### Configure Android Gradle Settings Source: https://github.com/blackuy/react-native-twilio-video-webrtc/blob/master/README.md Adds the react-native-twilio-video-webrtc library to your Android project's Gradle configuration. This involves updating `settings.gradle` to include the project and `android/app/build.gradle` to add it as a dependency. ```gradle include ':react-native-twilio-video-webrtc' project(':react-native-twilio-video-webrtc').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-twilio-video-webrtc/android') ``` ```gradle dependencies { ..... ..... ..... implementation project(':react-native-twilio-video-webrtc') } ``` -------------------------------- ### Enable Jumbo Mode for Android Builds Source: https://github.com/blackuy/react-native-twilio-video-webrtc/blob/master/README.md Enables jumbo mode in your `app/build.gradle` file to resolve `DexIndexOverflowException`. This option increases the number of methods that can be included in a single DEX file, which can be necessary for larger projects. ```gradle android { ... dexOptions { jumboMode true } } ``` -------------------------------- ### Configure Proguard Rules for Twilio Library Source: https://github.com/blackuy/react-native-twilio-video-webrtc/blob/master/README.md Adds Proguard rules to `proguard-rules.pro` to prevent the stripping of necessary Twilio library symbols. This ensures that the library functions correctly when code shrinking is enabled. ```proguard -keep class com.twilio.** { *; } -keep class tvi.webrtc.** { *; } ``` -------------------------------- ### Display Local Video Preview with TwilioVideoLocalView Source: https://context7.com/blackuy/react-native-twilio-video-webrtc/llms.txt A React Native component for rendering the local user's camera preview. The `enabled` prop controls its visibility. It supports custom styling and can be configured with different `scaleType` options ('fit' or 'fill'). ```jsx import React, { useState } from 'react'; import { TwilioVideoLocalView } from 'react-native-twilio-video-webrtc'; const LocalVideo = () => { const [showLocalVideo, setShowLocalVideo] = useState(true); return ( <> {/* Example of conditional rendering */}