### Install LiveKit Expo Dependencies and Run Project
Source: https://context7.com/livekit-examples/react-native-expo-quickstart/llms.txt
This bash script outlines the commands to install the core LiveKit packages, Expo-specific plugins, and the Expo dev client. It also includes instructions for starting the development server and running the app on Android and iOS devices.
```bash
# Install core dependencies
npm install @livekit/react-native @livekit/react-native-webrtc livekit-client
# Install Expo-specific plugins
npm install @livekit/react-native-expo-plugin @config-plugins/react-native-webrtc
# Install Expo dev client for native module support
npm install expo-dev-client
# Start development server
npx expo start
# Run on device (in separate terminal)
npx expo run:android # For Android
npx expo run:ios # For iOS
```
--------------------------------
### Initialize LiveKitRoom and Audio Session in React Native Expo
Source: https://context7.com/livekit-examples/react-native-expo-quickstart/llms.txt
Demonstrates the setup of the `LiveKitRoom` component to manage the LiveKit server connection and session lifecycle. It also includes the essential `AudioSession.startAudioSession()` call required before connecting to ensure proper audio handling in the React Native environment. The `registerGlobals()` function must be called once before using any LiveKit components.
```tsx
import { LiveKitRoom, AudioSession, registerGlobals } from '@livekit/react-native';
import { useEffect } from 'react';
// Required: Register LiveKit globals before using any LiveKit components
registerGlobals();
export default function App() {
// Start audio session before connecting
useEffect(() => {
const start = async () => {
await AudioSession.startAudioSession();
};
start();
return () => {
AudioSession.stopAudioSession();
};
}, []);
return (
);
}
```
--------------------------------
### Manage Audio Session Lifecycle in React Native Expo
Source: https://context7.com/livekit-examples/react-native-expo-quickstart/llms.txt
The AudioSession API manages the audio session, ensuring correct audio routing and handling on iOS and Android. It must be started before connecting to a room and stopped when leaving. This snippet demonstrates starting and stopping the audio session with a button.
```tsx
import { AudioSession } from '@livekit/react-native';
import { useEffect, useState } from 'react';
import { Button, View } from 'react-native';
const AudioManager = () => {
const [isAudioActive, setIsAudioActive] = useState(false);
const startAudio = async () => {
try {
await AudioSession.startAudioSession();
setIsAudioActive(true);
} catch (error) {
console.error('Failed to start audio session:', error);
}
};
const stopAudio = async () => {
try {
await AudioSession.stopAudioSession();
setIsAudioActive(false);
} catch (error) {
console.error('Failed to stop audio session:', error);
}
};
// Auto-start on mount
useEffect(() => {
startAudio();
return () => {
stopAudio();
};
}, []);
return (
);
};
```
--------------------------------
### Configure Expo Project for LiveKit
Source: https://context7.com/livekit-examples/react-native-expo-quickstart/llms.txt
This JSON configuration is for the Expo project's `app.json` or `app.config.js`. It includes necessary plugins for LiveKit and WebRTC integration, and specifies Android permissions required for real-time communication features.
```json
{
"expo": {
"name": "my-livekit-app",
"plugins": [
"@livekit/react-native-expo-plugin",
"@config-plugins/react-native-webrtc"
],
"android": {
"permissions": [
"android.permission.CAMERA",
"android.permission.RECORD_AUDIO",
"android.permission.INTERNET",
"android.permission.ACCESS_NETWORK_STATE",
"android.permission.BLUETOOTH",
"android.permission.MODIFY_AUDIO_SETTINGS",
"android.permission.WAKE_LOCK"
]
},
"ios": {
"bitcode": false
}
}
}
```
--------------------------------
### Retrieve and Render Participant Tracks with useTracks in React Native
Source: https://context7.com/livekit-examples/react-native-expo-quickstart/llms.txt
Illustrates how to use the `useTracks` hook to fetch and display video and audio tracks from participants in a LiveKit room. It shows filtering tracks by `Track.Source` (e.g., Camera, Microphone) and rendering them using `VideoTrack` or placeholder views. The hook returns an array of `TrackReferenceOrPlaceholder` which needs to be checked with `isTrackReference` before rendering.
```tsx
import { useTracks, TrackReferenceOrPlaceholder, VideoTrack, isTrackReference } from '@livekit/react-native';
import { Track } from 'livekit-client';
import { FlatList, View, StyleSheet } from 'react-native';
const RoomView = () => {
// Get all camera tracks from all participants
const cameraTracks = useTracks([Track.Source.Camera]);
// Get microphone tracks
const microphoneTracks = useTracks([Track.Source.Microphone]);
// Get screen share tracks
const screenTracks = useTracks([Track.Source.ScreenShare]);
const renderTrack = ({ item }: { item: TrackReferenceOrPlaceholder }) => {
if (isTrackReference(item)) {
return (
);
}
return ;
};
return (
`track-${index}`}
/>
);
};
const styles = StyleSheet.create({
video: { width: '100%', height: 300 },
placeholder: { width: '100%', height: 300, backgroundColor: '#333' }
});
```
--------------------------------
### Render Participant Video Feed with VideoTrack Component in React Native
Source: https://context7.com/livekit-examples/react-native-expo-quickstart/llms.txt
Shows how to use the `VideoTrack` component to display a participant's video stream in a React Native application. This component handles rendering and scaling of the video feed and supports optional mirroring for local participant's video. It also includes logic to display a placeholder if no video is available and shows the participant's identity.
```tsx
import { VideoTrack, isTrackReference, TrackReferenceOrPlaceholder } from '@livekit/react-native';
import { View, Text, StyleSheet } from 'react-native';
const ParticipantView = ({ trackRef }: { trackRef: TrackReferenceOrPlaceholder }) => {
if (!isTrackReference(trackRef)) {
return (
No video available
);
}
return (
{trackRef.participant.identity}
);
};
const styles = StyleSheet.create({
container: { position: 'relative', width: '100%', height: 300 },
video: { width: '100%', height: '100%' },
participantName: {
position: 'absolute',
bottom: 10,
left: 10,
color: 'white',
backgroundColor: 'rgba(0,0,0,0.5)',
padding: 5,
borderRadius: 4
},
emptyView: {
width: '100%',
height: 300,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#1a1a1a'
}
});
```
=== COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.