Skip to content
Merged
Show file tree
Hide file tree
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
37 changes: 32 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Use this SDK to add realtime video, audio and data features to your ESP32 projec
- **Bidirectional audio**: Opus encoding, acoustic echo cancellation (AEC)
- **Video publishing**: H.264 encoding, subscribing coming soon
- **AI Agents**: interact with agents in the cloud built with [LiveKit Agents](https://docs.livekit.io/agents/)
- **Real-time data**: data streams (receiving), data packets, remote method calls (RPC)
- **Real-time data**: data streams, data packets, remote method calls (RPC)

## Getting Started

Expand Down Expand Up @@ -173,17 +173,16 @@ livekit_room_rpc_register(room_handle, "get_cpu_temp", get_cpu_temp);

#### Data streams

Data streams deliver ordered sequences of chunks (Header → Chunks → Trailer) over the reliable data channel. Currently, only receiving data streams is supported. There are two kinds:
Data streams deliver ordered sequences of chunks (Header → Chunks → Trailer) over the reliable data channel. There are two kinds:

- **Text streams**: Each chunk is independently valid UTF-8 and can be used directly as a string. Used for chat messages, transcriptions, etc.
- **Text streams**: Each chunk is independently valid UTF-8 and can be used directly as a string. When sending, data is automatically chunked at UTF-8 character boundaries so multi-byte characters are never split. Used for chat messages, transcriptions, etc.
- **Byte streams**: Chunks are raw binary fragments of a larger payload, split without delimiters. Chunks must be aggregated by the application to reconstruct the original data. Used for file transfers, binary payloads, etc.

Register a handler to receive text stream chunks on a topic:
**Receiving** — register a handler for a topic:

```c
static void on_text_chunk(const livekit_data_stream_chunk_t* chunk, void* ctx)
{
// Each chunk is valid UTF-8, safe to use as a string directly
ESP_LOGI(TAG, "%.*s", (int)chunk->content_size, (const char*)chunk->content);
}

Expand All @@ -195,6 +194,34 @@ livekit_room_data_stream_topic_register(room_handle, "lk.chat", &handler);

The optional `on_open` and `on_close` callbacks in the handler can be set for additional behavior such as logging stream metadata or detecting abnormal closure.

**Sending a text stream:**

```c
livekit_data_stream_options_t opts = { .topic = "lk.chat", .is_text = true };
livekit_data_stream_handle_t stream;
livekit_room_data_stream_open(room_handle, &opts, &stream);
livekit_room_data_stream_write(room_handle, stream, (const uint8_t*)"hello world", 11);
livekit_room_data_stream_close(room_handle, stream);
```

**Sending a byte stream:**

```c
uint8_t image_data[4096];
size_t image_size = read_image(image_data, sizeof(image_data));

livekit_data_stream_options_t opts = {
.topic = "image",
.is_text = false,
.total_length = image_size,
.has_total_length = true,
};
livekit_data_stream_handle_t stream;
livekit_room_data_stream_open(room_handle, &opts, &stream);
livekit_room_data_stream_write(room_handle, stream, image_data, image_size);
livekit_room_data_stream_close(room_handle, stream);
```

#### User packets

Publish a user packet containing a raw data payload under a specific topic:
Expand Down
6 changes: 5 additions & 1 deletion components/livekit/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,12 @@ menu "LiveKit"
config LK_PUB_VIDEO_TRACK_NAME
string "Name of the published video track"
default "Video"
config LK_MAX_DATA_STREAMS
config LK_MAX_DATA_STREAM_READERS
int "Maximum concurrent incoming data streams"
range 1 32
default 4
config LK_MAX_DATA_STREAM_WRITERS
int "Maximum concurrent outgoing data streams"
range 1 32
default 4
endmenu
2 changes: 1 addition & 1 deletion components/livekit/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ Use this SDK to add realtime video, audio and data features to your ESP32 projec
- **Bidirectional audio**: Opus encoding, acoustic echo cancellation (AEC)
- **Video publishing**: H.264 encoding, subscribing coming soon
- **AI Agents**: interact with agents in the cloud built with [LiveKit Agents](https://docs.livekit.io/agents/)
- **Real-time data**: data packets, remote method calls (RPC)
- **Real-time data**: data streams, data packets, remote method calls (RPC)
58 changes: 0 additions & 58 deletions components/livekit/core/data_stream_manager.h

This file was deleted.

Loading
Loading