diff --git a/crates/call/src/room.rs b/crates/call/src/room.rs index 909fe4d977085b4936b31991a957b6fea68c1ac9..1bd86944bfe4e5ef1cde0d2fab1c109c69215441 100644 --- a/crates/call/src/room.rs +++ b/crates/call/src/room.rs @@ -50,7 +50,9 @@ impl Entity for Room { type Event = Event; fn release(&mut self, _: &mut MutableAppContext) { - self.client.send(proto::LeaveRoom { id: self.id }).log_err(); + if self.status.is_online() { + self.client.send(proto::LeaveRoom { id: self.id }).log_err(); + } } } @@ -210,6 +212,7 @@ impl Room { self.pending_participants.clear(); self.participant_user_ids.clear(); self.subscriptions.clear(); + self.live_kit_room.take(); self.client.send(proto::LeaveRoom { id: self.id })?; Ok(()) } @@ -630,4 +633,8 @@ impl RoomStatus { pub fn is_offline(&self) -> bool { matches!(self, RoomStatus::Offline) } + + pub fn is_online(&self) -> bool { + matches!(self, RoomStatus::Online) + } } diff --git a/crates/live_kit_client/LiveKitBridge/Sources/LiveKitBridge/LiveKitBridge.swift b/crates/live_kit_client/LiveKitBridge/Sources/LiveKitBridge/LiveKitBridge.swift index 1c49109fc50045de5b2bb0dcb39fbc0ef994c09e..dadc2fdb100ffdc37df6713588707a24909c812d 100644 --- a/crates/live_kit_client/LiveKitBridge/Sources/LiveKitBridge/LiveKitBridge.swift +++ b/crates/live_kit_client/LiveKitBridge/Sources/LiveKitBridge/LiveKitBridge.swift @@ -83,6 +83,12 @@ public func LKRoomConnect(room: UnsafeRawPointer, url: CFString, token: CFString } } +@_cdecl("LKRoomDisconnect") +public func LKRoomDisconnect(room: UnsafeRawPointer) { + let room = Unmanaged.fromOpaque(room).takeUnretainedValue() + room.disconnect() +} + @_cdecl("LKRoomPublishVideoTrack") public func LKRoomPublishVideoTrack(room: UnsafeRawPointer, track: UnsafeRawPointer, callback: @escaping @convention(c) (UnsafeRawPointer, CFString?) -> Void, callback_data: UnsafeRawPointer) { let room = Unmanaged.fromOpaque(room).takeUnretainedValue() diff --git a/crates/live_kit_client/src/live_kit_client.rs b/crates/live_kit_client/src/live_kit_client.rs index af46fbb2e06815c651b31a062dd36c69aeb1b525..07075dcee8ca8b1ce69b58e4d22093b4449f2d21 100644 --- a/crates/live_kit_client/src/live_kit_client.rs +++ b/crates/live_kit_client/src/live_kit_client.rs @@ -43,6 +43,7 @@ extern "C" { callback: extern "C" fn(*mut c_void, CFStringRef), callback_data: *mut c_void, ); + fn LKRoomDisconnect(room: *const c_void); fn LKRoomPublishVideoTrack( room: *const c_void, track: *const c_void, @@ -195,7 +196,10 @@ impl Room { impl Drop for Room { fn drop(&mut self) { - unsafe { LKRelease(self.native_room) } + unsafe { + LKRoomDisconnect(self.native_room); + LKRelease(self.native_room); + } } }