3232#include < vector>
3333
3434#include " livekit/livekit.h"
35- #include " livekit_ffi.h" // same as simple_room; internal but used here
35+ #include " livekit_ffi.h"
3636
3737using namespace livekit ;
3838using namespace std ::chrono_literals;
3939
4040namespace {
4141
42- // ------------------------------------------------------------
43- // Global control (same pattern as simple_room)
44- // ------------------------------------------------------------
45-
4642std::atomic<bool > g_running{true };
4743
4844void handleSignal (int ) { g_running.store (false ); }
@@ -91,38 +87,31 @@ bool ensurePeerPresent(Room &room, const std::string &identity,
9187 std::cout << " [Caller] Waiting up to " << timeout.count () << " s for "
9288 << friendly_role << " (identity=\" " << identity
9389 << " \" ) to join...\n " ;
94-
9590 bool present = waitForParticipant (
9691 room, identity,
9792 std::chrono::duration_cast<std::chrono::milliseconds>(timeout));
98-
9993 if (present) {
10094 std::cout << " [Caller] " << friendly_role << " is present.\n " ;
10195 return true ;
10296 }
103-
10497 // Timed out
10598 auto info = room.room_info ();
10699 const std::string room_name = info.name ;
107-
108100 std::cout << " [Caller] Timed out after " << timeout.count ()
109101 << " s waiting for " << friendly_role << " (identity=\" " << identity
110102 << " \" ).\n " ;
111103 std::cout << " [Caller] No participant with identity \" " << identity
112104 << " \" appears to be connected to room \" " << room_name
113105 << " \" .\n\n " ;
114-
115106 std::cout << " To start a " << friendly_role
116107 << " in another terminal, run:\n\n "
117108 << " lk token create -r test -i " << identity
118109 << " --join --valid-for 99999h --dev --room=" << room_name << " \n "
119110 << " ./build/examples/SimpleRpc " << url
120111 << " $token --role=" << friendly_role << " \n\n " ;
121-
122112 return false ;
123113}
124114
125- // Parse args similar to simple_room, plus optional --role / role positional
126115bool parseArgs (int argc, char *argv[], std::string &url, std::string &token,
127116 std::string &role) {
128117 // --help
@@ -206,26 +195,18 @@ bool parseArgs(int argc, char *argv[], std::string &url, std::string &token,
206195 return !(url.empty () || token.empty ());
207196}
208197
209- // ------------------------------------------------------------
210- // Tiny helpers for the simple JSON used in the sample
211- // (to avoid bringing in a json library)
212- // ------------------------------------------------------------
213-
214- // create {"key":number}
215198std::string makeNumberJson (const std::string &key, double value) {
216199 std::ostringstream oss;
217200 oss << " {\" " << key << " \" :" << value << " }" ;
218201 return oss.str ();
219202}
220203
221- // create {"key":"value"}
222204std::string makeStringJson (const std::string &key, const std::string &value) {
223205 std::ostringstream oss;
224206 oss << " {\" " << key << " \" :\" " << value << " \" }" ;
225207 return oss.str ();
226208}
227209
228- // very naive parse of {"key":number}
229210double parseNumberFromJson (const std::string &json) {
230211 auto colon = json.find (' :' );
231212 if (colon == std::string::npos)
@@ -236,7 +217,6 @@ double parseNumberFromJson(const std::string &json) {
236217 return std::stod (num_str);
237218}
238219
239- // very naive parse of {"key":"value"}
240220std::string parseStringFromJson (const std::string &json) {
241221 auto colon = json.find (' :' );
242222 if (colon == std::string::npos)
@@ -250,10 +230,7 @@ std::string parseStringFromJson(const std::string &json) {
250230 return json.substr (first_quote + 1 , second_quote - first_quote - 1 );
251231}
252232
253- // ------------------------------------------------------------
254- // RPC handler registration (for greeter & math-genius)
255- // ------------------------------------------------------------
256-
233+ // RPC handler registration
257234void registerReceiverMethods (Room &greeters_room, Room &math_genius_room) {
258235 LocalParticipant *greeter_lp = greeters_room.local_participant ();
259236 LocalParticipant *math_genius_lp = math_genius_room.local_participant ();
@@ -321,19 +298,15 @@ void registerReceiverMethods(Room &greeters_room, Room &math_genius_room) {
321298 std::cout << " [Math Genius] This will take 30 seconds even though "
322299 " you're only giving me "
323300 << data.response_timeout_sec << " seconds\n " ;
324-
301+ // Sleep for 30 seconds to mimic a long running task.
325302 std::this_thread::sleep_for (30s);
326303 return makeStringJson (" result" , " Calculation complete!" );
327304 });
328305
329306 // Note: we do NOT register "quantum-hypergeometric-series" here,
330- // so the caller sees UNSUPPORTED_METHOD, just like in Python.
307+ // so the caller sees UNSUPPORTED_METHOD
331308}
332309
333- // ------------------------------------------------------------
334- // Caller-side helpers (like perform_* in rpc.py)
335- // ------------------------------------------------------------
336-
337310void performGreeting (Room &room) {
338311 std::cout << " [Caller] Letting the greeter know that I've arrived\n " ;
339312 double t0 = nowMs ();
@@ -460,10 +433,6 @@ void performLongCalculation(Room &room) {
460433
461434} // namespace
462435
463- // ------------------------------------------------------------
464- // main – similar style to simple_room/main.cpp
465- // ------------------------------------------------------------
466-
467436int main (int argc, char *argv[]) {
468437 std::string url, token, role;
469438 if (!parseArgs (argc, argv, url, token, role)) {
@@ -479,7 +448,7 @@ int main(int argc, char *argv[]) {
479448 std::cout << " Connecting to: " << url << " \n " ;
480449 std::cout << " Role: " << role << " \n " ;
481450
482- // Ctrl-C
451+ // Ctrl-C to quit the program
483452 std::signal (SIGINT, handleSignal);
484453
485454 Room room{};
0 commit comments