From df0629ae6c7a9279e94545124bcbb3c44b550268 Mon Sep 17 00:00:00 2001 From: Hiroshi Horie <548776+hiroshihorie@users.noreply.github.com> Date: Fri, 13 Sep 2024 03:58:49 +0900 Subject: [PATCH] Reorder unmute sequence (#483) --- Sources/LiveKit/Track/AudioManager.swift | 3 ++- Sources/LiveKit/Track/Track.swift | 8 ++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/Sources/LiveKit/Track/AudioManager.swift b/Sources/LiveKit/Track/AudioManager.swift index 8d0187ce8..0a9b72ba7 100644 --- a/Sources/LiveKit/Track/AudioManager.swift +++ b/Sources/LiveKit/Track/AudioManager.swift @@ -203,9 +203,10 @@ public class AudioManager: Loggable { // trigger events when state mutates _state.onDidMutate = { [weak self] newState, oldState in guard let self else { return } + // Return if state is equal. + guard newState != oldState else { return } self.log("\(oldState) -> \(newState)") - #if os(iOS) let configureFunc = newState.customConfigureFunc ?? self.defaultConfigureAudioSessionFunc configureFunc(newState, oldState) diff --git a/Sources/LiveKit/Track/Track.swift b/Sources/LiveKit/Track/Track.swift index 039bde41f..8b2252a8a 100644 --- a/Sources/LiveKit/Track/Track.swift +++ b/Sources/LiveKit/Track/Track.swift @@ -351,16 +351,16 @@ extension Track { func _mute() async throws { // LocalTrack only, already muted guard self is LocalTrack, !isMuted else { return } - try await disable() - try await stop() + try await disable() // Disable track first + try await stop() // Stop track set(muted: true, shouldSendSignal: true) } func _unmute() async throws { // LocalTrack only, already un-muted guard self is LocalTrack, isMuted else { return } - try await enable() - try await start() + try await start() // Start track first (Configure session first if local audio) + try await enable() // Enable track set(muted: false, shouldSendSignal: true) } }