Skip to content

Commit 6457ca9

Browse files
Sxian/clt 2342/implement the remaining room events (#14)
* RPC features * added a new README and fix the comments * point to the right line * fix the linux build * fix the build and addressed the comments * fix the build * recover the room.cpp * recover room.cpp from the uncheckin changes * initial commit * removed the un-needed functions from room_proto_converter.h * move the room event types into room_event_types.h from room_delegate.h, and fix the comments * removed the deprecated events
1 parent 96e7643 commit 6457ca9

23 files changed

+1530
-757
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ add_library(livekit
160160
include/livekit/audio_source.h
161161
include/livekit/audio_stream.h
162162
include/livekit/room.h
163+
include/livekit/room_event_types.h
163164
include/livekit/room_delegate.h
164165
include/livekit/ffi_handle.h
165166
include/livekit/ffi_client.h

examples/simple_room/main.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,9 @@ class SimpleRoomDelegate : public livekit::RoomDelegate {
156156
void onParticipantConnected(
157157
livekit::Room & /*room*/,
158158
const livekit::ParticipantConnectedEvent &ev) override {
159-
std::cout << "[Room] participant connected: identity=" << ev.identity
160-
<< " name=" << ev.name << "\n";
159+
std::cout << "[Room] participant connected: identity="
160+
<< ev.participant->identity()
161+
<< " name=" << ev.participant->name() << "\n";
161162
}
162163

163164
void onTrackSubscribed(livekit::Room & /*room*/,
@@ -172,19 +173,18 @@ class SimpleRoomDelegate : public livekit::RoomDelegate {
172173
<< participant_identity << " track_sid=" << track_sid
173174
<< " name=" << track_name;
174175
if (ev.track) {
175-
std::cout << " kind=" << static_cast<int>(ev.track->kind()) << "\n";
176+
std::cout << " kind=" << static_cast<int>(ev.track->kind());
176177
}
177178
if (ev.publication) {
178-
std::cout << " source=" << static_cast<int>(ev.publication->source())
179-
<< "\n";
179+
std::cout << " source=" << static_cast<int>(ev.publication->source());
180180
}
181+
std::cout << std::endl;
181182

182183
// If this is a VIDEO track, create a VideoStream and attach to renderer
183184
if (ev.track && ev.track->kind() == TrackKind::KIND_VIDEO) {
184185
VideoStream::Options opts;
185186
opts.format = livekit::VideoBufferType::RGBA;
186187
auto video_stream = VideoStream::fromTrack(ev.track, opts);
187-
std::cout << "after fromTrack " << std::endl;
188188
if (!video_stream) {
189189
std::cerr << "Failed to create VideoStream for track " << track_sid
190190
<< "\n";

include/livekit/audio_frame.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ class AudioFrame {
4343
AudioFrame(std::vector<std::int16_t> data, int sample_rate, int num_channels,
4444
int samples_per_channel);
4545
AudioFrame(); // Default constructor
46+
virtual ~AudioFrame() = default;
4647

4748
/**
4849
* Create a new zero-initialized AudioFrame instance.

include/livekit/audio_source.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,7 @@ class AudioSource {
4343
* @param queue_size_ms Max buffer duration for the internal queue in ms.
4444
*/
4545
AudioSource(int sample_rate, int num_channels, int queue_size_ms = 1000);
46-
47-
~AudioSource();
46+
virtual ~AudioSource() = default;
4847

4948
AudioSource(const AudioSource &) = delete;
5049
AudioSource &operator=(const AudioSource &) = delete;

include/livekit/audio_stream.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ class AudioStream {
8585
TrackSource track_source,
8686
const Options &options);
8787

88-
~AudioStream();
88+
virtual ~AudioStream();
8989

9090
/// No copy, assignment constructors.
9191
AudioStream(const AudioStream &) = delete;

include/livekit/livekit.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "remote_track_publication.h"
2727
#include "room.h"
2828
#include "room_delegate.h"
29+
#include "room_event_types.h"
2930
#include "track_publication.h"
3031
#include "video_frame.h"
3132
#include "video_source.h"

include/livekit/local_participant.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
#include "livekit/ffi_handle.h"
2020
#include "livekit/participant.h"
21-
#include "livekit/room_delegate.h"
21+
#include "livekit/room_event_types.h"
2222
#include "livekit/rpc_error.h"
2323

2424
#include <cstdint>
@@ -203,6 +203,9 @@ class LocalParticipant : public Participant {
203203
const std::string &caller_identity,
204204
const std::string &payload,
205205
double response_timeout);
206+
// Called by Room events like kTrackMuted.
207+
std::shared_ptr<TrackPublication>
208+
findTrackPublication(const std::string &sid) const override;
206209
friend class Room;
207210

208211
private:

include/livekit/participant.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ class Participant {
3939
name_(std::move(name)), identity_(std::move(identity)),
4040
metadata_(std::move(metadata)), attributes_(std::move(attributes)),
4141
kind_(kind), reason_(reason) {}
42+
virtual ~Participant() = default;
4243

4344
// Plain getters (caller ensures threading)
4445
const std::string &sid() const noexcept { return sid_; }
@@ -72,6 +73,11 @@ class Participant {
7273
reason_ = reason;
7374
}
7475

76+
protected:
77+
virtual std::shared_ptr<TrackPublication>
78+
findTrackPublication(const std::string &sid) const = 0;
79+
friend class Room;
80+
7581
private:
7682
FfiHandle handle_;
7783
std::string sid_, name_, identity_, metadata_;

include/livekit/remote_participant.h

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class RemoteTrackPublication;
2828

2929
class RemoteParticipant : public Participant {
3030
public:
31-
using TrackPublicationMap =
31+
using PublicationMap =
3232
std::unordered_map<std::string, std::shared_ptr<RemoteTrackPublication>>;
3333

3434
RemoteParticipant(FfiHandle handle, std::string sid, std::string name,
@@ -37,20 +37,27 @@ class RemoteParticipant : public Participant {
3737
ParticipantKind kind, DisconnectReason reason);
3838

3939
// A dictionary of track publications associated with the participant.
40-
const TrackPublicationMap &track_publications() const noexcept {
40+
const PublicationMap &trackPublications() const noexcept {
4141
return track_publications_;
4242
}
4343

4444
// Optional: non-const access if you want to mutate in-place.
45-
TrackPublicationMap &mutable_track_publications() noexcept {
45+
PublicationMap &mutableTrackPublications() noexcept {
4646
return track_publications_;
4747
}
4848

4949
// C++ equivalent of Python's __repr__
5050
std::string to_string() const;
5151

52+
protected:
53+
// Called by Room events like kTrackMuted. This is internal plumbing and not
54+
// intended to be called directly by SDK users.
55+
std::shared_ptr<TrackPublication>
56+
findTrackPublication(const std::string &sid) const override;
57+
friend class Room;
58+
5259
private:
53-
TrackPublicationMap track_publications_;
60+
PublicationMap track_publications_;
5461
};
5562

5663
// Convenience for logging / streaming

include/livekit/room.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
#include "livekit/ffi_client.h"
2121
#include "livekit/ffi_handle.h"
22-
#include "livekit/room_delegate.h"
22+
#include "livekit/room_event_types.h"
2323
#include <memory>
2424
#include <mutex>
2525

@@ -185,6 +185,7 @@ class Room {
185185
std::unique_ptr<LocalParticipant> local_participant_;
186186
std::unordered_map<std::string, std::shared_ptr<RemoteParticipant>>
187187
remote_participants_;
188+
ConnectionState connection_state_ = ConnectionState::Disconnected;
188189

189190
void OnEvent(const proto::FfiEvent &event);
190191
};

0 commit comments

Comments
 (0)