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.
This commit is contained in:
cogwheel0
2025-10-10 20:56:28 +05:30
parent 4eb1191748
commit 8b26484ec5
2 changed files with 6 additions and 3 deletions

View File

@@ -266,7 +266,6 @@ class BackgroundStreamingHandler(private val activity: MainActivity) : MethodCal
}
private fun startBackgroundExecution(streamIds: List<String>, requiresMic: Boolean) {
activeStreams.clear()
activeStreams.addAll(streamIds)
streamsRequiringMic.retainAll(activeStreams)
if (requiresMic) {

View File

@@ -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()
}