From 067aa41396b2b181331de5b1d3bafcdb63298206 Mon Sep 17 00:00:00 2001 From: Vlad Kononenko Date: Wed, 31 May 2023 14:44:29 +0600 Subject: [PATCH] (ScreenSharing): mute button added --- ScreenSharing/Services/CallManager.swift | 11 ++++- .../Stories/CallViewController.swift | 42 +++++++++++++++---- .../Stories/Storyboards/Call.storyboard | 35 ++++++++++------ .../CallOptionButton/CallOptionButton.swift | 4 ++ 4 files changed, 72 insertions(+), 20 deletions(-) diff --git a/ScreenSharing/Services/CallManager.swift b/ScreenSharing/Services/CallManager.swift index 2ee6f3f..acdceba 100644 --- a/ScreenSharing/Services/CallManager.swift +++ b/ScreenSharing/Services/CallManager.swift @@ -160,7 +160,16 @@ final class CallManager: completion(nil) } } - + + func toggleMuteStatus(_ completion: @escaping (Error?) -> Void) { + guard let wrapper = managedCallWrapper else { + completion(CallError.hasNoActiveCall) + return + } + wrapper.call.sendAudio = !wrapper.call.sendAudio + completion(nil) + } + func endCall() throws { guard let call = managedCallWrapper?.call else { throw CallError.hasNoActiveCall diff --git a/ScreenSharing/Stories/CallViewController.swift b/ScreenSharing/Stories/CallViewController.swift index 9c4cb48..2169da2 100644 --- a/ScreenSharing/Stories/CallViewController.swift +++ b/ScreenSharing/Stories/CallViewController.swift @@ -1,6 +1,6 @@ /* -* Copyright (c) 2011-2020, Zingaya, Inc. All rights reserved. -*/ + * Copyright (c) 2011-2020, Zingaya, Inc. All rights reserved. + */ import UIKit import VoxImplantSDK @@ -10,6 +10,7 @@ final class CallViewController: UIViewController { override var supportedInterfaceOrientations: UIInterfaceOrientationMask { .all } @IBOutlet private weak var conferenceView: ConferenceView! @IBOutlet private weak var videoButton: CallOptionButton! + @IBOutlet private weak var muteButton: CallOptionButton! @IBOutlet private weak var sharingButton: CallOptionButton! @IBOutlet private weak var hangupButton: CallOptionButton! private var screenSharingButtonSubview: UIImageView? @@ -41,7 +42,31 @@ final class CallViewController: UIViewController { button.state = previousState } } - + + muteButton.state = .initial(model: CallOptionButtonModels.mute) + muteButton.state = .normal + muteButton.touchUpHandler = { [weak self] button in + Log.d("Changing mute status") + + let previousState = button.state + button.state = .unavailable + + self?.callManager.toggleMuteStatus { error in + if let error = error { + Log.e("sendAudio error \(error.localizedDescription)") + AlertHelper.showError(message: error.localizedDescription, on: self) + } + button.state = previousState + if button.state == .normal { + button.state = .selected + button.updateButtonLabel(text: "Unmute") + } else { + button.state = .normal + button.updateButtonLabel(text: "Mute") + } + } + } + if #available(iOS 12.0, *) { sharingButton.state = .initial(model: CallOptionButtonModels.screen) } else { @@ -142,12 +167,12 @@ final class CallViewController: UIViewController { screenSharingButtonSubview?.tintColor = call.sharingScreen ? #colorLiteral(red: 0.9607843137, green: 0.2941176471, blue: 0.368627451, alpha: 1) : .white } else { sharingButton.state = call.state == .connected - ? call.sharingScreen ? .selected : .normal - : .unavailable + ? call.sharingScreen ? .selected : .normal + : .unavailable } videoButton.state = call.state == .connected - ? call.sendingVideo ? .normal : .selected - : .unavailable + ? call.sendingVideo ? .normal : .selected + : .unavailable } private enum CallOptionButtonModels { @@ -155,5 +180,8 @@ final class CallViewController: UIViewController { static let screen = CallOptionButtonModel(image: nil, text: "Screen") static let camera = CallOptionButtonModel(image: UIImage(named: "videoOn"), imageSelected: UIImage(named: "videoOff"), text: "Camera") static let hangup = CallOptionButtonModel(image: UIImage(named: "hangup"), imageTint: #colorLiteral(red: 1, green: 0.02352941176, blue: 0.2549019608, alpha: 1), text: "Hangup") + static let mute = CallOptionButtonModel(image: UIImage(named: "micOn"), + imageSelected: UIImage(named: "micOff"), + text: "Mute") } } diff --git a/ScreenSharing/Stories/Storyboards/Call.storyboard b/ScreenSharing/Stories/Storyboards/Call.storyboard index 8f27e9d..4c05d2b 100644 --- a/ScreenSharing/Stories/Storyboards/Call.storyboard +++ b/ScreenSharing/Stories/Storyboards/Call.storyboard @@ -1,10 +1,11 @@ - - + + - + + @@ -13,22 +14,26 @@ - + - + - + - + + + + + - + @@ -45,7 +50,7 @@ - + @@ -75,6 +80,7 @@ + @@ -88,7 +94,6 @@ - @@ -113,6 +118,7 @@ + @@ -136,10 +142,10 @@ - + - + @@ -150,4 +156,9 @@ + + + + + diff --git a/Shared/UI/CallOptionButton/CallOptionButton.swift b/Shared/UI/CallOptionButton/CallOptionButton.swift index 7987fbb..3aa9efd 100644 --- a/Shared/UI/CallOptionButton/CallOptionButton.swift +++ b/Shared/UI/CallOptionButton/CallOptionButton.swift @@ -82,4 +82,8 @@ final class CallOptionButton: UIView, NibLoadable { @IBAction private func touchUpInside(_ sender: UIButton) { touchUpHandler?(self) } + + func updateButtonLabel(text: String) { + buttonDescriptionLabel.text = text + } }