Remove usage of ! in call view.

pull/1/head
Matthew Chen 7 years ago
parent ef95e0538a
commit ce197b0ada

@ -30,27 +30,27 @@ class CallViewController: OWSViewController, CallObserver, CallServiceObserver,
// MARK: Views // MARK: Views
var hasConstraints = false var hasConstraints = false
var blurView: UIVisualEffectView! var blurView: UIVisualEffectView?
var dateFormatter: DateFormatter? var dateFormatter: DateFormatter?
// MARK: Contact Views // MARK: Contact Views
var contactNameLabel: MarqueeLabel! let contactNameLabel = MarqueeLabel()
var contactAvatarView: AvatarImageView! let contactAvatarView = AvatarImageView()
var contactAvatarContainerView: UIView! let contactAvatarContainerView = UIView.container()
var callStatusLabel: UILabel! let callStatusLabel = UILabel()
var callDurationTimer: Timer? var callDurationTimer: Timer?
// MARK: Ongoing Call Controls // MARK: Ongoing Call Controls
var ongoingCallView: UIView! var ongoingCallView: UIView?
var hangUpButton: UIButton! var hangUpButton: UIButton?
var audioSourceButton: UIButton! var audioSourceButton: UIButton?
var audioModeMuteButton: UIButton! var audioModeMuteButton: UIButton?
var audioModeVideoButton: UIButton! var audioModeVideoButton: UIButton?
var videoModeMuteButton: UIButton! var videoModeMuteButton: UIButton?
var videoModeVideoButton: UIButton! var videoModeVideoButton: UIButton?
// TODO: Later, we'll re-enable the text message button // TODO: Later, we'll re-enable the text message button
// so users can send and read messages during a // so users can send and read messages during a
// call. // call.
@ -58,15 +58,15 @@ class CallViewController: OWSViewController, CallObserver, CallServiceObserver,
// MARK: Incoming Call Controls // MARK: Incoming Call Controls
var incomingCallView: UIView! var incomingCallView: UIView?
var acceptIncomingButton: UIButton! var acceptIncomingButton: UIButton?
var declineIncomingButton: UIButton! var declineIncomingButton: UIButton?
// MARK: Video Views // MARK: Video Views
var remoteVideoView: RemoteVideoView! var remoteVideoView: RemoteVideoView?
var localVideoView: RTCCameraPreviewView! var localVideoView: RTCCameraPreviewView?
weak var localVideoTrack: RTCVideoTrack? weak var localVideoTrack: RTCVideoTrack?
weak var remoteVideoTrack: RTCVideoTrack? weak var remoteVideoTrack: RTCVideoTrack?
var localVideoConstraints: [NSLayoutConstraint] = [] var localVideoConstraints: [NSLayoutConstraint] = []
@ -90,8 +90,8 @@ class CallViewController: OWSViewController, CallObserver, CallServiceObserver,
} }
} }
} }
var settingsNagView: UIView! let settingsNagView = UIView()
var settingsNagDescriptionLabel: UILabel! let settingsNagDescriptionLabel = UILabel()
// MARK: Audio Source // MARK: Audio Source
@ -219,7 +219,8 @@ class CallViewController: OWSViewController, CallObserver, CallServiceObserver,
// Dark blurred background. // Dark blurred background.
let blurEffect = UIBlurEffect(style: .dark) let blurEffect = UIBlurEffect(style: .dark)
blurView = UIVisualEffectView(effect: blurEffect) let blurView = UIVisualEffectView(effect: blurEffect)
self.blurView = blurView
blurView.isUserInteractionEnabled = false blurView.isUserInteractionEnabled = false
self.view.addSubview(blurView) self.view.addSubview(blurView)
@ -234,15 +235,22 @@ class CallViewController: OWSViewController, CallObserver, CallServiceObserver,
} }
func didTouchRootView(sender: UIGestureRecognizer) { func didTouchRootView(sender: UIGestureRecognizer) {
guard let remoteVideoView = remoteVideoView else {
owsFail("\(TAG) missing remoteVideoView.")
return
}
if !remoteVideoView.isHidden { if !remoteVideoView.isHidden {
shouldRemoteVideoControlsBeHidden = !shouldRemoteVideoControlsBeHidden shouldRemoteVideoControlsBeHidden = !shouldRemoteVideoControlsBeHidden
} }
} }
func createVideoViews() { func createVideoViews() {
remoteVideoView = RemoteVideoView() let remoteVideoView = RemoteVideoView()
self.remoteVideoView = remoteVideoView
remoteVideoView.isUserInteractionEnabled = false remoteVideoView.isUserInteractionEnabled = false
localVideoView = RTCCameraPreviewView()
let localVideoView = RTCCameraPreviewView()
self.localVideoView = localVideoView
remoteVideoView.isHidden = true remoteVideoView.isHidden = true
localVideoView.isHidden = true localVideoView.isHidden = true
@ -251,8 +259,6 @@ class CallViewController: OWSViewController, CallObserver, CallServiceObserver,
} }
func createContactViews() { func createContactViews() {
contactNameLabel = MarqueeLabel()
// marquee config // marquee config
contactNameLabel.type = .continuous contactNameLabel.type = .continuous
// This feels pretty slow when you're initially waiting for it, but when you're overlaying video calls, anything faster is distracting. // This feels pretty slow when you're initially waiting for it, but when you're overlaying video calls, anything faster is distracting.
@ -272,7 +278,6 @@ class CallViewController: OWSViewController, CallObserver, CallServiceObserver,
self.view.addSubview(contactNameLabel) self.view.addSubview(contactNameLabel)
callStatusLabel = UILabel()
callStatusLabel.font = UIFont.ows_regularFont(withSize: ScaleFromIPhone5To7Plus(19, 25)) callStatusLabel.font = UIFont.ows_regularFont(withSize: ScaleFromIPhone5To7Plus(19, 25))
callStatusLabel.textColor = UIColor.white callStatusLabel.textColor = UIColor.white
callStatusLabel.layer.shadowOffset = CGSize.zero callStatusLabel.layer.shadowOffset = CGSize.zero
@ -280,14 +285,11 @@ class CallViewController: OWSViewController, CallObserver, CallServiceObserver,
callStatusLabel.layer.shadowRadius = 4 callStatusLabel.layer.shadowRadius = 4
self.view.addSubview(callStatusLabel) self.view.addSubview(callStatusLabel)
contactAvatarContainerView = UIView.container()
self.view.addSubview(contactAvatarContainerView) self.view.addSubview(contactAvatarContainerView)
contactAvatarView = AvatarImageView()
contactAvatarContainerView.addSubview(contactAvatarView) contactAvatarContainerView.addSubview(contactAvatarView)
} }
func createSettingsNagViews() { func createSettingsNagViews() {
settingsNagView = UIView()
settingsNagView.isHidden = true settingsNagView.isHidden = true
self.view.addSubview(settingsNagView) self.view.addSubview(settingsNagView)
@ -296,7 +298,6 @@ class CallViewController: OWSViewController, CallObserver, CallServiceObserver,
viewStack.autoPinWidthToSuperview() viewStack.autoPinWidthToSuperview()
viewStack.autoVCenterInSuperview() viewStack.autoVCenterInSuperview()
settingsNagDescriptionLabel = UILabel()
settingsNagDescriptionLabel.text = NSLocalizedString("CALL_VIEW_SETTINGS_NAG_DESCRIPTION_ALL", settingsNagDescriptionLabel.text = NSLocalizedString("CALL_VIEW_SETTINGS_NAG_DESCRIPTION_ALL",
comment: "Reminder to the user of the benefits of enabling CallKit and disabling CallKit privacy.") comment: "Reminder to the user of the benefits of enabling CallKit and disabling CallKit privacy.")
settingsNagDescriptionLabel.font = UIFont.ows_regularFont(withSize: ScaleFromIPhone5To7Plus(16, 18)) settingsNagDescriptionLabel.font = UIFont.ows_regularFont(withSize: ScaleFromIPhone5To7Plus(16, 18))
@ -348,32 +349,38 @@ class CallViewController: OWSViewController, CallObserver, CallServiceObserver,
// textMessageButton = createButton(imageName:"message-active-wide", // textMessageButton = createButton(imageName:"message-active-wide",
// action:#selector(didPressTextMessage)) // action:#selector(didPressTextMessage))
audioSourceButton = createButton(imageName: "audio-call-speaker-inactive", let audioSourceButton = createButton(imageName: "audio-call-speaker-inactive",
action: #selector(didPressAudioSource)) action: #selector(didPressAudioSource),
audioSourceButton.accessibilityLabel = NSLocalizedString("CALL_VIEW_AUDIO_SOURCE_LABEL", accessibilityLabel: NSLocalizedString("CALL_VIEW_AUDIO_SOURCE_LABEL",
comment: "Accessibility label for selection the audio source") comment: "Accessibility label for selection the audio source"))
self.audioSourceButton = audioSourceButton
hangUpButton = createButton(imageName: "hangup-active-wide",
action: #selector(didPressHangup)) let hangUpButton = createButton(imageName: "hangup-active-wide",
hangUpButton.accessibilityLabel = NSLocalizedString("CALL_VIEW_HANGUP_LABEL", action: #selector(didPressHangup),
comment: "Accessibility label for hang up call") accessibilityLabel: NSLocalizedString("CALL_VIEW_HANGUP_LABEL",
comment: "Accessibility label for hang up call"))
audioModeMuteButton = createButton(imageName: "audio-call-mute-inactive", self.hangUpButton = hangUpButton
action: #selector(didPressMute))
audioModeMuteButton.accessibilityLabel = NSLocalizedString("CALL_VIEW_MUTE_LABEL", let audioModeMuteButton = createButton(imageName: "audio-call-mute-inactive",
comment: "Accessibility label for muting the microphone") action: #selector(didPressMute),
accessibilityLabel: NSLocalizedString("CALL_VIEW_MUTE_LABEL",
videoModeMuteButton = createButton(imageName: "video-mute-unselected", comment: "Accessibility label for muting the microphone"))
action: #selector(didPressMute)) self.audioModeMuteButton = audioModeMuteButton
videoModeMuteButton.accessibilityLabel = NSLocalizedString("CALL_VIEW_MUTE_LABEL", comment: "Accessibility label for muting the microphone")
let videoModeMuteButton = createButton(imageName: "video-mute-unselected",
audioModeVideoButton = createButton(imageName: "audio-call-video-inactive", action: #selector(didPressMute),
action: #selector(didPressVideo)) accessibilityLabel: NSLocalizedString("CALL_VIEW_MUTE_LABEL", comment: "Accessibility label for muting the microphone"))
audioModeVideoButton.accessibilityLabel = NSLocalizedString("CALL_VIEW_SWITCH_TO_VIDEO_LABEL", comment: "Accessibility label to switch to video call") self.videoModeMuteButton = videoModeMuteButton
videoModeVideoButton = createButton(imageName: "video-video-unselected", let audioModeVideoButton = createButton(imageName: "audio-call-video-inactive",
action: #selector(didPressVideo)) action: #selector(didPressVideo),
videoModeVideoButton.accessibilityLabel = NSLocalizedString("CALL_VIEW_SWITCH_TO_AUDIO_LABEL", comment: "Accessibility label to switch to audio only") accessibilityLabel: NSLocalizedString("CALL_VIEW_SWITCH_TO_VIDEO_LABEL", comment: "Accessibility label to switch to video call"))
self.audioModeMuteButton = audioModeVideoButton
let videoModeVideoButton = createButton(imageName: "video-video-unselected",
action: #selector(didPressVideo),
accessibilityLabel: NSLocalizedString("CALL_VIEW_SWITCH_TO_AUDIO_LABEL", comment: "Accessibility label to switch to audio only"))
self.videoModeVideoButton = videoModeVideoButton
setButtonSelectedImage(button: audioModeMuteButton, imageName: "audio-call-mute-active") setButtonSelectedImage(button: audioModeMuteButton, imageName: "audio-call-mute-active")
setButtonSelectedImage(button: videoModeMuteButton, imageName: "video-mute-selected") setButtonSelectedImage(button: videoModeMuteButton, imageName: "video-mute-selected")
@ -425,14 +432,16 @@ class CallViewController: OWSViewController, CallObserver, CallServiceObserver,
func createIncomingCallControls() { func createIncomingCallControls() {
acceptIncomingButton = createButton(imageName: "call-active-wide", let acceptIncomingButton = createButton(imageName: "call-active-wide",
action: #selector(didPressAnswerCall)) action: #selector(didPressAnswerCall),
acceptIncomingButton.accessibilityLabel = NSLocalizedString("CALL_VIEW_ACCEPT_INCOMING_CALL_LABEL", accessibilityLabel: NSLocalizedString("CALL_VIEW_ACCEPT_INCOMING_CALL_LABEL",
comment: "Accessibility label for accepting incoming calls") comment: "Accessibility label for accepting incoming calls"))
declineIncomingButton = createButton(imageName: "hangup-active-wide", self.acceptIncomingButton = acceptIncomingButton
action: #selector(didPressDeclineCall)) let declineIncomingButton = createButton(imageName: "hangup-active-wide",
declineIncomingButton.accessibilityLabel = NSLocalizedString("CALL_VIEW_DECLINE_INCOMING_CALL_LABEL", action: #selector(didPressDeclineCall),
comment: "Accessibility label for declining incoming calls") accessibilityLabel: NSLocalizedString("CALL_VIEW_DECLINE_INCOMING_CALL_LABEL",
comment: "Accessibility label for declining incoming calls"))
self.declineIncomingButton = declineIncomingButton
incomingCallView = createContainerForCallControls(controlGroups: [ incomingCallView = createContainerForCallControls(controlGroups: [
[acceptIncomingButton, declineIncomingButton ] [acceptIncomingButton, declineIncomingButton ]
@ -451,19 +460,19 @@ class CallViewController: OWSViewController, CallObserver, CallServiceObserver,
for row in rows { for row in rows {
containerView.addSubview(row) containerView.addSubview(row)
row.autoHCenterInSuperview() row.autoHCenterInSuperview()
if prevRow != nil { if let prevRow = prevRow {
row.autoPinEdge(.top, to: .bottom, of: prevRow!, withOffset: rowspacing) row.autoPinEdge(.top, to: .bottom, of: prevRow, withOffset: rowspacing)
} }
prevRow = row prevRow = row
} }
containerView.setContentHuggingVerticalHigh() containerView.setContentHuggingVerticalHigh()
rows.first!.autoPinEdge(toSuperviewEdge: .top) rows.first?.autoPinEdge(toSuperviewEdge: .top)
rows.last!.autoPinEdge(toSuperviewEdge: .bottom) rows.last?.autoPinEdge(toSuperviewEdge: .bottom)
return containerView return containerView
} }
func createButton(imageName: String, action: Selector) -> UIButton { func createButton(imageName: String, action: Selector, accessibilityLabel: String) -> UIButton {
let image = UIImage(named: imageName) let image = UIImage(named: imageName)
assert(image != nil) assert(image != nil)
let button = UIButton() let button = UIButton()
@ -475,6 +484,7 @@ class CallViewController: OWSViewController, CallObserver, CallServiceObserver,
button.addTarget(self, action: action, for: .touchUpInside) button.addTarget(self, action: action, for: .touchUpInside)
button.autoSetDimension(.width, toSize: buttonSize()) button.autoSetDimension(.width, toSize: buttonSize())
button.autoSetDimension(.height, toSize: buttonSize()) button.autoSetDimension(.height, toSize: buttonSize())
button.accessibilityLabel = accessibilityLabel
return button return button
} }
@ -493,11 +503,11 @@ class CallViewController: OWSViewController, CallObserver, CallServiceObserver,
subview.setContentHuggingHorizontalHigh() subview.setContentHuggingHorizontalHigh()
subview.autoVCenterInSuperview() subview.autoVCenterInSuperview()
if lastSubview != nil { if let lastSubview = lastSubview {
let spacer = UIView() let spacer = UIView()
spacer.isHidden = true spacer.isHidden = true
row.addSubview(spacer) row.addSubview(spacer)
spacer.autoPinEdge(.left, to: .right, of: lastSubview!) spacer.autoPinEdge(.left, to: .right, of: lastSubview)
spacer.autoPinEdge(.right, to: .left, of: subview) spacer.autoPinEdge(.right, to: .left, of: subview)
spacer.setContentHuggingHorizontalLow() spacer.setContentHuggingHorizontalLow()
spacer.autoVCenterInSuperview() spacer.autoVCenterInSuperview()
@ -512,8 +522,8 @@ class CallViewController: OWSViewController, CallObserver, CallServiceObserver,
lastSubview = subview lastSubview = subview
} }
subviews.first!.autoPinEdge(toSuperviewEdge: .left) subviews.first?.autoPinEdge(toSuperviewEdge: .left)
subviews.last!.autoPinEdge(toSuperviewEdge: .right) subviews.last?.autoPinEdge(toSuperviewEdge: .right)
} else if subviews.count == 1 { } else if subviews.count == 1 {
// If there's only one subview in this row, center it. // If there's only one subview in this row, center it.
let subview = subviews.first! let subview = subviews.first!
@ -528,6 +538,27 @@ class CallViewController: OWSViewController, CallObserver, CallServiceObserver,
// MARK: - Layout // MARK: - Layout
override func updateViewConstraints() { override func updateViewConstraints() {
guard let blurView = blurView else {
owsFail("\(TAG) missing blurView.")
return
}
guard let localVideoView = localVideoView else {
owsFail("\(TAG) missing localVideoView.")
return
}
guard let remoteVideoView = remoteVideoView else {
owsFail("\(TAG) missing remoteVideoView.")
return
}
guard let ongoingCallView = ongoingCallView else {
owsFail("\(TAG) missing ongoingCallView.")
return
}
guard let incomingCallView = incomingCallView else {
owsFail("\(TAG) missing incomingCallView.")
return
}
if !hasConstraints { if !hasConstraints {
// We only want to create our constraints once. // We only want to create our constraints once.
// //
@ -613,11 +644,19 @@ class CallViewController: OWSViewController, CallObserver, CallServiceObserver,
} }
internal func updateRemoteVideoLayout() { internal func updateRemoteVideoLayout() {
guard let remoteVideoView = remoteVideoView else {
owsFail("\(TAG) missing remoteVideoView.")
return
}
remoteVideoView.isHidden = !self.hasRemoteVideoTrack remoteVideoView.isHidden = !self.hasRemoteVideoTrack
updateCallUI(callState: call.state) updateCallUI(callState: call.state)
} }
internal func updateLocalVideoLayout() { internal func updateLocalVideoLayout() {
guard let localVideoView = localVideoView else {
owsFail("\(TAG) missing localVideoView.")
return
}
NSLayoutConstraint.deactivate(self.localVideoConstraints) NSLayoutConstraint.deactivate(self.localVideoConstraints)
@ -662,9 +701,10 @@ class CallViewController: OWSViewController, CallObserver, CallServiceObserver,
let callDuration = call.connectionDuration() let callDuration = call.connectionDuration()
let callDurationDate = Date(timeIntervalSinceReferenceDate: callDuration) let callDurationDate = Date(timeIntervalSinceReferenceDate: callDuration)
if dateFormatter == nil { if dateFormatter == nil {
dateFormatter = DateFormatter() let dateFormatter = DateFormatter()
dateFormatter!.dateFormat = "HH:mm:ss" dateFormatter.dateFormat = "HH:mm:ss"
dateFormatter!.timeZone = TimeZone(identifier: "UTC")! dateFormatter.timeZone = TimeZone(identifier: "UTC")!
self.dateFormatter = dateFormatter
} }
var formattedDate = dateFormatter!.string(from: callDurationDate) var formattedDate = dateFormatter!.string(from: callDurationDate)
if formattedDate.hasPrefix("00:") { if formattedDate.hasPrefix("00:") {
@ -707,29 +747,39 @@ class CallViewController: OWSViewController, CallObserver, CallServiceObserver,
func updateCallUI(callState: CallState) { func updateCallUI(callState: CallState) {
assert(Thread.isMainThread) assert(Thread.isMainThread)
guard let remoteVideoView = remoteVideoView else {
owsFail("\(TAG) missing remoteVideoView.")
return
}
guard let localVideoView = localVideoView else {
owsFail("\(TAG) missing localVideoView.")
return
}
updateCallStatusLabel(callState: callState) updateCallStatusLabel(callState: callState)
if isShowingSettingsNag { if isShowingSettingsNag {
settingsNagView.isHidden = false settingsNagView.isHidden = false
contactAvatarView.isHidden = true contactAvatarView.isHidden = true
ongoingCallView.isHidden = true ongoingCallView?.isHidden = true
return return
} }
// Marquee scrolling is distracting during a video call, disable it. // Marquee scrolling is distracting during a video call, disable it.
contactNameLabel.labelize = call.hasLocalVideo contactNameLabel.labelize = call.hasLocalVideo
audioModeMuteButton.isSelected = call.isMuted audioModeMuteButton?.isSelected = call.isMuted
videoModeMuteButton.isSelected = call.isMuted videoModeMuteButton?.isSelected = call.isMuted
audioModeVideoButton.isSelected = call.hasLocalVideo audioModeVideoButton?.isSelected = call.hasLocalVideo
videoModeVideoButton.isSelected = call.hasLocalVideo videoModeVideoButton?.isSelected = call.hasLocalVideo
// Show Incoming vs. Ongoing call controls // Show Incoming vs. Ongoing call controls
let isRinging = callState == .localRinging let isRinging = callState == .localRinging
incomingCallView.isHidden = !isRinging incomingCallView?.isHidden = !isRinging
incomingCallView.isUserInteractionEnabled = isRinging incomingCallView?.isUserInteractionEnabled = isRinging
ongoingCallView.isHidden = isRinging ongoingCallView?.isHidden = isRinging
ongoingCallView.isUserInteractionEnabled = !isRinging ongoingCallView?.isUserInteractionEnabled = !isRinging
// Rework control state if remote video is available. // Rework control state if remote video is available.
let hasRemoteVideo = !remoteVideoView.isHidden let hasRemoteVideo = !remoteVideoView.isHidden
@ -749,7 +799,7 @@ class CallViewController: OWSViewController, CallObserver, CallServiceObserver,
if shouldRemoteVideoControlsBeHidden && !remoteVideoView.isHidden { if shouldRemoteVideoControlsBeHidden && !remoteVideoView.isHidden {
contactNameLabel.isHidden = true contactNameLabel.isHidden = true
callStatusLabel.isHidden = true callStatusLabel.isHidden = true
ongoingCallView.isHidden = true ongoingCallView?.isHidden = true
} else { } else {
contactNameLabel.isHidden = false contactNameLabel.isHidden = false
callStatusLabel.isHidden = false callStatusLabel.isHidden = false
@ -759,24 +809,24 @@ class CallViewController: OWSViewController, CallObserver, CallServiceObserver,
if self.hasAlternateAudioSources { if self.hasAlternateAudioSources {
// 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".
audioSourceButton.isSelected = false audioSourceButton?.isSelected = false
if hasLocalVideo { if hasLocalVideo {
audioSourceButton.setImage(#imageLiteral(resourceName: "ic_speaker_bluetooth_inactive_video_mode"), for: .normal) audioSourceButton?.setImage(#imageLiteral(resourceName: "ic_speaker_bluetooth_inactive_video_mode"), for: .normal)
audioSourceButton.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 {
audioSourceButton.setImage(#imageLiteral(resourceName: "ic_speaker_bluetooth_inactive_audio_mode"), for: .normal) audioSourceButton?.setImage(#imageLiteral(resourceName: "ic_speaker_bluetooth_inactive_audio_mode"), for: .normal)
audioSourceButton.setImage(#imageLiteral(resourceName: "ic_speaker_bluetooth_inactive_audio_mode"), for: .selected) audioSourceButton?.setImage(#imageLiteral(resourceName: "ic_speaker_bluetooth_inactive_audio_mode"), for: .selected)
} }
audioSourceButton.isHidden = false audioSourceButton?.isHidden = false
} else { } else {
// No bluetooth audio detected // No bluetooth audio detected
audioSourceButton.setImage(#imageLiteral(resourceName: "audio-call-speaker-inactive"), for: .normal) audioSourceButton?.setImage(#imageLiteral(resourceName: "audio-call-speaker-inactive"), for: .normal)
audioSourceButton.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.
audioSourceButton.isHidden = hasLocalVideo audioSourceButton?.isHidden = hasLocalVideo
} }
// Dismiss Handling // Dismiss Handling
@ -819,18 +869,18 @@ class CallViewController: OWSViewController, CallObserver, CallServiceObserver,
// before the operation completes. // before the operation completes.
func updateAudioSourceButtonIsSelected() { func updateAudioSourceButtonIsSelected() {
guard callUIAdapter.audioService.isSpeakerphoneEnabled else { guard callUIAdapter.audioService.isSpeakerphoneEnabled else {
self.audioSourceButton.isSelected = false self.audioSourceButton?.isSelected = false
return return
} }
// VideoChat mode enables the output speaker, but we don't // VideoChat mode enables the output speaker, but we don't
// want to highlight the speaker button in that case. // want to highlight the speaker button in that case.
guard !call.hasLocalVideo else { guard !call.hasLocalVideo else {
self.audioSourceButton.isSelected = false self.audioSourceButton?.isSelected = false
return return
} }
self.audioSourceButton.isSelected = true self.audioSourceButton?.isSelected = true
} }
// MARK: - Actions // MARK: - Actions
@ -936,7 +986,10 @@ class CallViewController: OWSViewController, CallObserver, CallServiceObserver,
private func markSettingsNagAsComplete() { private func markSettingsNagAsComplete() {
Logger.info("\(TAG) called \(#function)") Logger.info("\(TAG) called \(#function)")
let preferences = Environment.current().preferences! guard let preferences = Environment.current().preferences else {
owsFail("\(TAG) missing preferences.")
return
}
preferences.setIsCallKitEnabled(preferences.isCallKitEnabled()) preferences.setIsCallKitEnabled(preferences.isCallKitEnabled())
preferences.setIsCallKitPrivacyEnabled(preferences.isCallKitPrivacyEnabled()) preferences.setIsCallKitPrivacyEnabled(preferences.isCallKitPrivacyEnabled())
@ -1000,6 +1053,10 @@ class CallViewController: OWSViewController, CallObserver, CallServiceObserver,
guard self.localVideoTrack != localVideoTrack else { guard self.localVideoTrack != localVideoTrack else {
return return
} }
guard let localVideoView = localVideoView else {
owsFail("\(TAG) missing localVideoView.")
return
}
self.localVideoTrack = localVideoTrack self.localVideoTrack = localVideoTrack
@ -1023,6 +1080,10 @@ class CallViewController: OWSViewController, CallObserver, CallServiceObserver,
guard self.remoteVideoTrack != remoteVideoTrack else { guard self.remoteVideoTrack != remoteVideoTrack else {
return return
} }
guard let remoteVideoView = remoteVideoView else {
owsFail("\(TAG) missing remoteVideoView.")
return
}
self.remoteVideoTrack?.remove(remoteVideoView) self.remoteVideoTrack?.remove(remoteVideoView)
self.remoteVideoTrack = nil self.remoteVideoTrack = nil

Loading…
Cancel
Save