Skip to content

Commit 4163172

Browse files
RPC features
1 parent 1319391 commit 4163172

File tree

14 files changed

+1116
-17
lines changed

14 files changed

+1116
-17
lines changed

CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ add_library(livekit
169169
include/livekit/local_participant.h
170170
include/livekit/remote_participant.h
171171
include/livekit/livekit.h
172+
include/livekit/rpc_error.h
172173
include/livekit/stats.h
173174
include/livekit/track.h
174175
include/livekit/track_publication.h
@@ -198,6 +199,7 @@ add_library(livekit
198199
src/track_publication.cpp
199200
src/local_track_publication.cpp
200201
src/remote_track_publication.cpp
202+
src/rpc_error.cpp
201203
src/video_frame.cpp
202204
src/video_source.cpp
203205
src/video_stream.cpp

README.md

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,16 @@ All build actions are managed by the provided build.sh script.
4141

4242
## 🧪 Run Example
4343

44+
### Generate Tokens
45+
Before running any participant, create JWT tokens with the proper identity and room name, example
4446
```bash
45-
./build/examples/SimpleRoom --url ws://localhost:7880 --token <jwt-token>
47+
lk token create -r test -i your_own_identity --join --valid-for 99999h --dev --room=your_own_room
48+
```
49+
50+
### SimpleRoom
51+
52+
```bash
53+
./build/examples/SimpleRoom --url $URL --token <jwt-token>
4654
```
4755

4856
You can also provide the URL and token via environment variables:
@@ -54,6 +62,33 @@ export LIVEKIT_TOKEN=<jwt-token>
5462

5563
Press Ctrl-C to exit the example.
5664

65+
### SimpleRpc
66+
The SimpleRpc example demonstrates how to:
67+
- Connect multiple participants to the same LiveKit room
68+
- Register RPC handlers (e.g., arrival, square-root, divide, long-calculation)
69+
- Send RPC requests from one participant to another
70+
- Handle success, application errors, unsupported methods, and timeouts
71+
- Observe round-trip times (RTT) for each RPC call
72+
73+
#### 🔑 Generate Tokens
74+
Before running any participant, create JWT tokens with "caller", "greeter" and "math-genius" identities and room name.
75+
```bash
76+
lk token create -r test -i caller --join --valid-for 99999h --dev --room=your_own_room
77+
lk token create -r test -i greeter --join --valid-for 99999h --dev --room=your_own_room
78+
lk token create -r test -i math-genius --join --valid-for 99999h --dev --room=your_own_room
79+
```
80+
81+
#### ▶ Start Participants
82+
Every participant is run as a separate terminal process, note --role needs to match the token identity.
83+
```bash
84+
./build/examples/SimpleRpc --url $URL --token <jwt-token> --role=math-genius
85+
```
86+
The caller will automatically:
87+
- Wait for the greeter and math-genius to join
88+
- Perform RPC calls
89+
- Print round-trip times
90+
- Annotate expected successes or expected failures
91+
5792
## 🧰 Recommended Setup
5893
### macOS
5994
```bash

examples/CMakeLists.txt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ project (livekit-examples)
44
set(CMAKE_CXX_STANDARD 17)
55
set(CMAKE_CXX_STANDARD_REQUIRED ON)
66

7+
#################### SimpleRoom example ##########################
8+
79
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
810
include(sdl3)
911

@@ -32,3 +34,22 @@ add_custom_command(TARGET SimpleRoom POST_BUILD
3234
${CMAKE_SOURCE_DIR}/data
3335
${CMAKE_CURRENT_BINARY_DIR}/data
3436
)
37+
38+
#################### SimpleRpc example ##########################
39+
40+
include(FetchContent)
41+
FetchContent_Declare(
42+
nlohmann_json
43+
URL https://github.com/nlohmann/json/releases/download/v3.11.3/json.tar.xz
44+
)
45+
FetchContent_MakeAvailable(nlohmann_json)
46+
47+
add_executable(SimpleRpc
48+
simple_rpc/main.cpp
49+
)
50+
51+
target_link_libraries(SimpleRpc
52+
PRIVATE
53+
nlohmann_json::nlohmann_json
54+
livekit
55+
)

examples/simple_room/main.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ namespace {
4242

4343
std::atomic<bool> g_running{true};
4444

45-
void print_usage(const char *prog) {
45+
void printUsage(const char *prog) {
4646
std::cerr << "Usage:\n"
4747
<< " " << prog << " <ws-url> <token>\n"
4848
<< "or:\n"
@@ -52,9 +52,9 @@ void print_usage(const char *prog) {
5252
<< " LIVEKIT_URL, LIVEKIT_TOKEN\n";
5353
}
5454

55-
void handle_sigint(int) { g_running.store(false); }
55+
void handleSignal(int) { g_running.store(false); }
5656

57-
bool parse_args(int argc, char *argv[], std::string &url, std::string &token) {
57+
bool parseArgs(int argc, char *argv[], std::string &url, std::string &token) {
5858
// 1) --help
5959
for (int i = 1; i < argc; ++i) {
6060
std::string a = argv[i];
@@ -215,8 +215,8 @@ class SimpleRoomDelegate : public livekit::RoomDelegate {
215215

216216
int main(int argc, char *argv[]) {
217217
std::string url, token;
218-
if (!parse_args(argc, argv, url, token)) {
219-
print_usage(argv[0]);
218+
if (!parseArgs(argc, argv, url, token)) {
219+
printUsage(argv[0]);
220220
return 1;
221221
}
222222

@@ -238,7 +238,7 @@ int main(int argc, char *argv[]) {
238238
std::cout << "Connecting to: " << url << std::endl;
239239

240240
// Handle Ctrl-C to exit the idle loop
241-
std::signal(SIGINT, handle_sigint);
241+
std::signal(SIGINT, handleSignal);
242242

243243
livekit::Room room{};
244244
SimpleRoomDelegate delegate(media);

0 commit comments

Comments
 (0)