@@ -124,7 +124,7 @@ bool Room::connect(const std::string& url, const std::string& token, const RoomO
124124 auto new_room_info = fromProto (owned_room.info ());
125125
126126 // Setup local particpant
127- std::unique_ptr <LocalParticipant> new_local_participant;
127+ std::shared_ptr <LocalParticipant> new_local_participant;
128128 {
129129 const auto & owned_local = connectCb.result ().local_participant ();
130130 const auto & pinfo = owned_local.info ();
@@ -141,7 +141,7 @@ bool Room::connect(const std::string& url, const std::string& token, const RoomO
141141 // Participant base stores a weak_ptr<FfiHandle>, so share the room handle
142142 FfiHandle participant_handle (static_cast <uintptr_t >(owned_local.handle ().id ()));
143143 new_local_participant =
144- std::make_unique <LocalParticipant>(std::move (participant_handle), pinfo.sid (), pinfo.name (), pinfo.identity (),
144+ std::make_shared <LocalParticipant>(std::move (participant_handle), pinfo.sid (), pinfo.name (), pinfo.identity (),
145145 pinfo.metadata (), std::move (attrs), kind, reason);
146146 }
147147
@@ -164,11 +164,11 @@ bool Room::connect(const std::string& url, const std::string& token, const RoomO
164164 }
165165
166166 // Setup e2eeManager
167- std::unique_ptr <E2EEManager> new_e2ee_manager;
167+ std::shared_ptr <E2EEManager> new_e2ee_manager;
168168 if (options.encryption ) {
169169 LK_LOG_INFO (" creating E2eeManager" );
170170 new_e2ee_manager =
171- std::unique_ptr <E2EEManager>(new E2EEManager (new_room_handle->get (), options.encryption .value ()));
171+ std::shared_ptr <E2EEManager>(new E2EEManager (new_room_handle->get (), options.encryption .value ()));
172172 }
173173
174174 // Publish all state atomically under lock
@@ -186,7 +186,7 @@ bool Room::connect(const std::string& url, const std::string& token, const RoomO
186186 return true ;
187187 } catch (const std::exception& e) {
188188 int listener_to_remove = 0 ;
189- std::unique_ptr <LocalParticipant> local_participant_to_cleanup;
189+ std::shared_ptr <LocalParticipant> local_participant_to_cleanup;
190190 {
191191 const std::scoped_lock<std::mutex> g (lock_);
192192 connection_state_ = ConnectionState::Disconnected;
@@ -299,23 +299,23 @@ RoomInfoData Room::roomInfo() const {
299299 return room_info_;
300300}
301301
302- LocalParticipant* Room::localParticipant () const {
302+ std::weak_ptr< LocalParticipant> Room::localParticipant () const {
303303 const std::scoped_lock<std::mutex> g (lock_);
304- return local_participant_. get () ;
304+ return local_participant_;
305305}
306306
307- RemoteParticipant* Room::remoteParticipant (const std::string& identity) const {
307+ std::weak_ptr< RemoteParticipant> Room::remoteParticipant (const std::string& identity) const {
308308 const std::scoped_lock<std::mutex> g (lock_);
309309 auto it = remote_participants_.find (identity);
310- return it == remote_participants_.end () ? nullptr : it->second . get () ;
310+ return it == remote_participants_.end () ? std::weak_ptr<RemoteParticipant>{} : it->second ;
311311}
312312
313- std::vector<RemoteParticipant* > Room::remoteParticipants () const {
313+ std::vector<std::weak_ptr< RemoteParticipant> > Room::remoteParticipants () const {
314314 const std::scoped_lock<std::mutex> guard (lock_);
315- std::vector<RemoteParticipant* > out;
315+ std::vector<std::weak_ptr< RemoteParticipant> > out;
316316 out.reserve (remote_participants_.size ());
317317 for (const auto & kv : remote_participants_) {
318- out.push_back (kv.second . get () );
318+ out.push_back (kv.second );
319319 }
320320 return out;
321321}
@@ -337,9 +337,9 @@ std::future<SessionStats> Room::getStats() const {
337337 return FfiClient::instance ().getSessionStatsAsync (handle->get ());
338338}
339339
340- E2EEManager* Room::e2eeManager () const {
340+ std::weak_ptr< E2EEManager> Room::e2eeManager () const {
341341 const std::scoped_lock<std::mutex> g (lock_);
342- return e2ee_manager_. get () ;
342+ return e2ee_manager_;
343343}
344344
345345void Room::registerTextStreamHandler (const std::string& topic, TextStreamHandler handler) {
@@ -1211,10 +1211,10 @@ void Room::onEvent(const FfiEvent& event) {
12111211
12121212 // Move state out of lock scope before destroying to avoid holding lock
12131213 // during potentially long destructors
1214- std::unique_ptr <LocalParticipant> old_local_participant;
1214+ std::shared_ptr <LocalParticipant> old_local_participant;
12151215 std::unordered_map<std::string, std::shared_ptr<RemoteParticipant>> old_remote_participants;
12161216 std::shared_ptr<FfiHandle> old_room_handle;
1217- std::unique_ptr <E2EEManager> old_e2ee_manager;
1217+ std::shared_ptr <E2EEManager> old_e2ee_manager;
12181218 std::unordered_map<std::string, std::shared_ptr<TextStreamReader>> old_text_readers;
12191219 std::unordered_map<std::string, std::shared_ptr<ByteStreamReader>> old_byte_readers;
12201220
0 commit comments