LiveKit C++ SDK
Real-time audio/video SDK for C++
Loading...
Searching...
No Matches
participant.h
1/*
2 * Copyright 2025 LiveKit
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an “AS IS” BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#pragma once
18
19#include <cstdint>
20#include <memory>
21#include <string>
22#include <unordered_map>
23
24#include "livekit/ffi_handle.h"
25#include "livekit/room_delegate.h"
26
27namespace livekit {
28
29enum class ParticipantKind { Standard = 0, Ingress, Egress, Sip, Agent };
30
32public:
33 Participant(FfiHandle handle, std::string sid, std::string name,
34 std::string identity, std::string metadata,
35 std::unordered_map<std::string, std::string> attributes,
36 ParticipantKind kind, DisconnectReason reason)
37 : handle_(std::move(handle)), sid_(std::move(sid)),
38 name_(std::move(name)), identity_(std::move(identity)),
39 metadata_(std::move(metadata)), attributes_(std::move(attributes)),
40 kind_(kind), reason_(reason) {}
41 virtual ~Participant() = default;
42
43 // Plain getters (caller ensures threading)
44 const std::string &sid() const noexcept { return sid_; }
45 const std::string &name() const noexcept { return name_; }
46 const std::string &identity() const noexcept { return identity_; }
47 const std::string &metadata() const noexcept { return metadata_; }
48 const std::unordered_map<std::string, std::string> &
49 attributes() const noexcept {
50 return attributes_;
51 }
52 ParticipantKind kind() const noexcept { return kind_; }
53 DisconnectReason disconnectReason() const noexcept { return reason_; }
54
55 uintptr_t ffiHandleId() const noexcept { return handle_.get(); }
56
57 // Setters (caller ensures threading)
58 void set_name(std::string name) noexcept { name_ = std::move(name); }
59 void set_metadata(std::string metadata) noexcept {
60 metadata_ = std::move(metadata);
61 }
62 void
63 set_attributes(std::unordered_map<std::string, std::string> attrs) noexcept {
64 attributes_ = std::move(attrs);
65 }
66 void set_attribute(const std::string &key, const std::string &value) {
67 attributes_[key] = value;
68 }
69 void remove_attribute(const std::string &key) { attributes_.erase(key); }
70 void set_kind(ParticipantKind kind) noexcept { kind_ = kind; }
71 void set_disconnect_reason(DisconnectReason reason) noexcept {
72 reason_ = reason;
73 }
74
75protected:
76 virtual std::shared_ptr<TrackPublication>
77 findTrackPublication(const std::string &sid) const = 0;
78 friend class Room;
79
80private:
81 FfiHandle handle_;
82 std::string sid_, name_, identity_, metadata_;
83 std::unordered_map<std::string, std::string> attributes_;
84 ParticipantKind kind_;
85 DisconnectReason reason_;
86};
87
88} // namespace livekit
RAII wrapper for an FFI handle (uintptr_t) coming from Rust.
Definition ffi_handle.h:29
Definition participant.h:31
Definition room.h:89