Voice AI quickstart
To build your first voice AI app for Next.js, use the following quickstart and the starter app. Otherwise follow the getting started guide below.
Voice AI quickstart
Next.js Voice Agent
Getting started guide
This guide walks you through the steps to build a video-conferencing application using React. It uses the LiveKit React components library to render the UI and communicate with LiveKit servers via WebRTC. By the end, you will have a basic video-conferencing application you can run with multiple participants.
Install LiveKit SDK
Install the LiveKit SDK:
yarn add @livekit/components-react @livekit/components-styles livekit-client
Join a room
Update the serverUrl
and token
values and copy and paste the following into your src/App.tsx
file. To generate a token for this example, see Creating a token.
This example hardcodes a token. In a real app, your server generates a token for you.
import {ControlBar,GridLayout,ParticipantTile,RoomAudioRenderer,useTracks,RoomContext,} from '@livekit/components-react';import { Room, Track } from 'livekit-client';import '@livekit/components-styles';import { useState } from 'react';const serverUrl = '<your LiveKit server URL>';const token = '<generate a token>';export default function App() {const [room] = useState(() => new Room({// Optimize video quality for each participant's screenadaptiveStream: true,// Enable automatic audio/video quality optimizationdynacast: true,}));// Connect to roomuseEffect(() => {let mounted = true;const connect = async () => {if (mounted) {await room.connect(serverUrl, token);}};connect();return () => {mounted = false;room.disconnect();};}, [room]);return (<RoomContext.Provider value={room}><div data-lk-theme="default" style={{ height: '100vh' }}>{/* Your custom component with basic video conferencing functionality. */}<MyVideoConference />{/* The RoomAudioRenderer takes care of room-wide audio for you. */}<RoomAudioRenderer />{/* Controls for the user to start/stop audio, video, and screen share tracks */}<ControlBar /></div></RoomContext.Provider>);}function MyVideoConference() {// `useTracks` returns all camera and screen share tracks. If a user// joins without a published camera track, a placeholder track is returned.const tracks = useTracks([{ source: Track.Source.Camera, withPlaceholder: true },{ source: Track.Source.ScreenShare, withPlaceholder: false },],{ onlySubscribed: false },);return (<GridLayout tracks={tracks} style={{ height: 'calc(100vh - var(--lk-control-bar-height))' }}>{/* The GridLayout accepts zero or one child. The child is usedas a template to render all passed in tracks. */}<ParticipantTile /></GridLayout>);}
Next steps
The following resources are useful for getting started with LiveKit on React.
Generating tokens
Guide to generating authentication tokens for your users.
Realtime media
Complete documentation for live video and audio tracks.
Realtime data
Send and receive realtime data between clients.
JavaScript SDK
LiveKit JavaScript SDK on GitHub.
React components
LiveKit React components on GitHub.
JavaScript SDK reference
LiveKit JavaScript SDK reference docs.
React components reference
LiveKit React components reference docs.