session-ios/Session/Calls/CallVC.swift

551 lines
22 KiB
Swift
Raw Normal View History

2021-08-16 06:40:07 +02:00
import WebRTC
import SessionUIKit
import SessionMessagingKit
import SessionUtilitiesKit
2021-09-22 09:06:14 +02:00
import UIKit
2021-11-15 02:22:31 +01:00
import MediaPlayer
2021-08-16 06:40:07 +02:00
final class CallVC: UIViewController, VideoPreviewDelegate {
2021-10-28 08:02:41 +02:00
let call: SessionCall
2021-11-30 01:57:56 +01:00
var latestKnownAudioOutputDeviceName: String?
2021-12-01 00:38:02 +01:00
var durationTimer: Timer?
2021-12-01 00:39:27 +01:00
var duration: Int = 0
2021-10-14 07:01:50 +02:00
var shouldRestartCamera = true
2021-10-28 08:02:41 +02:00
weak var conversationVC: ConversationVC? = nil
2021-08-16 06:40:07 +02:00
lazy var cameraManager: CameraManager = {
let result = CameraManager()
result.delegate = self
return result
}()
2021-08-18 01:56:28 +02:00
// MARK: UI Components
private lazy var localVideoView: LocalVideoView = {
let result = LocalVideoView()
2021-11-03 05:31:50 +01:00
result.isHidden = !call.isVideoEnabled
result.layer.cornerRadius = 10
result.layer.masksToBounds = true
result.set(.width, to: LocalVideoView.width)
result.set(.height, to: LocalVideoView.height)
2022-02-08 04:14:33 +01:00
result.makeViewDraggable()
2021-09-08 06:55:52 +02:00
return result
}()
private lazy var remoteVideoView: RemoteVideoView = {
let result = RemoteVideoView()
result.alpha = 0
result.backgroundColor = .black
2021-12-01 03:25:12 +01:00
result.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(handleRemoteVieioViewTapped)))
2021-08-18 02:45:55 +02:00
return result
}()
2021-08-18 01:56:28 +02:00
private lazy var fadeView: UIView = {
let result = UIView()
let height: CGFloat = 64
var frame = UIScreen.main.bounds
frame.size.height = height
let layer = CAGradientLayer()
layer.frame = frame
layer.colors = [ UIColor(hex: 0x000000).withAlphaComponent(0.4).cgColor, UIColor(hex: 0x000000).withAlphaComponent(0).cgColor ]
result.layer.insertSublayer(layer, at: 0)
result.set(.height, to: height)
return result
}()
2021-12-01 00:38:02 +01:00
private lazy var profilePictureView: UIImageView = {
let result = UIImageView()
let radius: CGFloat = isIPhone6OrSmaller ? 100 : 120
2021-12-01 00:38:02 +01:00
result.image = self.call.profilePicture
result.set(.width, to: radius * 2)
result.set(.height, to: radius * 2)
result.layer.cornerRadius = radius
2021-12-01 00:38:02 +01:00
result.layer.masksToBounds = true
result.contentMode = .scaleAspectFill
return result
}()
private lazy var minimizeButton: UIButton = {
2021-08-18 01:56:28 +02:00
let result = UIButton(type: .custom)
result.isHidden = !call.hasConnected
let image = UIImage(named: "Minimize")!.withTint(.white)
2021-08-18 01:56:28 +02:00
result.setImage(image, for: UIControl.State.normal)
result.set(.width, to: 60)
result.set(.height, to: 60)
result.addTarget(self, action: #selector(minimize), for: UIControl.Event.touchUpInside)
2021-08-18 02:03:10 +02:00
return result
}()
2021-09-23 04:55:28 +02:00
private lazy var answerButton: UIButton = {
let result = UIButton(type: .custom)
2021-11-10 04:31:02 +01:00
result.isHidden = call.hasStartedConnecting
2021-09-23 04:55:28 +02:00
let image = UIImage(named: "AnswerCall")!.withTint(.white)
result.setImage(image, for: UIControl.State.normal)
result.set(.width, to: 60)
result.set(.height, to: 60)
result.backgroundColor = Colors.accent
result.layer.cornerRadius = 30
result.addTarget(self, action: #selector(answerCall), for: UIControl.Event.touchUpInside)
return result
}()
2021-09-08 06:55:52 +02:00
private lazy var hangUpButton: UIButton = {
let result = UIButton(type: .custom)
let image = UIImage(named: "EndCall")!.withTint(.white)
result.setImage(image, for: UIControl.State.normal)
result.set(.width, to: 60)
result.set(.height, to: 60)
result.backgroundColor = Colors.destructive
result.layer.cornerRadius = 30
2021-09-23 04:55:28 +02:00
result.addTarget(self, action: #selector(endCall), for: UIControl.Event.touchUpInside)
return result
}()
private lazy var responsePanel: UIStackView = {
let result = UIStackView(arrangedSubviews: [hangUpButton, answerButton])
result.axis = .horizontal
result.spacing = Values.veryLargeSpacing * 2 + 40
2021-09-08 06:55:52 +02:00
return result
}()
private lazy var switchCameraButton: UIButton = {
let result = UIButton(type: .custom)
2021-11-03 05:31:50 +01:00
result.isEnabled = call.isVideoEnabled
2021-09-08 06:55:52 +02:00
let image = UIImage(named: "SwitchCamera")!.withTint(.white)
result.setImage(image, for: UIControl.State.normal)
result.set(.width, to: 60)
result.set(.height, to: 60)
result.backgroundColor = UIColor(hex: 0x1F1F1F)
result.layer.cornerRadius = 30
result.addTarget(self, action: #selector(switchCamera), for: UIControl.Event.touchUpInside)
return result
}()
private lazy var switchAudioButton: UIButton = {
let result = UIButton(type: .custom)
let image = UIImage(named: "AudioOff")!.withTint(.white)
2021-09-08 06:55:52 +02:00
result.setImage(image, for: UIControl.State.normal)
result.set(.width, to: 60)
result.set(.height, to: 60)
result.backgroundColor = call.isMuted ? Colors.destructive : UIColor(hex: 0x1F1F1F)
2021-09-08 06:55:52 +02:00
result.layer.cornerRadius = 30
result.addTarget(self, action: #selector(switchAudio), for: UIControl.Event.touchUpInside)
return result
}()
2021-09-23 04:55:28 +02:00
private lazy var videoButton: UIButton = {
let result = UIButton(type: .custom)
2021-11-12 07:01:57 +01:00
let image = UIImage(named: "VideoCall")?.withRenderingMode(.alwaysTemplate)
2021-09-23 04:55:28 +02:00
result.setImage(image, for: UIControl.State.normal)
result.set(.width, to: 60)
result.set(.height, to: 60)
2021-11-12 07:01:57 +01:00
result.tintColor = .white
2021-09-23 04:55:28 +02:00
result.backgroundColor = UIColor(hex: 0x1F1F1F)
result.layer.cornerRadius = 30
result.addTarget(self, action: #selector(operateCamera), for: UIControl.Event.touchUpInside)
return result
}()
2021-11-15 02:22:31 +01:00
private lazy var volumeView: MPVolumeView = {
let result = MPVolumeView()
let image = UIImage(named: "Speaker")?.withRenderingMode(.alwaysTemplate)
2021-11-15 06:02:24 +01:00
result.showsVolumeSlider = false
2021-11-15 02:22:31 +01:00
result.showsRouteButton = true
result.setRouteButtonImage(image, for: UIControl.State.normal)
result.set(.width, to: 60)
result.set(.height, to: 60)
result.tintColor = .white
result.backgroundColor = UIColor(hex: 0x1F1F1F)
result.layer.cornerRadius = 30
return result
}()
2021-09-23 04:55:28 +02:00
private lazy var operationPanel: UIStackView = {
2021-11-15 02:22:31 +01:00
let result = UIStackView(arrangedSubviews: [switchCameraButton, videoButton, switchAudioButton, volumeView])
2021-09-23 04:55:28 +02:00
result.axis = .horizontal
result.spacing = Values.veryLargeSpacing
return result
}()
2021-08-18 02:33:33 +02:00
private lazy var titleLabel: UILabel = {
2021-08-18 02:03:10 +02:00
let result = UILabel()
result.textColor = .white
result.font = .boldSystemFont(ofSize: Values.veryLargeFontSize)
result.textAlignment = .center
2021-08-18 01:56:28 +02:00
return result
}()
2021-08-18 05:07:15 +02:00
private lazy var callInfoLabel: UILabel = {
2021-08-18 02:33:33 +02:00
let result = UILabel()
2021-11-10 04:31:02 +01:00
result.isHidden = call.hasConnected
2021-08-18 02:33:33 +02:00
result.textColor = .white
result.font = .boldSystemFont(ofSize: Values.veryLargeFontSize)
result.textAlignment = .center
2021-11-10 04:31:02 +01:00
if call.hasStartedConnecting { result.text = "Connecting..." }
2021-08-18 02:33:33 +02:00
return result
}()
2022-04-07 09:02:57 +02:00
private lazy var callDurationLabel: UILabel = {
let result = UILabel()
result.isHidden = true
result.textColor = .white
result.font = .boldSystemFont(ofSize: Values.veryLargeFontSize)
result.textAlignment = .center
return result
}()
2021-08-16 06:40:07 +02:00
// MARK: Lifecycle
2021-10-28 08:02:41 +02:00
init(for call: SessionCall) {
self.call = call
super.init(nibName: nil, bundle: nil)
2021-11-03 05:31:50 +01:00
setupStateChangeCallbacks()
self.modalPresentationStyle = .overFullScreen
self.modalTransitionStyle = .crossDissolve
}
func setupStateChangeCallbacks() {
self.call.remoteVideoStateDidChange = { isEnabled in
DispatchQueue.main.async {
UIView.animate(withDuration: 0.25) {
self.remoteVideoView.alpha = isEnabled ? 1 : 0
}
2021-12-01 03:25:12 +01:00
if self.callInfoLabel.alpha < 0.5 {
UIView.animate(withDuration: 0.25) {
self.operationPanel.alpha = 1
self.responsePanel.alpha = 1
self.callInfoLabel.alpha = 1
}
}
2021-11-03 05:31:50 +01:00
}
}
2021-11-09 01:53:38 +01:00
self.call.hasStartedConnectingDidChange = {
DispatchQueue.main.async {
self.callInfoLabel.text = "Connecting..."
self.answerButton.alpha = 0
UIView.animate(withDuration: 0.5, delay: 0, usingSpringWithDamping: 1, initialSpringVelocity: 1, options: .curveEaseIn, animations: {
self.answerButton.isHidden = true
}, completion: nil)
}
}
2021-11-03 05:31:50 +01:00
self.call.hasConnectedDidChange = {
DispatchQueue.main.async {
2021-11-29 06:32:02 +01:00
CallRingTonePlayer.shared.stopPlayingRingTone()
2021-11-03 05:31:50 +01:00
self.callInfoLabel.text = "Connected"
self.minimizeButton.isHidden = false
2021-12-01 00:38:02 +01:00
self.durationTimer = Timer.scheduledTimer(withTimeInterval: 1, repeats: true) { _ in
self.updateDuration()
}
2022-04-07 09:02:57 +02:00
self.callInfoLabel.isHidden = true
self.callDurationLabel.isHidden = false
2021-11-03 05:31:50 +01:00
}
}
2021-10-28 08:02:41 +02:00
self.call.hasEndedDidChange = {
2021-11-09 01:53:38 +01:00
DispatchQueue.main.async {
2021-12-01 00:38:02 +01:00
self.durationTimer?.invalidate()
self.durationTimer = nil
self.handleEndCallMessage()
2021-11-09 01:53:38 +01:00
}
2021-10-28 08:02:41 +02:00
}
self.call.hasStartedReconnecting = {
DispatchQueue.main.async {
self.callInfoLabel.isHidden = false
2022-04-07 09:02:57 +02:00
self.callDurationLabel.isHidden = true
self.callInfoLabel.text = "Reconnecting..."
}
}
self.call.hasReconnected = {
DispatchQueue.main.async {
self.callInfoLabel.isHidden = true
2022-04-07 09:02:57 +02:00
self.callDurationLabel.isHidden = false
}
}
}
required init(coder: NSCoder) { preconditionFailure("Use init(for:) instead.") }
2021-08-16 06:40:07 +02:00
override func viewDidLoad() {
super.viewDidLoad()
2021-08-17 08:02:20 +02:00
view.backgroundColor = .black
2021-08-16 06:40:07 +02:00
setUpViewHierarchy()
2021-10-14 07:01:50 +02:00
if shouldRestartCamera { cameraManager.prepare() }
2021-11-03 05:31:50 +01:00
touch(call.videoCapturer)
2021-10-28 08:02:41 +02:00
titleLabel.text = self.call.contactName
2021-11-09 01:53:38 +01:00
AppEnvironment.shared.callManager.startCall(call) { error in
DispatchQueue.main.async {
if let _ = error {
self.callInfoLabel.text = "Can't start a call."
self.endCall()
} else {
self.callInfoLabel.text = "Ringing..."
self.answerButton.isHidden = true
}
}
}
2022-02-15 00:12:12 +01:00
setupOrientationMonitoring()
NotificationCenter.default.addObserver(self, selector: #selector(audioRouteDidChange), name: AVAudioSession.routeChangeNotification, object: nil)
}
deinit {
2022-02-15 00:12:12 +01:00
UIDevice.current.endGeneratingDeviceOrientationNotifications()
NotificationCenter.default.removeObserver(self)
2021-08-16 06:40:07 +02:00
}
func setUpViewHierarchy() {
2021-12-01 00:38:02 +01:00
// Profile picture container
let profilePictureContainer = UIView()
view.addSubview(profilePictureContainer)
2021-08-16 07:00:38 +02:00
// Remote video view
2021-11-03 05:31:50 +01:00
call.attachRemoteVideoRenderer(remoteVideoView)
2021-08-16 07:00:38 +02:00
view.addSubview(remoteVideoView)
remoteVideoView.translatesAutoresizingMaskIntoConstraints = false
remoteVideoView.pin(to: view)
// Local video view
2021-11-03 05:31:50 +01:00
call.attachLocalVideoRenderer(localVideoView)
2021-08-18 01:56:28 +02:00
// Fade view
view.addSubview(fadeView)
fadeView.translatesAutoresizingMaskIntoConstraints = false
fadeView.pin([ UIView.HorizontalEdge.left, UIView.VerticalEdge.top, UIView.HorizontalEdge.right ], to: view)
2021-10-21 07:28:48 +02:00
// Minimize button
view.addSubview(minimizeButton)
minimizeButton.translatesAutoresizingMaskIntoConstraints = false
minimizeButton.pin(.left, to: .left, of: view)
minimizeButton.pin(.top, to: .top, of: view, withInset: 32)
2021-08-18 05:07:15 +02:00
// Title label
2021-08-18 02:33:33 +02:00
view.addSubview(titleLabel)
titleLabel.translatesAutoresizingMaskIntoConstraints = false
titleLabel.center(.vertical, in: minimizeButton)
2021-08-18 02:33:33 +02:00
titleLabel.center(.horizontal, in: view)
2021-09-23 04:55:28 +02:00
// Response Panel
view.addSubview(responsePanel)
responsePanel.center(.horizontal, in: view)
responsePanel.pin(.bottom, to: .bottom, of: view, withInset: -Values.newConversationButtonBottomOffset)
// Operation Panel
view.addSubview(operationPanel)
operationPanel.center(.horizontal, in: view)
operationPanel.pin(.bottom, to: .top, of: responsePanel, withInset: -Values.veryLargeSpacing)
2021-12-01 00:38:02 +01:00
// Profile picture view
profilePictureContainer.pin(.top, to: .bottom, of: fadeView)
profilePictureContainer.pin(.bottom, to: .top, of: operationPanel)
profilePictureContainer.pin([ UIView.HorizontalEdge.left, UIView.HorizontalEdge.right ], to: view)
profilePictureContainer.addSubview(profilePictureView)
profilePictureView.center(in: profilePictureContainer)
// Call info label
let callInfoLabelContainer = UIView()
view.addSubview(callInfoLabelContainer)
callInfoLabelContainer.pin(.top, to: .bottom, of: profilePictureView)
callInfoLabelContainer.pin(.bottom, to: .bottom, of: profilePictureContainer)
callInfoLabelContainer.pin([ UIView.HorizontalEdge.left, UIView.HorizontalEdge.right ], to: view)
callInfoLabelContainer.addSubview(callInfoLabel)
2022-04-07 09:02:57 +02:00
callInfoLabelContainer.addSubview(callDurationLabel)
2021-12-01 00:38:02 +01:00
callInfoLabel.translatesAutoresizingMaskIntoConstraints = false
callInfoLabel.center(in: callInfoLabelContainer)
2022-04-07 09:02:57 +02:00
callDurationLabel.translatesAutoresizingMaskIntoConstraints = false
callDurationLabel.center(in: callInfoLabelContainer)
2021-09-22 09:06:14 +02:00
}
private func addLocalVideoView() {
let safeAreaInsets = UIApplication.shared.keyWindow!.safeAreaInsets
let window = CurrentAppContext().mainWindow!
window.addSubview(localVideoView)
localVideoView.autoPinEdge(toSuperviewEdge: .right, withInset: Values.smallSpacing)
let topMargin = safeAreaInsets.top + Values.veryLargeSpacing
localVideoView.autoPinEdge(toSuperviewEdge: .top, withInset: topMargin)
}
2021-08-16 06:40:07 +02:00
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
2021-11-03 05:31:50 +01:00
if (call.isVideoEnabled && shouldRestartCamera) { cameraManager.start() }
2021-10-14 07:01:50 +02:00
shouldRestartCamera = true
addLocalVideoView()
remoteVideoView.alpha = call.isRemoteVideoEnabled ? 1 : 0
2021-08-16 06:40:07 +02:00
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
2021-11-03 05:31:50 +01:00
if (call.isVideoEnabled && shouldRestartCamera) { cameraManager.stop() }
localVideoView.removeFromSuperview()
2021-10-26 06:48:31 +02:00
}
2022-02-15 00:12:12 +01:00
// MARK: - Orientation
private func setupOrientationMonitoring() {
UIDevice.current.beginGeneratingDeviceOrientationNotifications()
NotificationCenter.default.addObserver(self, selector: #selector(didChangeDeviceOrientation), name: UIDevice.orientationDidChangeNotification, object: UIDevice.current)
}
@objc func didChangeDeviceOrientation(notification: Notification) {
func rotateAllButtons(rotationAngle: CGFloat) {
let transform = CGAffineTransform(rotationAngle: rotationAngle)
UIView.animate(withDuration: 0.2) {
self.answerButton.transform = transform
self.hangUpButton.transform = transform
self.switchAudioButton.transform = transform
self.switchCameraButton.transform = transform
self.videoButton.transform = transform
self.volumeView.transform = transform
}
}
switch UIDevice.current.orientation {
case .portrait:
rotateAllButtons(rotationAngle: 0)
case .portraitUpsideDown:
rotateAllButtons(rotationAngle: .pi)
case .landscapeLeft:
rotateAllButtons(rotationAngle: .halfPi)
case .landscapeRight:
rotateAllButtons(rotationAngle: .pi + .halfPi)
default:
break
}
}
// MARK: Call signalling
2021-08-18 05:07:15 +02:00
func handleAnswerMessage(_ message: CallMessage) {
2021-08-19 05:42:46 +02:00
callInfoLabel.text = "Connecting..."
2021-08-18 05:07:15 +02:00
}
2021-11-10 04:31:02 +01:00
func handleEndCallMessage() {
2022-04-05 08:35:09 +02:00
SNLog("[Calls] Ending call.")
2022-04-07 09:02:57 +02:00
self.callInfoLabel.isHidden = false
self.callDurationLabel.isHidden = true
2021-08-18 05:07:15 +02:00
callInfoLabel.text = "Call Ended"
2021-08-18 02:33:33 +02:00
UIView.animate(withDuration: 0.25) {
2021-08-18 02:45:55 +02:00
self.remoteVideoView.alpha = 0
2021-12-14 04:34:59 +01:00
self.operationPanel.alpha = 1
self.responsePanel.alpha = 1
self.callInfoLabel.alpha = 1
2021-08-18 02:33:33 +02:00
}
Timer.scheduledTimer(withTimeInterval: 2, repeats: false) { _ in
self.conversationVC?.showInputAccessoryView()
2021-08-18 02:33:33 +02:00
self.presentingViewController?.dismiss(animated: true, completion: nil)
}
2021-08-16 06:40:07 +02:00
}
2021-08-18 01:56:28 +02:00
2021-09-23 04:55:28 +02:00
@objc private func answerCall() {
AppEnvironment.shared.callManager.answerCall(call) { error in
DispatchQueue.main.async {
if let _ = error {
self.callInfoLabel.text = "Can't answer the call."
self.endCall()
2021-11-09 01:53:38 +01:00
}
2021-10-25 02:49:54 +02:00
}
2021-09-23 04:55:28 +02:00
}
}
@objc private func endCall() {
2021-11-09 01:53:38 +01:00
AppEnvironment.shared.callManager.endCall(call) { error in
if let _ = error {
self.call.endSessionCall()
AppEnvironment.shared.callManager.reportCurrentCallEnded(reason: nil)
}
DispatchQueue.main.async {
self.conversationVC?.showInputAccessoryView()
self.presentingViewController?.dismiss(animated: true, completion: nil)
}
2021-11-09 01:53:38 +01:00
}
2021-08-18 01:56:28 +02:00
}
2021-09-08 06:55:52 +02:00
2021-12-01 00:38:02 +01:00
@objc private func updateDuration() {
2022-04-07 09:02:57 +02:00
callDurationLabel.text = String(format: "%.2d:%.2d", duration/60, duration%60)
2021-12-01 00:39:27 +01:00
duration += 1
2021-12-01 00:38:02 +01:00
}
// MARK: Minimize to a floating view
@objc private func minimize() {
2021-10-14 07:01:50 +02:00
self.shouldRestartCamera = false
2021-10-11 04:14:39 +02:00
let miniCallView = MiniCallView(from: self)
miniCallView.show()
self.conversationVC?.showInputAccessoryView()
presentingViewController?.dismiss(animated: true, completion: nil)
2021-09-23 04:55:28 +02:00
}
// MARK: Video and Audio
2021-09-23 04:55:28 +02:00
@objc private func operateCamera() {
2021-11-03 05:31:50 +01:00
if (call.isVideoEnabled) {
2021-09-23 04:55:28 +02:00
localVideoView.isHidden = true
cameraManager.stop()
2021-11-12 07:01:57 +01:00
videoButton.tintColor = .white
videoButton.backgroundColor = UIColor(hex: 0x1F1F1F)
2021-09-23 04:55:28 +02:00
switchCameraButton.isEnabled = false
2021-11-03 05:31:50 +01:00
call.isVideoEnabled = false
2021-09-23 04:55:28 +02:00
} else {
guard requestCameraPermissionIfNeeded() else { return }
2021-10-21 07:28:48 +02:00
let previewVC = VideoPreviewVC()
previewVC.delegate = self
present(previewVC, animated: true, completion: nil)
2021-09-22 06:54:26 +02:00
}
2021-10-21 07:28:48 +02:00
}
func cameraDidConfirmTurningOn() {
localVideoView.isHidden = false
cameraManager.prepare()
cameraManager.start()
2021-11-12 07:01:57 +01:00
videoButton.tintColor = UIColor(hex: 0x1F1F1F)
videoButton.backgroundColor = .white
2021-10-21 07:28:48 +02:00
switchCameraButton.isEnabled = true
2021-11-03 05:31:50 +01:00
call.isVideoEnabled = true
}
2021-09-08 06:55:52 +02:00
@objc private func switchCamera() {
cameraManager.switchCamera()
}
@objc private func switchAudio() {
2021-11-03 05:31:50 +01:00
if call.isMuted {
2021-09-08 06:55:52 +02:00
switchAudioButton.backgroundColor = UIColor(hex: 0x1F1F1F)
2021-11-03 05:31:50 +01:00
call.isMuted = false
2021-09-08 06:55:52 +02:00
} else {
switchAudioButton.backgroundColor = Colors.destructive
2021-11-03 05:31:50 +01:00
call.isMuted = true
2021-09-08 06:55:52 +02:00
}
}
@objc private func audioRouteDidChange() {
let currentSession = AVAudioSession.sharedInstance()
let currentRoute = currentSession.currentRoute
if let currentOutput = currentRoute.outputs.first {
2021-11-30 01:57:56 +01:00
if let latestKnownAudioOutputDeviceName = latestKnownAudioOutputDeviceName, currentOutput.portName == latestKnownAudioOutputDeviceName { return }
latestKnownAudioOutputDeviceName = currentOutput.portName
switch currentOutput.portType {
case .builtInSpeaker:
let image = UIImage(named: "Speaker")?.withRenderingMode(.alwaysTemplate)
volumeView.setRouteButtonImage(image, for: .normal)
volumeView.tintColor = UIColor(hex: 0x1F1F1F)
volumeView.backgroundColor = .white
case .headphones:
let image = UIImage(named: "Headsets")?.withRenderingMode(.alwaysTemplate)
volumeView.setRouteButtonImage(image, for: .normal)
volumeView.tintColor = UIColor(hex: 0x1F1F1F)
volumeView.backgroundColor = .white
case .bluetoothLE: fallthrough
case .bluetoothA2DP:
let image = UIImage(named: "Bluetooth")?.withRenderingMode(.alwaysTemplate)
volumeView.setRouteButtonImage(image, for: .normal)
volumeView.tintColor = UIColor(hex: 0x1F1F1F)
volumeView.backgroundColor = .white
case .bluetoothHFP:
let image = UIImage(named: "Airpods")?.withRenderingMode(.alwaysTemplate)
volumeView.setRouteButtonImage(image, for: .normal)
volumeView.tintColor = UIColor(hex: 0x1F1F1F)
volumeView.backgroundColor = .white
2021-12-01 00:38:02 +01:00
case .builtInReceiver: fallthrough
default:
2021-12-01 00:38:02 +01:00
let image = UIImage(named: "Speaker")?.withRenderingMode(.alwaysTemplate)
volumeView.setRouteButtonImage(image, for: .normal)
volumeView.tintColor = .white
volumeView.backgroundColor = UIColor(hex: 0x1F1F1F)
}
}
}
2021-12-01 03:25:12 +01:00
@objc private func handleRemoteVieioViewTapped(gesture: UITapGestureRecognizer) {
2022-04-07 09:02:57 +02:00
let isHidden = callDurationLabel.alpha < 0.5
2021-12-01 03:25:12 +01:00
UIView.animate(withDuration: 0.5) {
self.operationPanel.alpha = isHidden ? 1 : 0
self.responsePanel.alpha = isHidden ? 1 : 0
2022-04-07 09:02:57 +02:00
self.callDurationLabel.alpha = isHidden ? 1 : 0
2021-12-01 03:25:12 +01:00
}
}
2021-08-16 06:40:07 +02:00
}