From 8b26484ec5987984e472940d5d076586e80ec08b Mon Sep 17 00:00:00 2001 From: cogwheel0 <172976095+cogwheel0@users.noreply.github.com> Date: Fri, 10 Oct 2025 20:56:28 +0530 Subject: [PATCH] refactor: improve background streaming handler by optimizing active stream management - Removed unnecessary clearing of active streams in the Android implementation, allowing for more efficient management of stream IDs. - Updated iOS implementation to use formUnion and formIntersection for better handling of active and microphone streams, enhancing performance and clarity in stream management. - Ensured that microphone activation only occurs when there are active microphone streams, improving resource utilization. --- .../app/cogwheel/conduit/BackgroundStreamingHandler.kt | 1 - ios/Runner/AppDelegate.swift | 8 ++++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/android/app/src/main/kotlin/app/cogwheel/conduit/BackgroundStreamingHandler.kt b/android/app/src/main/kotlin/app/cogwheel/conduit/BackgroundStreamingHandler.kt index e07ea85..a05d9cd 100644 --- a/android/app/src/main/kotlin/app/cogwheel/conduit/BackgroundStreamingHandler.kt +++ b/android/app/src/main/kotlin/app/cogwheel/conduit/BackgroundStreamingHandler.kt @@ -266,7 +266,6 @@ class BackgroundStreamingHandler(private val activity: MainActivity) : MethodCal } private fun startBackgroundExecution(streamIds: List, requiresMic: Boolean) { - activeStreams.clear() activeStreams.addAll(streamIds) streamsRequiringMic.retainAll(activeStreams) if (requiresMic) { diff --git a/ios/Runner/AppDelegate.swift b/ios/Runner/AppDelegate.swift index a23ac58..a509cec 100644 --- a/ios/Runner/AppDelegate.swift +++ b/ios/Runner/AppDelegate.swift @@ -130,9 +130,13 @@ class BackgroundStreamingHandler: NSObject { } private func startBackgroundExecution(streamIds: [String], requiresMic: Bool) { - activeStreams = Set(streamIds) + activeStreams.formUnion(streamIds) + microphoneStreams.formIntersection(activeStreams) if requiresMic { - microphoneStreams = microphoneStreams.union(streamIds) + microphoneStreams.formUnion(streamIds) + } + + if !microphoneStreams.isEmpty { VoiceBackgroundAudioManager.shared.activate() }