- remove dead code
- rename vars
- add coments

// FREEBIE
pull/1/head
Michael Kirk 8 years ago
parent a59eb25aef
commit 4e11e90ebb

@ -41,8 +41,7 @@ class CallViewController: UIViewController, CallObserver, CallServiceObserver, R
var ongoingCallView: UIView! var ongoingCallView: UIView!
var hangUpButton: UIButton! var hangUpButton: UIButton!
var audioRouteButton: UIButton! var audioSourceButton: UIButton!
var soundRouteButton: UIButton!
var audioModeMuteButton: UIButton! var audioModeMuteButton: UIButton!
var audioModeVideoButton: UIButton! var audioModeVideoButton: UIButton!
var videoModeMuteButton: UIButton! var videoModeMuteButton: UIButton!
@ -87,28 +86,21 @@ class CallViewController: UIViewController, CallObserver, CallServiceObserver, R
var settingsNagView: UIView! var settingsNagView: UIView!
var settingsNagDescriptionLabel: UILabel! var settingsNagDescriptionLabel: UILabel!
// MARK: Audio Routing // MARK: Audio Source
// var hasAlternateAudioRoutes = false { var hasAlternateAudioSources: Bool {
// didSet { Logger.info("\(TAG) available audio routes count: \(allAudioSources.count)")
// if oldValue != hasAlternateAudioRoutes {
// updateCallUI(callState: call.state)
// }
// }
// }
// TODO use "audioSource" terminalogy rather than input/output/route
var hasAlternateAudioRoutes: Bool {
Logger.info("\(TAG) available audio routes count: \(allAvailableAudioRoutes.count)")
// internal mic and speakerphone will be the first two, any more than one indicates e.g. an attached bluetooth device. // internal mic and speakerphone will be the first two, any more than one indicates e.g. an attached bluetooth device.
// TODO is this sufficient? Are their devices w/ bluetooth but no external speaker? e.g. ipod? // TODO is this sufficient? Are their devices w/ bluetooth but no external speaker? e.g. ipod?
return allAvailableAudioRoutes.count > 2 return allAudioSources.count > 2
} }
var allAvailableAudioRoutes: Set<AudioSource> var allAudioSources: Set<AudioSource>
var availableAudioRoutes: Set<AudioSource> { var appropriateAudioSources: Set<AudioSource> {
if call.hasLocalVideo { if call.hasLocalVideo {
let forVideo = allAvailableAudioRoutes.filter { audioSource in let appropriateForVideo = allAudioSources.filter { audioSource in
if audioSource.isBuiltInSpeaker { if audioSource.isBuiltInSpeaker {
return true return true
} else { } else {
@ -116,12 +108,14 @@ class CallViewController: UIViewController, CallObserver, CallServiceObserver, R
owsFail("Only built in speaker should be lacking a port description.") owsFail("Only built in speaker should be lacking a port description.")
return false return false
} }
// Don't use receiver when video is enabled. Only bluetooth or speaker
return portDescription.portType != AVAudioSessionPortBuiltInMic return portDescription.portType != AVAudioSessionPortBuiltInMic
} }
} }
return Set(forVideo) return Set(appropriateForVideo)
} else { } else {
return allAvailableAudioRoutes return allAudioSources
} }
} }
@ -150,7 +144,7 @@ class CallViewController: UIViewController, CallObserver, CallServiceObserver, R
required init?(coder aDecoder: NSCoder) { required init?(coder aDecoder: NSCoder) {
contactsManager = Environment.getCurrent().contactsManager contactsManager = Environment.getCurrent().contactsManager
callUIAdapter = Environment.getCurrent().callUIAdapter callUIAdapter = Environment.getCurrent().callUIAdapter
allAvailableAudioRoutes = Set(callUIAdapter.audioService.availableInputs) allAudioSources = Set(callUIAdapter.audioService.availableInputs)
super.init(coder: aDecoder) super.init(coder: aDecoder)
observeNotifications() observeNotifications()
} }
@ -158,7 +152,7 @@ class CallViewController: UIViewController, CallObserver, CallServiceObserver, R
required init() { required init() {
contactsManager = Environment.getCurrent().contactsManager contactsManager = Environment.getCurrent().contactsManager
callUIAdapter = Environment.getCurrent().callUIAdapter callUIAdapter = Environment.getCurrent().callUIAdapter
allAvailableAudioRoutes = Set(callUIAdapter.audioService.availableInputs) allAudioSources = Set(callUIAdapter.audioService.availableInputs)
super.init(nibName: nil, bundle: nil) super.init(nibName: nil, bundle: nil)
observeNotifications() observeNotifications()
} }
@ -354,8 +348,8 @@ class CallViewController: UIViewController, CallObserver, CallServiceObserver, R
// textMessageButton = createButton(imageName:"message-active-wide", // textMessageButton = createButton(imageName:"message-active-wide",
// action:#selector(didPressTextMessage)) // action:#selector(didPressTextMessage))
audioRouteButton = createButton(imageName:"audio-call-speaker-inactive", audioSourceButton = createButton(imageName:"audio-call-speaker-inactive",
action:#selector(didPressAudioRoute)) action:#selector(didPressAudioSource))
hangUpButton = createButton(imageName:"hangup-active-wide", hangUpButton = createButton(imageName:"hangup-active-wide",
action:#selector(didPressHangup)) action:#selector(didPressHangup))
audioModeMuteButton = createButton(imageName:"audio-call-mute-inactive", audioModeMuteButton = createButton(imageName:"audio-call-mute-inactive",
@ -373,7 +367,7 @@ class CallViewController: UIViewController, CallObserver, CallServiceObserver, R
setButtonSelectedImage(button: videoModeVideoButton, imageName: "video-video-selected") setButtonSelectedImage(button: videoModeVideoButton, imageName: "video-video-selected")
ongoingCallView = createContainerForCallControls(controlGroups : [ ongoingCallView = createContainerForCallControls(controlGroups : [
[audioModeMuteButton, audioRouteButton, audioModeVideoButton ], [audioModeMuteButton, audioSourceButton, audioModeVideoButton ],
[videoModeMuteButton, hangUpButton, videoModeVideoButton ] [videoModeMuteButton, hangUpButton, videoModeVideoButton ]
]) ])
} }
@ -382,10 +376,10 @@ class CallViewController: UIViewController, CallObserver, CallServiceObserver, R
AssertIsOnMainThread() AssertIsOnMainThread()
// TODO unnecessary? // TODO unnecessary?
let availableInputs = callUIAdapter.audioService.availableInputs let availableInputs = callUIAdapter.audioService.availableInputs
self.allAvailableAudioRoutes.formUnion(availableInputs) self.allAudioSources.formUnion(availableInputs)
} }
func presentAudioRoutePicker() { func presentAudioSourcePicker() {
Logger.info("\(TAG) in \(#function)") Logger.info("\(TAG) in \(#function)")
AssertIsOnMainThread() AssertIsOnMainThread()
@ -395,7 +389,7 @@ class CallViewController: UIViewController, CallObserver, CallServiceObserver, R
actionSheetController.addAction(dismissAction) actionSheetController.addAction(dismissAction)
let currentAudioSource = callUIAdapter.audioService.currentAudioSource(call: self.call) let currentAudioSource = callUIAdapter.audioService.currentAudioSource(call: self.call)
for audioSource in self.availableAudioRoutes { for audioSource in self.appropriateAudioSources {
// TODO add image // TODO add image
let routeAudioAction = UIAlertAction(title: audioSource.localizedName, style: .default) { _ in let routeAudioAction = UIAlertAction(title: audioSource.localizedName, style: .default) { _ in
// Disable any speakerphone // Disable any speakerphone
@ -413,27 +407,9 @@ class CallViewController: UIViewController, CallObserver, CallServiceObserver, R
actionSheetController.addAction(routeAudioAction) actionSheetController.addAction(routeAudioAction)
} }
// if let builtInMicrophoneSource = self.callUIAdapter.audioService.builtInMicrophoneSource {
// Speakerphone is handled separately from the other audio routes as it doesn't appear as an "input"
// let speakerphoneAction = UIAlertAction(title:
// style: .default) { _ in
// self.updateAudioOutput(audioSource: builtInMicrophoneSource)
//
// }
// actionSheetController.addAction(speakerphoneAction)
// } else {
// owsFail("unable to find built in microphone source")
// }
self.present(actionSheetController, animated: true) self.present(actionSheetController, animated: true)
} }
func updateAudioOutput(audioSource: AudioSource) {
Logger.info("\(TAG) in \(#function) with audioSource: \(audioSource)")
// This seems like overreach. audioservice as property on CVC?
}
func setButtonSelectedImage(button: UIButton, imageName: String) { func setButtonSelectedImage(button: UIButton, imageName: String) {
let image = UIImage(named:imageName) let image = UIImage(named:imageName)
assert(image != nil) assert(image != nil)
@ -806,33 +782,30 @@ class CallViewController: UIViewController, CallObserver, CallServiceObserver, R
callStatusLabel.isHidden = false callStatusLabel.isHidden = false
} }
// Handle audio source picking interface (blue tooth) // Audio Source Handling (bluetooth)
if self.hasAlternateAudioRoutes { if self.hasAlternateAudioSources {
// TODO proper image
Logger.info("\(TAG) in \(#function) setting alternate audio route image")
// With bluetooth, button does not stay selected. Pressing it pops an actionsheet // With bluetooth, button does not stay selected. Pressing it pops an actionsheet
// and the button should immediately "unselect". // and the button should immediately "unselect".
audioRouteButton.isSelected = false audioSourceButton.isSelected = false
if hasLocalVideo { if hasLocalVideo {
audioRouteButton.setImage(#imageLiteral(resourceName: "ic_speaker_bluetooth_inactive_video_mode"), for: .normal) audioSourceButton.setImage(#imageLiteral(resourceName: "ic_speaker_bluetooth_inactive_video_mode"), for: .normal)
audioRouteButton.setImage(#imageLiteral(resourceName: "ic_speaker_bluetooth_inactive_video_mode"), for: .selected) audioSourceButton.setImage(#imageLiteral(resourceName: "ic_speaker_bluetooth_inactive_video_mode"), for: .selected)
} else { } else {
audioRouteButton.setImage(#imageLiteral(resourceName: "ic_speaker_bluetooth_inactive_audio_mode"), for: .normal) audioSourceButton.setImage(#imageLiteral(resourceName: "ic_speaker_bluetooth_inactive_audio_mode"), for: .normal)
audioRouteButton.setImage(#imageLiteral(resourceName: "ic_speaker_bluetooth_inactive_audio_mode"), for: .selected) audioSourceButton.setImage(#imageLiteral(resourceName: "ic_speaker_bluetooth_inactive_audio_mode"), for: .selected)
} }
audioRouteButton.isHidden = false audioSourceButton.isHidden = false
} else { } else {
// No bluetooth audio detected // No bluetooth audio detected
audioRouteButton.isSelected = call.isSpeakerphoneEnabled audioSourceButton.isSelected = call.isSpeakerphoneEnabled
audioRouteButton.setImage(#imageLiteral(resourceName: "audio-call-speaker-inactive"), for: .normal) audioSourceButton.setImage(#imageLiteral(resourceName: "audio-call-speaker-inactive"), for: .normal)
audioRouteButton.setImage(#imageLiteral(resourceName: "audio-call-speaker-active"), for: .selected) audioSourceButton.setImage(#imageLiteral(resourceName: "audio-call-speaker-active"), for: .selected)
// If there's no bluetooth, we always use speakerphone, so no need for // If there's no bluetooth, we always use speakerphone, so no need for
// a button, giving more screen back for the video. // a button, giving more screen back for the video.
audioRouteButton.isHidden = hasLocalVideo audioSourceButton.isHidden = hasLocalVideo
} }
// Dismiss Handling // Dismiss Handling
@ -892,11 +865,11 @@ class CallViewController: UIViewController, CallObserver, CallServiceObserver, R
} }
} }
func didPressAudioRoute(sender button: UIButton) { func didPressAudioSource(sender button: UIButton) {
Logger.info("\(TAG) called \(#function)") Logger.info("\(TAG) called \(#function)")
if self.hasAlternateAudioRoutes { if self.hasAlternateAudioSources {
presentAudioRoutePicker() presentAudioSourcePicker()
} else { } else {
didPressSpeakerphone(sender: button) didPressSpeakerphone(sender: button)
} }

@ -9,17 +9,11 @@ public let CallAudioServiceSessionChanged = Notification.Name("CallAudioServiceS
struct AudioSource: Hashable { struct AudioSource: Hashable {
// let name: String
let image: UIImage let image: UIImage
let localizedName: String let localizedName: String
let portDescription: AVAudioSessionPortDescription? let portDescription: AVAudioSessionPortDescription?
let isBuiltInSpeaker: Bool let isBuiltInSpeaker: Bool
// init(name: String, image: UIImage, isCurrentRoute: Bool) {
//
// }
//
init(localizedName: String, image: UIImage, isBuiltInSpeaker: Bool, portDescription: AVAudioSessionPortDescription? = nil) { init(localizedName: String, image: UIImage, isBuiltInSpeaker: Bool, portDescription: AVAudioSessionPortDescription? = nil) {
self.localizedName = localizedName self.localizedName = localizedName
self.image = image self.image = image
@ -385,69 +379,24 @@ struct AudioSource: Hashable {
// MARK - AudioSession MGMT // MARK - AudioSession MGMT
// TODO move this to CallAudioSession? // TODO move this to CallAudioSession?
var hasAlternateAudioRoutes: Bool {
// let session = AVAudioSession.sharedInstance()
// PROBLEM: doesn't list bluetooth when speakerphone is enabled.
// guard let availableInputs = session.availableInputs else {
// // I'm not sure when this would happen.
// owsFail("No available inputs or inputs not ready")
// return false
// }
//
// let availableInputs = session.currentRoute.inputs
Logger.info("\(TAG) in \(#function) availableInputs: \(availableInputs)")
for input in self.availableInputs {
if input.portDescription?.portType == AVAudioSessionPortBluetoothHFP {
return true
}
}
return false
}
// Note this method is sensitive to the current audio session configuration. // Note this method is sensitive to the current audio session configuration.
// Specifically if you call it while speakerphone is enabled you won't see // Specifically if you call it while speakerphone is enabled you won't see
// any connected bluetooth routes. // any connected bluetooth routes.
var availableInputs: [AudioSource] { var availableInputs: [AudioSource] {
let session = AVAudioSession.sharedInstance() let session = AVAudioSession.sharedInstance()
// guard let availableOutputs = session.outputDataSources else {
// Maybe... shows the bluetooth AND the receiver (but not speaker)
// PROBLEM: doesn't list bluetooth when speakerphone is enabled.
guard let availableInputs = session.availableInputs else { guard let availableInputs = session.availableInputs else {
// I'm not sure when this would happen. // I'm not sure when this would happen.
owsFail("No available inputs or inputs not ready") owsFail("No available inputs or inputs not ready")
return [AudioSource.builtInSpeaker] return [AudioSource.builtInSpeaker]
} }
// PROBLEM: doesn't list iphone internal
// PROBLEM: doesn't list bluetooth until toggling speakerphone on/off
// let availableInputs = session.currentRoute.inputs
// let availableInputs = session.currentRoute.outputs
// NOPE. only shows the single active one. (e.g. blue tooth XOR receive)
// let availableOutputs = session.currentRoute.outputs
Logger.info("\(TAG) in \(#function) availableInputs: \(availableInputs)") Logger.info("\(TAG) in \(#function) availableInputs: \(availableInputs)")
return [AudioSource.builtInSpeaker] + availableInputs.map { portDescription in return [AudioSource.builtInSpeaker] + availableInputs.map { portDescription in
// TODO get proper image
// TODO set isCurrentRoute correctly
// return AudioSource(name: output.dataSourceName, image:#imageLiteral(resourceName: "button_phone_white"), isCurrentRoute: false)
// return AudioSource(name: output.portName, image:#imageLiteral(resourceName: "button_phone_white"), isCurrentRoute: false)
return AudioSource(portDescription: portDescription) return AudioSource(portDescription: portDescription)
} }
} }
// var builtInMicrophoneSource: AudioSource? {
// availableInputs.first { source -> Bool in
// if source.uid =
// }
// }
func currentAudioSource(call: SignalCall) -> AudioSource? { func currentAudioSource(call: SignalCall) -> AudioSource? {
if call.isSpeakerphoneEnabled { if call.isSpeakerphoneEnabled {
return AudioSource.builtInSpeaker return AudioSource.builtInSpeaker

Loading…
Cancel
Save