Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 82 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,88 @@ Use this SDK to add realtime video, audio and data features to your React app. B

![LiveKit Components Preview](./.github/assets/livekit-meet.jpg)

## Quick Start
## Agents Quick Start

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Idea: by looking at the doc today, it seems Video Conference Quick Start is under Agent SDK Example, while I think they should be separate sections.

Does it make sense to have 1, 2 to distinguish the session that they are for different use cases like

1. Agent SDK Example

2. Video Conference Quick Start


First add the library to your project:

```shell
npm i @livekit/components-react
```

Next, you need a running agent. If you don't already have one, [it only takes a few minutes to set one up](https://docs.livekit.io/agents/start/voice-ai).

The rest of this guide assumes your agent is configured for [explicit dispatch](https://docs.livekit.io/agents/worker/agent-dispatch/#explicit) with `agent_name="example-agent"`.

Then, you can use the agents sdk to connect and interact with your agent:

```tsx
import { useEffect, useState } from "react";
import { TokenSource } from "livekit-client";
import {
useSession,
useAgent,
SessionProvider,
VideoTrack,
StartAudio,
RoomAudioRenderer,
} from "@livekit/components-react";

// Generated credentials manually and put them here
// Or, generate them another way: FIXME: add docs link here!
Comment on lines +50 to +51
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is another place the eventual TokenSource docs from here should be linked: livekit/client-sdk-js#1681

const tokenSource = TokenSource.literal({
serverUrl: "wss://my-livekit-server",
participantToken: 'generated-jwt',
});

export default function Example() {
const session = useSession(tokenSource, {
agentName: 'example-agent', /* <== Put your agent name here! */
});

const toggleStarted = () => {
if (session.connectionState === 'disconnected') {
session.start();
} else {
session.end();
}
};

const agent = useAgent(session);

return (
<SessionProvider session={session}>
<button onClick={toggleStarted} disabled={session.connectionState === 'connecting'}>
{session.isConnected ? 'Disconnect' : 'Connect'}
</button>

{session.isConnected ? (
<div className="flex flex-col gap-4 p-4">
<span>
<strong>Connection State:</strong>
{session.connectionState}
</span>
<span>
<strong>Agent State:</strong>
{agent.state}
</span>

{session.local.cameraTrack ? (
<VideoTrack trackRef={session.local.cameraTrack} />
) : null}
{agent.cameraTrack ? (
<VideoTrack trackRef={agent.cameraTrack} />
) : null}

<StartAudio label="Start audio" />
<RoomAudioRenderer />
</div>
) : null}
</SessionProvider>
);
}
```

### Video Conference Quick Start

First add the library to your project:

Expand Down