Skip to content

Commit b6cfa19

Browse files
fix
1 parent 260ce13 commit b6cfa19

8 files changed

Lines changed: 229 additions & 185 deletions

File tree

bridge/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ add_library(livekit_bridge SHARED
1111
src/bridge_video_track.cpp
1212
src/bridge_room_delegate.cpp
1313
src/bridge_room_delegate.h
14-
src/rpc_manager.cpp
15-
src/rpc_manager.h
14+
src/rpc_controller.cpp
15+
src/rpc_controller.h
1616
)
1717

1818
if(WIN32)

bridge/include/livekit_bridge/livekit_bridge.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ enum class TrackSource;
4949
namespace livekit_bridge {
5050

5151
class BridgeRoomDelegate;
52-
class RpcManager;
52+
class RpcController;
5353

5454
namespace test {
5555
class CallbackKeyTest;
@@ -403,7 +403,7 @@ class LiveKitBridge {
403403
VideoFrameCallback cb);
404404

405405
/// Execute a track action (mute/unmute/release) by track name.
406-
/// Used as the TrackActionFn callback for RpcManager.
406+
/// Used as the TrackActionFn callback for RpcController.
407407
/// Throws livekit::RpcError if the track is not found.
408408
/// @pre Caller does NOT hold mutex_ (acquires it internally).
409409
void executeTrackAction(const rpc::track_control::Action &action,
@@ -418,7 +418,7 @@ class LiveKitBridge {
418418

419419
std::unique_ptr<livekit::Room> room_;
420420
std::unique_ptr<BridgeRoomDelegate> delegate_;
421-
std::unique_ptr<RpcManager> rpc_manager_;
421+
std::unique_ptr<RpcController> rpc_controller_;
422422

423423
/// Registered callbacks (may be registered before tracks are subscribed).
424424
std::unordered_map<CallbackKey, AudioFrameCallback, CallbackKeyHash>

bridge/src/livekit_bridge.cpp

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
#include "livekit_bridge/livekit_bridge.h"
2121
#include "bridge_room_delegate.h"
2222
#include "livekit_bridge/rpc_constants.h"
23-
#include "rpc_manager.h"
23+
#include "rpc_controller.h"
2424

2525
#include "livekit/audio_frame.h"
2626
#include "livekit/audio_source.h"
@@ -64,7 +64,7 @@ LiveKitBridge::CallbackKeyHash::operator()(const CallbackKey &k) const {
6464

6565
LiveKitBridge::LiveKitBridge()
6666
: connected_(false), connecting_(false), sdk_initialized_(false),
67-
rpc_manager_(std::make_unique<RpcManager>(
67+
rpc_controller_(std::make_unique<RpcController>(
6868
[this](const rpc::track_control::Action &action,
6969
const std::string &track_name) {
7070
executeTrackAction(action, track_name);
@@ -133,15 +133,15 @@ bool LiveKitBridge::connect(const std::string &url, const std::string &token,
133133
assert(lp != nullptr);
134134
}
135135

136-
rpc_manager_->enable(lp);
136+
rpc_controller_->enable(lp);
137137
return true;
138138
}
139139

140140
void LiveKitBridge::disconnect() {
141-
// Disable the RPC manager before tearing down the room. This unregisters
141+
// Disable the RPC controller before tearing down the room. This unregisters
142142
// built-in handlers while the LocalParticipant is still alive.
143-
if (rpc_manager_->isEnabled()) {
144-
rpc_manager_->disable();
143+
if (rpc_controller_ && rpc_controller_->isEnabled()) {
144+
rpc_controller_->disable();
145145
}
146146

147147
// Collect threads to join outside the lock to avoid deadlock.
@@ -228,7 +228,10 @@ LiveKitBridge::createAudioTrack(const std::string &name, int sample_rate,
228228
int num_channels, livekit::TrackSource source) {
229229
std::lock_guard<std::mutex> lock(mutex_);
230230

231-
assert(connected_ && room_);
231+
if (!connected_ || !room_) {
232+
throw std::runtime_error(
233+
"createAudioTrack requires an active connection; call connect() first");
234+
}
232235

233236
// 1. Create audio source (real-time mode, queue_size_ms=0)
234237
auto audio_source =
@@ -260,7 +263,10 @@ LiveKitBridge::createVideoTrack(const std::string &name, int width, int height,
260263
livekit::TrackSource source) {
261264
std::lock_guard<std::mutex> lock(mutex_);
262265

263-
assert(connected_ && room_);
266+
if (!connected_ || !room_) {
267+
throw std::runtime_error(
268+
"createVideoTrack requires an active connection; call connect() first");
269+
}
264270

265271
// 1. Create video source
266272
auto video_source = std::make_shared<livekit::VideoSource>(width, height);
@@ -348,7 +354,7 @@ void LiveKitBridge::clearOnVideoFrameCallback(
348354
}
349355

350356
// ---------------------------------------------------------------
351-
// RPC (delegates to RpcManager)
357+
// RPC (delegates to RpcController)
352358
// ---------------------------------------------------------------
353359

354360
std::optional<std::string>
@@ -361,8 +367,8 @@ LiveKitBridge::performRpc(const std::string &destination_identity,
361367
}
362368

363369
try {
364-
return rpc_manager_->performRpc(destination_identity, method, payload,
365-
response_timeout);
370+
return rpc_controller_->performRpc(destination_identity, method, payload,
371+
response_timeout);
366372
} catch (const std::exception &e) {
367373
std::cerr << "[LiveKitBridge] Exception: " << e.what() << "\n";
368374
return std::nullopt;
@@ -383,7 +389,7 @@ bool LiveKitBridge::registerRpcMethod(
383389
return false;
384390
}
385391
try {
386-
rpc_manager_->registerRpcMethod(method_name, std::move(handler));
392+
rpc_controller_->registerRpcMethod(method_name, std::move(handler));
387393
return true;
388394
} catch (const std::exception &e) {
389395
std::cerr << "[LiveKitBridge] Exception: " << e.what() << "\n";
@@ -402,7 +408,7 @@ bool LiveKitBridge::unregisterRpcMethod(const std::string &method_name) {
402408
return false;
403409
}
404410
try {
405-
rpc_manager_->unregisterRpcMethod(method_name);
411+
rpc_controller_->unregisterRpcMethod(method_name);
406412
return true;
407413
} catch (const std::exception &e) {
408414
std::cerr << "[LiveKitBridge] Exception: " << e.what() << "\n";
@@ -422,7 +428,7 @@ bool LiveKitBridge::requestRemoteTrackMute(
422428
return false;
423429
}
424430
try {
425-
rpc_manager_->requestRemoteTrackMute(destination_identity, track_name);
431+
rpc_controller_->requestRemoteTrackMute(destination_identity, track_name);
426432
return true;
427433
} catch (const std::exception &e) {
428434
std::cerr << "[LiveKitBridge] Exception: " << e.what() << "\n";
@@ -442,7 +448,7 @@ bool LiveKitBridge::requestRemoteTrackUnmute(
442448
return false;
443449
}
444450
try {
445-
rpc_manager_->requestRemoteTrackUnmute(destination_identity, track_name);
451+
rpc_controller_->requestRemoteTrackUnmute(destination_identity, track_name);
446452
return true;
447453
} catch (const std::exception &e) {
448454
std::cerr << "[LiveKitBridge] Exception: " << e.what() << "\n";
@@ -457,7 +463,7 @@ bool LiveKitBridge::requestRemoteTrackUnmute(
457463
}
458464

459465
// ---------------------------------------------------------------
460-
// Track action callback for RpcManager
466+
// Track action callback for RpcController
461467
// ---------------------------------------------------------------
462468

463469
void LiveKitBridge::executeTrackAction(const rpc::track_control::Action &action,
Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@
1414
* limitations under the License.
1515
*/
1616

17-
/// @file rpc_manager.cpp
18-
/// @brief Implementation of RpcManager.
17+
/// @file rpc_controller.cpp
18+
/// @brief Implementation of RpcController.
1919

20-
#include "rpc_manager.h"
20+
#include "rpc_controller.h"
2121
#include "livekit_bridge/rpc_constants.h"
2222

2323
#include "livekit/local_participant.h"
@@ -28,16 +28,16 @@
2828

2929
namespace livekit_bridge {
3030

31-
RpcManager::RpcManager(TrackActionFn track_action_fn)
31+
RpcController::RpcController(TrackActionFn track_action_fn)
3232
: track_action_fn_(std::move(track_action_fn)), lp_(nullptr) {}
3333

34-
void RpcManager::enable(livekit::LocalParticipant *lp) {
34+
void RpcController::enable(livekit::LocalParticipant *lp) {
3535
assert(lp != nullptr);
3636
lp_ = lp;
3737
enableBuiltInHandlers();
3838
}
3939

40-
void RpcManager::disable() {
40+
void RpcController::disable() {
4141
if (lp_) {
4242
disableBuiltInHandlers();
4343
}
@@ -49,7 +49,7 @@ void RpcManager::disable() {
4949
// ---------------------------------------------------------------
5050

5151
std::string
52-
RpcManager::performRpc(const std::string &destination_identity,
52+
RpcController::performRpc(const std::string &destination_identity,
5353
const std::string &method, const std::string &payload,
5454
const std::optional<double> &response_timeout) {
5555
assert(lp_ != nullptr);
@@ -61,14 +61,14 @@ RpcManager::performRpc(const std::string &destination_identity,
6161
// User-registered handlers
6262
// ---------------------------------------------------------------
6363

64-
void RpcManager::registerRpcMethod(
64+
void RpcController::registerRpcMethod(
6565
const std::string &method_name,
6666
livekit::LocalParticipant::RpcHandler handler) {
6767
assert(lp_ != nullptr);
6868
lp_->registerRpcMethod(method_name, std::move(handler));
6969
}
7070

71-
void RpcManager::unregisterRpcMethod(const std::string &method_name) {
71+
void RpcController::unregisterRpcMethod(const std::string &method_name) {
7272
assert(lp_ != nullptr);
7373
lp_->unregisterRpcMethod(method_name);
7474
}
@@ -77,14 +77,14 @@ void RpcManager::unregisterRpcMethod(const std::string &method_name) {
7777
// Built-in outgoing convenience (track control)
7878
// ---------------------------------------------------------------
7979

80-
void RpcManager::requestRemoteTrackMute(const std::string &destination_identity,
80+
void RpcController::requestRemoteTrackMute(const std::string &destination_identity,
8181
const std::string &track_name) {
8282
namespace tc = rpc::track_control;
8383
performRpc(destination_identity, tc::kMethod,
8484
tc::formatPayload(tc::kActionMute, track_name), std::nullopt);
8585
}
8686

87-
void RpcManager::requestRemoteTrackUnmute(
87+
void RpcController::requestRemoteTrackUnmute(
8888
const std::string &destination_identity, const std::string &track_name) {
8989
namespace tc = rpc::track_control;
9090
performRpc(destination_identity, tc::kMethod,
@@ -95,7 +95,7 @@ void RpcManager::requestRemoteTrackUnmute(
9595
// Built-in handler registration
9696
// ---------------------------------------------------------------
9797

98-
void RpcManager::enableBuiltInHandlers() {
98+
void RpcController::enableBuiltInHandlers() {
9999
assert(lp_ != nullptr);
100100
lp_->registerRpcMethod(rpc::track_control::kMethod,
101101
[this](const livekit::RpcInvocationData &data)
@@ -104,7 +104,7 @@ void RpcManager::enableBuiltInHandlers() {
104104
});
105105
}
106106

107-
void RpcManager::disableBuiltInHandlers() {
107+
void RpcController::disableBuiltInHandlers() {
108108
assert(lp_ != nullptr);
109109
lp_->unregisterRpcMethod(rpc::track_control::kMethod);
110110
}
@@ -114,10 +114,10 @@ void RpcManager::disableBuiltInHandlers() {
114114
// ---------------------------------------------------------------
115115

116116
std::optional<std::string>
117-
RpcManager::handleTrackControlRpc(const livekit::RpcInvocationData &data) {
117+
RpcController::handleTrackControlRpc(const livekit::RpcInvocationData &data) {
118118
namespace tc = rpc::track_control;
119119

120-
std::cout << "[RpcManager] Handling track control RPC: " << data.payload
120+
std::cout << "[RpcController] Handling track control RPC: " << data.payload
121121
<< "\n";
122122
auto delim = data.payload.find(tc::kDelimiter);
123123
if (delim == std::string::npos || delim == 0) {
Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
* limitations under the License.
1515
*/
1616

17-
/// @file rpc_manager.h
18-
/// @brief Internal RPC manager that owns all RPC concerns for the bridge.
17+
/// @file rpc_controller.h
18+
/// @brief Internal RPC controller that owns all RPC concerns for the bridge.
1919

2020
#pragma once
2121

@@ -34,15 +34,15 @@ struct RpcInvocationData;
3434
namespace livekit_bridge {
3535

3636
namespace test {
37-
class RpcManagerTest;
37+
class RpcControllerTest;
3838
} // namespace test
3939

4040
/**
4141
* Owns all RPC concerns for the LiveKitBridge: built-in handler registration
4242
* and dispatch, user-registered custom handlers, and outgoing RPC calls.
4343
*
44-
* The manager is bound to a LocalParticipant via enable() and unbound via
45-
* disable(). All public methods require the manager to be enabled (i.e.,
44+
* The controller is bound to a LocalParticipant via enable() and unbound via
45+
* disable(). All public methods require the controller to be enabled (i.e.,
4646
* enable() has been called and disable() has not).
4747
*
4848
* Built-in handlers (e.g., track-control) are automatically registered on
@@ -51,15 +51,15 @@ class RpcManagerTest;
5151
*
5252
* Not part of the public API; lives in bridge/src/.
5353
*/
54-
class RpcManager {
54+
class RpcController {
5555
public:
5656
/// Callback the bridge provides to execute a track action
5757
/// (mute/unmute/release). Throws livekit::RpcError if the track is not found
5858
/// or the action is invalid.
5959
using TrackActionFn = std::function<void(
6060
const rpc::track_control::Action &action, const std::string &track_name)>;
6161

62-
explicit RpcManager(TrackActionFn track_action_fn);
62+
explicit RpcController(TrackActionFn track_action_fn);
6363

6464
/// Bind to a LocalParticipant and register all built-in RPC handlers.
6565
/// @pre @p lp must be non-null and remain valid until disable() is called.
@@ -68,7 +68,7 @@ class RpcManager {
6868
/// Unregister built-in handlers and unbind from the LocalParticipant.
6969
void disable();
7070

71-
/// Whether the manager is currently bound to a LocalParticipant.
71+
/// Whether the controller is currently bound to a LocalParticipant.
7272
bool isEnabled() const { return lp_ != nullptr; }
7373

7474
// -- Generic RPC --
@@ -118,7 +118,7 @@ class RpcManager {
118118
const std::string &track_name);
119119

120120
private:
121-
friend class test::RpcManagerTest;
121+
friend class test::RpcControllerTest;
122122

123123
/// @brief Enable built-in handlers.
124124
/// @throws if the LocalParticipant registerRpcMethod fails.
@@ -138,7 +138,7 @@ class RpcManager {
138138
/// Callback to execute a track action RPC
139139
TrackActionFn track_action_fn_;
140140

141-
/// The LocalParticipant bound to the manager.
141+
/// The LocalParticipant bound to the controller.
142142
livekit::LocalParticipant *lp_;
143143
};
144144

0 commit comments

Comments
 (0)