From 572e6e0250935c5cb9dacc07da58b3dfd537eb58 Mon Sep 17 00:00:00 2001 From: Aravind Raveendran Date: Mon, 14 Oct 2024 15:59:19 +1100 Subject: [PATCH] Disable track on inactive event This gives app developer better handle of which track to enable when they come back active --- .../Sources/RTSCore/Models/SourceBuilder.swift | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/LocalPackages/RTSCore/Sources/RTSCore/Models/SourceBuilder.swift b/LocalPackages/RTSCore/Sources/RTSCore/Models/SourceBuilder.swift index bb2805f3..2fb80033 100644 --- a/LocalPackages/RTSCore/Sources/RTSCore/Models/SourceBuilder.swift +++ b/LocalPackages/RTSCore/Sources/RTSCore/Models/SourceBuilder.swift @@ -160,11 +160,16 @@ private extension SourceBuilder { guard !Task.isCancelled else { return } switch activityEvent { case .active: - Self.logger.debug("👨‍🔧 Audio track for \(sourceId) is active, \(track.isActive)") + Self.logger.debug("👨‍🔧 Audio track for \(sourceId) is active") self.audioTrackStateUpdateSubject.send(sourceId) case .inactive: - Self.logger.debug("👨‍🔧 Audio track for \(sourceId) is inactive, \(track.isActive)") + Self.logger.debug("👨‍🔧 Audio track for \(sourceId) is inactive") + do { + try await track.disable() + } catch { + Self.logger.debug("👨‍🔧 Error disabling audio track for \(sourceId), \(error.localizedDescription)") + } self.audioTrackStateUpdateSubject.send(sourceId) } } @@ -184,11 +189,16 @@ private extension SourceBuilder { guard !Task.isCancelled else { return } switch activityEvent { case .active: - Self.logger.debug("👨‍🔧 Video track for \(sourceId) is active, \(track.isActive)") + Self.logger.debug("👨‍🔧 Video track for \(sourceId) is active") self.videoTrackStateUpdateSubject.send(sourceId) case .inactive: - Self.logger.debug("👨‍🔧 Video track for \(sourceId) is inactive, \(track.isActive)") + Self.logger.debug("👨‍🔧 Video track for \(sourceId) is inactive") + do { + try await track.disable() + } catch { + Self.logger.debug("👨‍🔧 Error disabling video track for \(sourceId), \(error.localizedDescription)") + } self.videoTrackStateUpdateSubject.send(sourceId) } }