Skip to content
Open
Changes from 1 commit
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
81 changes: 80 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,86 @@ 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, [host an agent manually](https://docs.livekit.io/agents/start/voice-ai/) or via [LiveKit Cloud Agents](https://docs.livekit.io/agents/ops/deployment/), and give it the name "example agent"

Then, you can use the agents sdk to connect and talk 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