diff --git a/Session/Calls/CallVC.swift b/Session/Calls/CallVC.swift index af43db4f6..ab7a5f405 100644 --- a/Session/Calls/CallVC.swift +++ b/Session/Calls/CallVC.swift @@ -233,6 +233,11 @@ final class CallVC : UIViewController, VideoPreviewDelegate { } } } + NotificationCenter.default.addObserver(self, selector: #selector(audioRouteDidChange), name: AVAudioSession.routeChangeNotification, object: nil) + } + + deinit { + NotificationCenter.default.removeObserver(self) } func setUpViewHierarchy() { @@ -309,7 +314,7 @@ final class CallVC : UIViewController, VideoPreviewDelegate { if (call.isVideoEnabled && shouldRestartCamera) { cameraManager.stop() } } - // MARK: Interaction + // MARK: Call signalling func handleAnswerMessage(_ message: CallMessage) { callInfoLabel.text = "Connecting..." } @@ -351,6 +356,7 @@ final class CallVC : UIViewController, VideoPreviewDelegate { } } + // MARK: Minimize to a floating view @objc private func minimize() { self.shouldRestartCamera = false let miniCallView = MiniCallView(from: self) @@ -359,6 +365,7 @@ final class CallVC : UIViewController, VideoPreviewDelegate { presentingViewController?.dismiss(animated: true, completion: nil) } + // MARK: Video and Audio @objc private func operateCamera() { if (call.isVideoEnabled) { localVideoView.isHidden = true @@ -399,6 +406,45 @@ final class CallVC : UIViewController, VideoPreviewDelegate { } } + @objc private func audioRouteDidChange() { + let currentSession = AVAudioSession.sharedInstance() + let currentRoute = currentSession.currentRoute + if let currentOutput = currentRoute.outputs.first { + switch currentOutput.portType { + case .builtInReceiver: + let image = UIImage(named: "Speaker")?.withRenderingMode(.alwaysTemplate) + volumeView.setRouteButtonImage(image, for: .normal) + volumeView.tintColor = .white + volumeView.backgroundColor = UIColor(hex: 0x1F1F1F) + 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 + default: + break + } + } + print(currentRoute.outputs) + } + + // MARK: Pan gesture handling @objc private func handlePanGesture(gesture: UIPanGestureRecognizer) { let location = gesture.location(in: self.view) if let draggedView = gesture.view { diff --git a/Session/Meta/Images.xcassets/Session/Airpods.imageset/Airpods.pdf b/Session/Meta/Images.xcassets/Session/Airpods.imageset/Airpods.pdf new file mode 100644 index 000000000..696a6fd4b Binary files /dev/null and b/Session/Meta/Images.xcassets/Session/Airpods.imageset/Airpods.pdf differ diff --git a/Session/Meta/Images.xcassets/Session/Airpods.imageset/Contents.json b/Session/Meta/Images.xcassets/Session/Airpods.imageset/Contents.json new file mode 100644 index 000000000..6bea31126 --- /dev/null +++ b/Session/Meta/Images.xcassets/Session/Airpods.imageset/Contents.json @@ -0,0 +1,12 @@ +{ + "images" : [ + { + "filename" : "Airpods.pdf", + "idiom" : "universal" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/Session/Meta/Images.xcassets/Session/Bluetooth.imageset/Bluetooth.pdf b/Session/Meta/Images.xcassets/Session/Bluetooth.imageset/Bluetooth.pdf new file mode 100644 index 000000000..d725fa2e4 Binary files /dev/null and b/Session/Meta/Images.xcassets/Session/Bluetooth.imageset/Bluetooth.pdf differ diff --git a/Session/Meta/Images.xcassets/Session/Bluetooth.imageset/Contents.json b/Session/Meta/Images.xcassets/Session/Bluetooth.imageset/Contents.json new file mode 100644 index 000000000..d7ed33397 --- /dev/null +++ b/Session/Meta/Images.xcassets/Session/Bluetooth.imageset/Contents.json @@ -0,0 +1,12 @@ +{ + "images" : [ + { + "filename" : "Bluetooth.pdf", + "idiom" : "universal" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/Session/Meta/Images.xcassets/Session/Headsets.imageset/Contents.json b/Session/Meta/Images.xcassets/Session/Headsets.imageset/Contents.json new file mode 100644 index 000000000..85eb7561e --- /dev/null +++ b/Session/Meta/Images.xcassets/Session/Headsets.imageset/Contents.json @@ -0,0 +1,12 @@ +{ + "images" : [ + { + "filename" : "Headsets.pdf", + "idiom" : "universal" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/Session/Meta/Images.xcassets/Session/Headsets.imageset/Headsets.pdf b/Session/Meta/Images.xcassets/Session/Headsets.imageset/Headsets.pdf new file mode 100644 index 000000000..dd9cc0d4c Binary files /dev/null and b/Session/Meta/Images.xcassets/Session/Headsets.imageset/Headsets.pdf differ