Skip to content

Commit

Permalink
Merge pull request #202 from eofster/delay-setting-audio-devices-afte…
Browse files Browse the repository at this point in the history
…r-system-audio-devices-update

Delay setting audio devices after system audio devices update
  • Loading branch information
eofster committed Apr 16, 2016
2 parents c08d860 + 4e72d00 commit 417d721
Show file tree
Hide file tree
Showing 25 changed files with 239 additions and 360 deletions.
70 changes: 23 additions & 47 deletions Telephone.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions Telephone/AKSIPUserAgent+UserAgent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
import UseCases

extension AKSIPUserAgent: UserAgent {
public var hasActiveCalls: Bool {
return started && activeCallsCount > 0
}

public func audioDevices() throws -> [UserAgentAudioDevice] {
if started {
return try UserAgentAudioDevices().all
Expand Down
29 changes: 14 additions & 15 deletions Telephone/CompositionRoot.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,36 +55,35 @@ class CompositionRoot: NSObject {
delegate: conditionalRingtonePlaybackInteractorDelegate
)

let userAgentSoundIOSelection = DelayingUserAgentSoundIOSelectionInteractor(
interactor: UserAgentSoundIOSelectionInteractor(
repository: audioDevices,
userAgent: userAgent,
userDefaults: userDefaults
),
userAgent: userAgent
)

preferencesController = PreferencesController(
delegate: preferencesControllerDelegate,
soundPreferencesViewEventTarget: DefaultSoundPreferencesViewEventTarget(
interactorFactory: interactorFactory,
presenterFactory: PresenterFactory(),
userAgentSoundIOSelection: userAgentSoundIOSelection,
ringtoneOutputUpdate: RingtoneOutputUpdateInteractor(playback: ringtonePlayback),
ringtoneSoundPlayback: DefaultSoundPlaybackInteractor(factory: userDefaultsSoundFactory),
userAgent: userAgent
ringtoneSoundPlayback: DefaultSoundPlaybackInteractor(factory: userDefaultsSoundFactory)
)
)

userAgentNotificationsToEventTargetAdapter = UserAgentNotificationsToEventTargetAdapter(
target: UserAgentSoundIOSelector(factory: interactorFactory),
target: userAgentSoundIOSelection,
userAgent: userAgent
)
devicesChangeEventSource = SystemAudioDevicesChangeEventSource(
target: SystemAudioDevicesChangeEventTargetComposite(
targets: [
UserAgentAudioDeviceUpdater(
interactor: UserAgentAudioDeviceUpdateAndSoundIOSelectionInteractor(
update: UserAgentAudioDeviceUpdateInteractor(
userAgent: userAgent
),
selection: UserAgentSoundIOSelectionInteractor(
repository: audioDevices,
userAgent: userAgent,
userDefaults: userDefaults
)
)
),
UserAgentAudioDeviceUpdateInteractor(userAgent: userAgent),
userAgentSoundIOSelection,
PreferencesSoundIOUpdater(preferences: preferencesController)
]
),
Expand Down
8 changes: 0 additions & 8 deletions Telephone/DefaultInteractorFactory.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,6 @@ class DefaultInteractorFactory {
}

extension DefaultInteractorFactory: InteractorFactory {
func createUserAgentSoundIOSelectionInteractor(userAgent userAgent: UserAgent) -> ThrowingInteractor {
return UserAgentSoundIOSelectionInteractor(
repository: repository,
userAgent: userAgent,
userDefaults: userDefaults
)
}

func createUserDefaultsSoundIOLoadInteractor(output output: UserDefaultsSoundIOLoadInteractorOutput) -> ThrowingInteractor {
return UserDefaultsSoundIOLoadInteractor(
repository: repository,
Expand Down
30 changes: 11 additions & 19 deletions Telephone/DefaultSoundPreferencesViewEventTarget.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,20 @@ import UseCases
class DefaultSoundPreferencesViewEventTarget: NSObject {
let interactorFactory: InteractorFactory
let presenterFactory: PresenterFactory
let userAgentSoundIOSelection: Interactor
let ringtoneOutputUpdate: ThrowingInteractor
let ringtoneSoundPlayback: SoundPlaybackInteractor
let userAgent: UserAgent

init(interactorFactory: InteractorFactory,
presenterFactory: PresenterFactory,
ringtoneOutputUpdate: ThrowingInteractor,
ringtoneSoundPlayback: SoundPlaybackInteractor,
userAgent: UserAgent) {
self.interactorFactory = interactorFactory
self.presenterFactory = presenterFactory
self.ringtoneOutputUpdate = ringtoneOutputUpdate
self.ringtoneSoundPlayback = ringtoneSoundPlayback
self.userAgent = userAgent
presenterFactory: PresenterFactory,
userAgentSoundIOSelection: Interactor,
ringtoneOutputUpdate: ThrowingInteractor,
ringtoneSoundPlayback: SoundPlaybackInteractor) {
self.interactorFactory = interactorFactory
self.presenterFactory = presenterFactory
self.userAgentSoundIOSelection = userAgentSoundIOSelection
self.ringtoneOutputUpdate = ringtoneOutputUpdate
self.ringtoneSoundPlayback = ringtoneSoundPlayback
}
}

Expand All @@ -51,7 +51,7 @@ extension DefaultSoundPreferencesViewEventTarget: SoundPreferencesViewEventTarge
updateUserDefaultsWithSoundIO(
PresentationSoundIO(input: input, output: output, ringtoneOutput: ringtoneOutput)
)
selectUserAgentAudioDevicesOrLogError()
userAgentSoundIOSelection.execute()
updateRingtoneOutputOrLogError()
}

Expand All @@ -76,14 +76,6 @@ extension DefaultSoundPreferencesViewEventTarget: SoundPreferencesViewEventTarge
interactorFactory.createUserDefaultsSoundIOSaveInteractor(soundIO: soundIO).execute()
}

private func selectUserAgentAudioDevicesOrLogError() {
do {
try interactorFactory.createUserAgentSoundIOSelectionInteractor(userAgent: userAgent).execute()
} catch {
print("Could not select user agent audio devices: \(error)")
}
}

private func updateRingtoneOutputOrLogError() {
do {
try ringtoneOutputUpdate.execute()
Expand Down
41 changes: 0 additions & 41 deletions Telephone/UserAgentAudioDeviceUpdater.swift

This file was deleted.

62 changes: 0 additions & 62 deletions Telephone/UserAgentSoundIOSelector.swift

This file was deleted.

11 changes: 0 additions & 11 deletions TelephoneTests/DefaultInteractorFactoryTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,6 @@ class DefaultInteractorFactoryTests: XCTestCase {
sut = DefaultInteractorFactory(repository: repository, userDefaults: userDefaults)
}

func testCanCreateUserAgentSoundIOSelectionInteractor() {
let userAgent = UserAgentSpy()

let result = sut.createUserAgentSoundIOSelectionInteractor(userAgent: userAgent) as! UserAgentSoundIOSelectionInteractor

XCTAssertNotNil(result)
XCTAssertTrue(result.repository === repository)
XCTAssertTrue(result.userAgent === userAgent)
XCTAssertTrue(result.userDefaults === userDefaults)
}

func testCanCreateUserDefaultsSoundIOLoadInteractor() {
let output = UserDefaultsSoundIOLoadInteractorOutputSpy()

Expand Down
12 changes: 5 additions & 7 deletions TelephoneTests/DefaultSoundPreferencesViewEventTargetTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,23 @@ import XCTest

class DefaultSoundPreferencesViewEventTargetTests: XCTestCase {
private var factory: InteractorFactorySpy!
private var userAgentSoundIOSelection: InteractorSpy!
private var ringtoneOutputUpdate: ThrowingInteractorSpy!
private var soundPlayback: SoundPlaybackInteractorSpy!
private var sut: DefaultSoundPreferencesViewEventTarget!

override func setUp() {
super.setUp()
factory = InteractorFactorySpy()
userAgentSoundIOSelection = InteractorSpy()
ringtoneOutputUpdate = ThrowingInteractorSpy()
soundPlayback = SoundPlaybackInteractorSpy()
sut = DefaultSoundPreferencesViewEventTarget(
interactorFactory: factory,
presenterFactory: PresenterFactory(),
userAgentSoundIOSelection: userAgentSoundIOSelection,
ringtoneOutputUpdate: ringtoneOutputUpdate,
ringtoneSoundPlayback: soundPlayback,
userAgent: UserAgentSpy()
ringtoneSoundPlayback: soundPlayback
)
}

Expand All @@ -60,7 +62,6 @@ class DefaultSoundPreferencesViewEventTargetTests: XCTestCase {
func testExecutesUserDefaultsSoundIOSaveInteractorWithExpectedArgumentsOnSoundIOChange() {
let interactor = InteractorSpy()
factory.stubWithUserDefaultsSoundIOSave(interactor)
factory.stubWithUserAgentSoundIOSelection(ThrowingInteractorSpy())
let soundIO = PresentationSoundIO(input: "input", output: "output1", ringtoneOutput: "output2")

sut.viewDidChangeSoundIO(
Expand All @@ -72,17 +73,14 @@ class DefaultSoundPreferencesViewEventTargetTests: XCTestCase {
}

func testExecutesUserAgentSoundIOSelectionInteractorOnSoundIOChange() {
let interactor = ThrowingInteractorSpy()
factory.stubWithUserAgentSoundIOSelection(interactor)
factory.stubWithUserDefaultsSoundIOSave(InteractorSpy())

sut.viewDidChangeSoundIO(input: "any-input", output: "any-output", ringtoneOutput: "any-output")

XCTAssertTrue(interactor.didCallExecute)
XCTAssertTrue(userAgentSoundIOSelection.didCallExecute)
}

func testExecutesRingtoneOutputUpdateInteractorOnSoundIOChange() {
factory.stubWithUserAgentSoundIOSelection(ThrowingInteractorSpy())
factory.stubWithUserDefaultsSoundIOSave(InteractorSpy())

sut.viewDidChangeSoundIO(input: "any-input", output: "any-output", ringtoneOutput: "any-output")
Expand Down
43 changes: 0 additions & 43 deletions TelephoneTests/UserAgentAudioDeviceUpdaterTests.swift

This file was deleted.

Loading

0 comments on commit 417d721

Please sign in to comment.