Skip to content
Open
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
2 changes: 0 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,6 @@ add_subdirectory(logging_levels/basic_usage logging_levels_basic_usage)
add_subdirectory(logging_levels/custom_sinks logging_levels_custom_sinks)
add_subdirectory(hello_livekit/sender hello_livekit_sender)
add_subdirectory(hello_livekit/receiver hello_livekit_receiver)
add_subdirectory(simple_joystick/sender simple_joystick_sender)
add_subdirectory(simple_joystick/receiver simple_joystick_receiver)
add_subdirectory(ping_pong/ping ping_pong_ping)
add_subdirectory(ping_pong/pong ping_pong_pong)
add_subdirectory(user_timestamped_video)
14 changes: 10 additions & 4 deletions basic_room/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,9 @@ int main(int argc, char* argv[]) {

std::shared_ptr<LocalTrackPublication> audioPub;
try {
room->localParticipant()->publishTrack(audioTrack, audioOpts);
auto lp = room->localParticipant().lock();
if (!lp) throw std::runtime_error("local participant unavailable");
lp->publishTrack(audioTrack, audioOpts);
audioPub = audioTrack->publication();
std::cout << "Published audio: sid=" << audioPub->sid() << "\n";
} catch (const std::exception& e) {
Expand All @@ -151,7 +153,9 @@ int main(int argc, char* argv[]) {

std::shared_ptr<LocalTrackPublication> videoPub;
try {
room->localParticipant()->publishTrack(videoTrack, videoOpts);
auto lp = room->localParticipant().lock();
if (!lp) throw std::runtime_error("local participant unavailable");
lp->publishTrack(videoTrack, videoOpts);
videoPub = videoTrack->publication();
std::cout << "Published video: sid=" << videoPub->sid() << "\n";
} catch (const std::exception& e) {
Expand Down Expand Up @@ -179,8 +183,10 @@ int main(int argc, char* argv[]) {

// Best-effort unpublish
try {
if (audioPub) room->localParticipant()->unpublishTrack(audioPub->sid());
if (videoPub) room->localParticipant()->unpublishTrack(videoPub->sid());
if (auto lp = room->localParticipant().lock()) {
if (audioPub) lp->unpublishTrack(audioPub->sid());
if (videoPub) lp->unpublishTrack(videoPub->sid());
}
} catch (...) {
}

Expand Down
8 changes: 5 additions & 3 deletions hello_livekit/receiver/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@
/// LIVEKIT_URL, LIVEKIT_RECEIVER_TOKEN, LIVEKIT_SENDER_IDENTITY

#include <atomic>
#include <cassert>
#include <chrono>
#include <csignal>
#include <cstdlib>
#include <iostream>
#include <stdexcept>
#include <thread>

#include "livekit/livekit.h"
Expand Down Expand Up @@ -83,8 +83,10 @@ int main(int argc, char* argv[]) {
return 1;
}

LocalParticipant* lp = room->localParticipant();
assert(lp);
auto lp = room->localParticipant().lock();
if (!lp) {
throw std::runtime_error("[receiver] local participant is null");
}

std::cout << "[info] [receiver] Connected as identity='" << lp->identity() << "' room='" << room->roomInfo().name
<< "'; subscribing to sender identity='" << sender_identity << "'\n";
Expand Down
40 changes: 23 additions & 17 deletions hello_livekit/sender/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@
/// LIVEKIT_URL, LIVEKIT_SENDER_TOKEN

#include <atomic>
#include <cassert>
#include <chrono>
#include <csignal>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <sstream>
#include <stdexcept>
#include <thread>

#include "livekit/livekit.h"
Expand Down Expand Up @@ -84,27 +84,33 @@ int main(int argc, char* argv[]) {
return 1;
}

LocalParticipant* lp = room->localParticipant();
assert(lp);
std::shared_ptr<LocalDataTrack> data_track;
std::shared_ptr<LocalVideoTrack> video_track;
std::shared_ptr<VideoSource> video_source;
{
auto lp = room->localParticipant().lock();
if (!lp) {
throw std::runtime_error("[sender] local participant is null");
}

std::cout << "[info] [sender] Connected as identity='" << lp->identity() << "' room='" << room->roomInfo().name
<< "' — pass this identity to HelloLivekitReceiver\n";
std::cout << "[info] [sender] Connected as identity='" << lp->identity() << "' room='" << room->roomInfo().name
<< "' — pass this identity to HelloLivekitReceiver\n";

auto video_source = std::make_shared<VideoSource>(kWidth, kHeight);
video_source = std::make_shared<VideoSource>(kWidth, kHeight);

std::shared_ptr<LocalVideoTrack> video_track =
lp->publishVideoTrack(kVideoTrackName, video_source, TrackSource::SOURCE_CAMERA);
video_track = lp->publishVideoTrack(kVideoTrackName, video_source, TrackSource::SOURCE_CAMERA);

auto publish_result = lp->publishDataTrack(kDataTrackName);
if (!publish_result) {
const auto& error = publish_result.error();
std::cerr << "[error] Failed to publish data track: code=" << static_cast<std::uint32_t>(error.code)
<< " message=" << error.message << "\n";
room.reset();
livekit::shutdown();
return 1;
auto publish_result = lp->publishDataTrack(kDataTrackName);
if (!publish_result) {
const auto& error = publish_result.error();
std::cerr << "[error] Failed to publish data track: code=" << static_cast<std::uint32_t>(error.code)
<< " message=" << error.message << "\n";
room.reset();
livekit::shutdown();
return 1;
}
data_track = publish_result.value();
}
std::shared_ptr<LocalDataTrack> data_track = publish_result.value();

const auto t0 = std::chrono::steady_clock::now();
std::uint64_t count = 0;
Expand Down
35 changes: 20 additions & 15 deletions ping_pong/ping/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@
/// identity is `ping`.

#include <atomic>
#include <cassert>
#include <csignal>
#include <cstdint>
#include <exception>
#include <iostream>
#include <memory>
#include <mutex>
#include <optional>
#include <stdexcept>
#include <string>
#include <thread>
#include <unordered_map>
Expand Down Expand Up @@ -98,24 +98,29 @@ int main(int argc, char* argv[]) {
return 1;
}

LocalParticipant* local_participant = room->localParticipant();
assert(local_participant);
std::shared_ptr<LocalDataTrack> ping_track;
{
auto local_participant = room->localParticipant().lock();
if (!local_participant) {
throw std::runtime_error("[ping] local participant is null");
}

std::cout << "[info] ping connected as identity='" << local_participant->identity() << "' room='"
<< room->roomInfo().name << "'\n";
std::cout << "[info] ping connected as identity='" << local_participant->identity() << "' room='"
<< room->roomInfo().name << "'\n";

auto publish_result = local_participant->publishDataTrack(ping_pong::kPingTrackName);
if (!publish_result) {
const auto& error = publish_result.error();
std::cerr << "[error] Failed to publish ping data track: code=" << static_cast<std::uint32_t>(error.code)
<< " message=" << error.message << "\n";
room->setDelegate(nullptr);
room.reset();
livekit::shutdown();
return 1;
auto publish_result = local_participant->publishDataTrack(ping_pong::kPingTrackName);
if (!publish_result) {
const auto& error = publish_result.error();
std::cerr << "[error] Failed to publish ping data track: code=" << static_cast<std::uint32_t>(error.code)
<< " message=" << error.message << "\n";
room->setDelegate(nullptr);
room.reset();
livekit::shutdown();
return 1;
}
ping_track = publish_result.value();
}

std::shared_ptr<LocalDataTrack> ping_track = publish_result.value();
std::unordered_map<std::uint64_t, ping_pong::PingMessage> sent_messages;
std::mutex sent_messages_mutex;

Expand Down
41 changes: 23 additions & 18 deletions ping_pong/pong/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@
/// on the "pong" data track. Use a token whose identity is `pong`.

#include <atomic>
#include <cassert>
#include <csignal>
#include <cstdint>
#include <exception>
#include <iostream>
#include <memory>
#include <optional>
#include <stdexcept>
#include <string>
#include <thread>
#include <vector>
Expand Down Expand Up @@ -77,25 +77,30 @@ int main(int argc, char* argv[]) {
return 1;
}

LocalParticipant* local_participant = room->localParticipant();
assert(local_participant);

std::cout << "[info] pong connected as identity='" << local_participant->identity() << "' room='"
<< room->roomInfo().name << "'\n";

auto publish_result = local_participant->publishDataTrack(ping_pong::kPongTrackName);
if (!publish_result) {
const auto& error = publish_result.error();
std::cerr << "[error] Failed to publish pong data track: code=" << static_cast<std::uint32_t>(error.code)
<< " message=" << error.message << "\n";
room->setDelegate(nullptr);
room.reset();
livekit::shutdown();
return 1;
std::shared_ptr<LocalDataTrack> pong_track;
{
// limit the scope of the local participant
auto local_participant = room->localParticipant().lock();
if (!local_participant) {
throw std::runtime_error("[pong] local participant is null");
}

std::cout << "[info] pong connected as identity='" << local_participant->identity() << "' room='"
<< room->roomInfo().name << "'\n";

auto publish_result = local_participant->publishDataTrack(ping_pong::kPongTrackName);
if (!publish_result) {
const auto& error = publish_result.error();
std::cerr << "[error] Failed to publish pong data track: code=" << static_cast<std::uint32_t>(error.code)
<< " message=" << error.message << "\n";
room->setDelegate(nullptr);
room.reset();
livekit::shutdown();
return 1;
}
pong_track = publish_result.value();
}

std::shared_ptr<LocalDataTrack> pong_track = publish_result.value();

const auto callback_id = room->addOnDataFrameCallback(
ping_pong::kPingParticipantIdentity, ping_pong::kPingTrackName,
[pong_track](const std::vector<std::uint8_t>& payload, std::optional<std::uint64_t> /*user_timestamp*/) {
Expand Down
5 changes: 3 additions & 2 deletions simple_data_stream/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ std::string randomHexId(std::size_t nbytes = 16) {
void greetParticipant(Room* room, const std::string& identity) {
std::cout << "[DataStream] Greeting participant: " << identity << "\n";

LocalParticipant* lp = room->localParticipant();
auto lp = room->localParticipant().lock();
if (!lp) {
std::cerr << "[DataStream] No local participant, cannot greet.\n";
return;
Expand Down Expand Up @@ -240,7 +240,8 @@ int main(int argc, char* argv[]) {
// Greet existing participants
{
auto remotes = room->remoteParticipants();
for (const auto& rp : remotes) {
for (const auto& weak_rp : remotes) {
auto rp = weak_rp.lock();
if (!rp) continue;
std::cout << "Remote: " << rp->identity() << "\n";
greetParticipant(room.get(), rp->identity());
Expand Down
32 changes: 0 additions & 32 deletions simple_joystick/receiver/CMakeLists.txt

This file was deleted.

45 changes: 0 additions & 45 deletions simple_joystick/receiver/json_utils.cpp

This file was deleted.

38 changes: 0 additions & 38 deletions simple_joystick/receiver/json_utils.h

This file was deleted.

Loading
Loading