Skip to content

Commit

Permalink
(ScreenSharing): mute button added
Browse files Browse the repository at this point in the history
  • Loading branch information
YesVladess committed May 31, 2023
1 parent 2d9f4c2 commit 067aa41
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 20 deletions.
11 changes: 10 additions & 1 deletion ScreenSharing/Services/CallManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
42 changes: 35 additions & 7 deletions ScreenSharing/Stories/CallViewController.swift
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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?
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -142,18 +167,21 @@ 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 {
static let screenOld = CallOptionButtonModel(image: UIImage(named: "screenSharing"), text: "Screen")
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")
}
}
35 changes: 23 additions & 12 deletions ScreenSharing/Stories/Storyboards/Call.storyboard
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="16097" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
<device id="retina6_1" orientation="landscape" appearance="light"/>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="21507" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
<device id="retina6_1" orientation="portrait" appearance="light"/>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="16087"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="21505"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="System colors in document resources" minToolsVersion="11.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
Expand All @@ -13,22 +14,26 @@
<objects>
<viewController storyboardIdentifier="CallViewController" modalTransitionStyle="crossDissolve" modalPresentationStyle="fullScreen" id="lXc-bE-qju" customClass="CallViewController" customModule="ScreenSharing" customModuleProvider="target" sceneMemberID="viewController">
<view key="view" contentMode="scaleToFill" id="tjM-Yt-clB">
<rect key="frame" x="0.0" y="0.0" width="896" height="414"/>
<rect key="frame" x="0.0" y="0.0" width="414" height="896"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="T0h-N4-6gM" customClass="ConferenceView" customModule="ScreenSharing" customModuleProvider="target">
<rect key="frame" x="121" y="2" width="731" height="389"/>
<rect key="frame" x="0.0" y="50" width="414" height="730"/>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
</view>
<stackView opaque="NO" contentMode="scaleToFill" axis="vertical" distribution="equalSpacing" spacing="16" translatesAutoresizingMaskIntoConstraints="NO" id="Zjy-PN-zVg">
<rect key="frame" x="60" y="123.5" width="45" height="167"/>
<rect key="frame" x="83" y="788" width="248" height="70"/>
<subviews>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="hFu-ye-gm0" customClass="CallOptionButton" customModule="ScreenSharing" customModuleProvider="target">
<rect key="frame" x="0.0" y="0.0" width="45" height="45"/>
<rect key="frame" x="0.0" y="0.0" width="50" height="70"/>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
</view>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="bvf-hv-WgN" userLabel="Mute Button" customClass="CallOptionButton" customModule="ScreenSharing" customModuleProvider="target">
<rect key="frame" x="66" y="0.0" width="50" height="70"/>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
</view>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="chO-89-Yb9" customClass="CallOptionButton" customModule="ScreenSharing" customModuleProvider="target">
<rect key="frame" x="0.0" y="61" width="45" height="45"/>
<rect key="frame" x="132" y="0.0" width="50" height="70"/>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<constraints>
<constraint firstAttribute="height" constant="45" id="Whp-r5-cfG"/>
Expand All @@ -45,7 +50,7 @@
</variation>
</view>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="ZfP-kl-nOy" customClass="CallOptionButton" customModule="ScreenSharing" customModuleProvider="target">
<rect key="frame" x="0.0" y="122" width="45" height="45"/>
<rect key="frame" x="198" y="0.0" width="50" height="70"/>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
</view>
</subviews>
Expand Down Expand Up @@ -75,6 +80,7 @@
</variation>
</stackView>
</subviews>
<viewLayoutGuide key="safeArea" id="X75-Rp-ZZc"/>
<color key="backgroundColor" red="0.10980392160000001" green="0.043137254899999998" blue="0.26274509800000001" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstItem="T0h-N4-6gM" firstAttribute="trailing" secondItem="X75-Rp-ZZc" secondAttribute="trailing" id="6Ed-nX-f5a"/>
Expand All @@ -88,7 +94,6 @@
<constraint firstItem="T0h-N4-6gM" firstAttribute="top" secondItem="X75-Rp-ZZc" secondAttribute="top" constant="2" id="j6V-bb-8rG"/>
<constraint firstItem="X75-Rp-ZZc" firstAttribute="bottom" secondItem="T0h-N4-6gM" secondAttribute="bottom" constant="2" id="ylj-Zz-zal"/>
</constraints>
<viewLayoutGuide key="safeArea" id="X75-Rp-ZZc"/>
<variation key="default">
<mask key="constraints">
<exclude reference="ylj-Zz-zal"/>
Expand All @@ -113,6 +118,7 @@
<connections>
<outlet property="conferenceView" destination="T0h-N4-6gM" id="hvd-yL-7T6"/>
<outlet property="hangupButton" destination="ZfP-kl-nOy" id="WsV-cj-U8r"/>
<outlet property="muteButton" destination="bvf-hv-WgN" id="CiQ-HA-QAI"/>
<outlet property="sharingButton" destination="chO-89-Yb9" id="CjM-b0-QQv"/>
<outlet property="videoButton" destination="hFu-ye-gm0" id="ANy-h1-WTv"/>
</connections>
Expand All @@ -136,10 +142,10 @@
<objects>
<viewController storyboardIdentifier="CallFailedViewController" modalTransitionStyle="crossDissolve" modalPresentationStyle="fullScreen" id="etP-PU-pd4" customClass="CallFailedViewController" customModule="ScreenSharing" customModuleProvider="target" sceneMemberID="viewController">
<view key="view" contentMode="scaleToFill" id="uSO-4c-pCo" customClass="DefaultCallFailedView" customModule="ScreenSharing" customModuleProvider="target">
<rect key="frame" x="0.0" y="0.0" width="896" height="414"/>
<rect key="frame" x="0.0" y="0.0" width="414" height="896"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" systemColor="systemBackgroundColor" cocoaTouchSystemColor="whiteColor"/>
<viewLayoutGuide key="safeArea" id="pMn-C2-FaM"/>
<color key="backgroundColor" systemColor="systemBackgroundColor"/>
</view>
<connections>
<outlet property="callFailedView" destination="uSO-4c-pCo" id="Sp3-Ar-zjL"/>
Expand All @@ -150,4 +156,9 @@
<point key="canvasLocation" x="1461" y="125"/>
</scene>
</scenes>
<resources>
<systemColor name="systemBackgroundColor">
<color white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
</systemColor>
</resources>
</document>
4 changes: 4 additions & 0 deletions Shared/UI/CallOptionButton/CallOptionButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,8 @@ final class CallOptionButton: UIView, NibLoadable {
@IBAction private func touchUpInside(_ sender: UIButton) {
touchUpHandler?(self)
}

func updateButtonLabel(text: String) {
buttonDescriptionLabel.text = text
}
}

0 comments on commit 067aa41

Please sign in to comment.