@@ -81,14 +81,14 @@ Room::~Room() {
8181 }
8282
8383 int listener_to_remove = 0 ;
84- std::unique_ptr <LocalParticipant> local_participant_to_cleanup;
84+ std::shared_ptr <LocalParticipant> local_participant_to_cleanup;
8585 std::unordered_map<std::string, std::shared_ptr<RemoteParticipant>> remote_participants_to_cleanup;
8686 {
8787 const std::scoped_lock<std::mutex> g (lock_);
8888 listener_to_remove = listener_id_;
8989 listener_id_ = 0 ;
9090 connection_state_ = ConnectionState::Disconnected;
91- // Move participant state out so accessors return nullptr during teardown.
91+ // Move participant state out so weak handles expire during teardown.
9292 local_participant_to_cleanup = std::move (local_participant_);
9393 remote_participants_to_cleanup = std::move (remote_participants_);
9494 room_handle_.reset ();
@@ -149,7 +149,7 @@ bool Room::connect(const std::string& url, const std::string& token, const RoomO
149149 auto new_room_info = fromProto (owned_room.info ());
150150
151151 // Setup local particpant
152- std::unique_ptr <LocalParticipant> new_local_participant;
152+ std::shared_ptr <LocalParticipant> new_local_participant;
153153 {
154154 const auto & owned_local = connectCb.result ().local_participant ();
155155 const auto & pinfo = owned_local.info ();
@@ -166,7 +166,7 @@ bool Room::connect(const std::string& url, const std::string& token, const RoomO
166166 // Participant base stores a weak_ptr<FfiHandle>, so share the room handle
167167 FfiHandle participant_handle (static_cast <uintptr_t >(owned_local.handle ().id ()));
168168 new_local_participant =
169- std::make_unique <LocalParticipant>(std::move (participant_handle), pinfo.sid (), pinfo.name (), pinfo.identity (),
169+ std::make_shared <LocalParticipant>(std::move (participant_handle), pinfo.sid (), pinfo.name (), pinfo.identity (),
170170 pinfo.metadata (), std::move (attrs), kind, reason);
171171 }
172172
@@ -189,11 +189,11 @@ bool Room::connect(const std::string& url, const std::string& token, const RoomO
189189 }
190190
191191 // Setup e2eeManager
192- std::unique_ptr <E2EEManager> new_e2ee_manager;
192+ std::shared_ptr <E2EEManager> new_e2ee_manager;
193193 if (options.encryption ) {
194194 LK_LOG_INFO (" creating E2eeManager" );
195195 new_e2ee_manager =
196- std::unique_ptr <E2EEManager>(new E2EEManager (new_room_handle->get (), options.encryption .value ()));
196+ std::shared_ptr <E2EEManager>(new E2EEManager (new_room_handle->get (), options.encryption .value ()));
197197 }
198198
199199 // Publish all state atomically under lock
@@ -211,7 +211,7 @@ bool Room::connect(const std::string& url, const std::string& token, const RoomO
211211 return true ;
212212 } catch (const std::exception& e) {
213213 int listener_to_remove = 0 ;
214- std::unique_ptr <LocalParticipant> local_participant_to_cleanup;
214+ std::shared_ptr <LocalParticipant> local_participant_to_cleanup;
215215 {
216216 const std::scoped_lock<std::mutex> g (lock_);
217217 connection_state_ = ConnectionState::Disconnected;
@@ -242,23 +242,23 @@ RoomInfoData Room::roomInfo() const {
242242 return room_info_;
243243}
244244
245- LocalParticipant* Room::localParticipant () const {
245+ std::weak_ptr< LocalParticipant> Room::localParticipant () const {
246246 const std::scoped_lock<std::mutex> g (lock_);
247- return local_participant_. get () ;
247+ return local_participant_;
248248}
249249
250- RemoteParticipant* Room::remoteParticipant (const std::string& identity) const {
250+ std::weak_ptr< RemoteParticipant> Room::remoteParticipant (const std::string& identity) const {
251251 const std::scoped_lock<std::mutex> g (lock_);
252252 auto it = remote_participants_.find (identity);
253- return it == remote_participants_.end () ? nullptr : it->second . get () ;
253+ return it == remote_participants_.end () ? std::weak_ptr<RemoteParticipant>{} : it->second ;
254254}
255255
256- std::vector<RemoteParticipant* > Room::remoteParticipants () const {
256+ std::vector<std::weak_ptr< RemoteParticipant> > Room::remoteParticipants () const {
257257 const std::scoped_lock<std::mutex> guard (lock_);
258- std::vector<RemoteParticipant* > out;
258+ std::vector<std::weak_ptr< RemoteParticipant> > out;
259259 out.reserve (remote_participants_.size ());
260260 for (const auto & kv : remote_participants_) {
261- out.push_back (kv.second . get () );
261+ out.push_back (kv.second );
262262 }
263263 return out;
264264}
@@ -280,9 +280,9 @@ std::future<SessionStats> Room::getStats() const {
280280 return FfiClient::instance ().getSessionStatsAsync (handle->get ());
281281}
282282
283- E2EEManager* Room::e2eeManager () const {
283+ std::weak_ptr< E2EEManager> Room::e2eeManager () const {
284284 const std::scoped_lock<std::mutex> g (lock_);
285- return e2ee_manager_. get () ;
285+ return e2ee_manager_;
286286}
287287
288288void Room::registerTextStreamHandler (const std::string& topic, TextStreamHandler handler) {
@@ -1143,10 +1143,10 @@ void Room::onEvent(const FfiEvent& event) {
11431143
11441144 // Move state out of lock scope before destroying to avoid holding lock
11451145 // during potentially long destructors
1146- std::unique_ptr <LocalParticipant> old_local_participant;
1146+ std::shared_ptr <LocalParticipant> old_local_participant;
11471147 std::unordered_map<std::string, std::shared_ptr<RemoteParticipant>> old_remote_participants;
11481148 std::shared_ptr<FfiHandle> old_room_handle;
1149- std::unique_ptr <E2EEManager> old_e2ee_manager;
1149+ std::shared_ptr <E2EEManager> old_e2ee_manager;
11501150 std::unordered_map<std::string, std::shared_ptr<TextStreamReader>> old_text_readers;
11511151 std::unordered_map<std::string, std::shared_ptr<ByteStreamReader>> old_byte_readers;
11521152
0 commit comments