Skip to content

Commit

Permalink
Use one instance for the microphoneChecker to avoid the overhead of i…
Browse files Browse the repository at this point in the history
…ts creation
  • Loading branch information
ipavlidakis committed Oct 4, 2023
1 parent 253bc46 commit b6c17b3
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 6 deletions.
1 change: 1 addition & 0 deletions DemoApp/Sources/Components/DemoAppViewFactory.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ final class DemoAppViewFactory: ViewFactory {
static let shared = DemoAppViewFactory()

@Injected(\.colors) var colors
@Injected(\.microphoneChecker) var microphoneChecker

func makeWaitingLocalUserView(viewModel: CallViewModel) -> some View {
DemoWaitingLocalUserView(viewFactory: self, viewModel: viewModel)
Expand Down
4 changes: 2 additions & 2 deletions DemoApp/Sources/Views/CustomCallView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ import SwiftUI
struct CustomCallView<Factory: ViewFactory>: View {

@Injected(\.colors) var colors
@Injected(\.microphoneChecker) var microphoneChecker

var viewFactory: Factory
@ObservedObject var viewModel: CallViewModel

@StateObject var microphoneChecker = MicrophoneChecker()

@State var mutedIndicatorShown = false

var body: some View {
Expand Down
2 changes: 1 addition & 1 deletion Sources/StreamVideo/Utils/ThermalStateObserver.swift
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ final class ThermalStateObserver: ObservableObject, ThermalStateObserving {
}
}

/// Provides the default value of the `Appearance` class.
/// Provides the default value of the `ThermalStateObserving` protocol.
public struct ThermalStateObserverKey: InjectionKey {
public static var currentValue: any ThermalStateObserving = ThermalStateObserver.shared
}
Expand Down
17 changes: 17 additions & 0 deletions Sources/StreamVideoSwiftUI/CallingViews/MicrophoneChecker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -173,3 +173,20 @@ protocol AudioSessionProtocol {
}

extension AVAudioSession: AudioSessionProtocol {}

/// Provides the default value of the `ThermalStateObserving` protocol.
public struct MicrophoneCheckerKey: InjectionKey {
public static var currentValue: MicrophoneChecker = MicrophoneChecker()
}

extension InjectedValues {

public var microphoneChecker: MicrophoneChecker {
get {
Self[MicrophoneCheckerKey.self]
}
set {
Self[MicrophoneCheckerKey.self] = newValue
}
}
}
4 changes: 2 additions & 2 deletions Sources/StreamVideoSwiftUI/CallingViews/PreJoiningView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import SwiftUI
public struct LobbyView: View {

@StateObject var viewModel: LobbyViewModel
@StateObject var microphoneChecker = MicrophoneChecker()
@Injected(\.microphoneChecker) var microphoneChecker

var callId: String
var callType: String
@Binding var callSettings: CallSettings
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ struct LobbyView_iOS13: View {

@ObservedObject var callViewModel: CallViewModel
@BackportStateObject var viewModel: LobbyViewModel
@BackportStateObject var microphoneChecker = MicrophoneChecker()
@Injected(\.microphoneChecker) var microphoneChecker: MicrophoneChecker

var callId: String
var callType: String
Expand Down

0 comments on commit b6c17b3

Please sign in to comment.