Skip to content

Commit cabaeb9

Browse files
committed
FIX: MS-26335
1 parent 7c14d10 commit cabaeb9

4 files changed

Lines changed: 87 additions & 35 deletions

File tree

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
//
2+
// AgoraState.swift
3+
// APIExample
4+
//
5+
// Created by XC on 2020/12/18.
6+
// Copyright © 2020 Agora Corp. All rights reserved.
7+
//
8+
9+
import Foundation
10+
11+
protocol AgoraState {
12+
var isJoined: Bool { get set }
13+
var agoraKit: AgoraRtcEngineKit! { get set }
14+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
//
2+
// RolePicker.swift
3+
// APIExample
4+
//
5+
// Created by XC on 2020/12/18.
6+
// Copyright © 2020 Agora Corp. All rights reserved.
7+
//
8+
9+
import Cocoa
10+
import AgoraRtcKit
11+
12+
class RolePicker: NSPopUpButton {
13+
14+
private let roles = AgoraClientRole.allValues()
15+
var agoraState: AgoraState?
16+
17+
var role: AgoraClientRole {
18+
get {
19+
roles[indexOfSelectedItem >= 0 && indexOfSelectedItem < roles.count ? indexOfSelectedItem : 0]
20+
}
21+
}
22+
23+
@IBAction func onSelect(_ sender: RolePicker) {
24+
guard let join = agoraState?.isJoined else { return }
25+
if join {
26+
agoraState?.agoraKit?.setClientRole(roles[sender.indexOfSelectedItem])
27+
}
28+
}
29+
30+
required init?(coder: NSCoder) {
31+
super.init(coder: coder)
32+
addItems(withTitles: roles.map { $0.description() })
33+
target = self
34+
action = #selector(onSelect)
35+
}
36+
}
37+

macOS/APIExample/Examples/Basic/JoinChannelVideo/Base.lproj/JoinChannelVideo.storyboard

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<document type="com.apple.InterfaceBuilder3.Cocoa.Storyboard.XIB" version="3.0" toolsVersion="16097.2" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
2+
<document type="com.apple.InterfaceBuilder3.Cocoa.Storyboard.XIB" version="3.0" toolsVersion="17701" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
33
<dependencies>
4-
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="16097.2"/>
4+
<deployment identifier="macosx"/>
5+
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="17701"/>
56
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
67
</dependencies>
78
<scenes>
@@ -13,21 +14,21 @@
1314
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
1415
<subviews>
1516
<customView translatesAutoresizingMaskIntoConstraints="NO" id="r7G-ng-73B" customClass="AGEVideoContainer" customModule="AGEVideoLayout">
16-
<rect key="frame" x="0.0" y="102" width="600" height="498"/>
17+
<rect key="frame" x="0.0" y="100" width="600" height="500"/>
1718
</customView>
1819
<popUpButton verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="9b9-Hz-pR8">
19-
<rect key="frame" x="18" y="37" width="319" height="25"/>
20+
<rect key="frame" x="17" y="36" width="313" height="25"/>
2021
<popUpButtonCell key="cell" type="push" bezelStyle="rounded" alignment="left" lineBreakMode="truncatingTail" borderStyle="borderAndBezel" imageScaling="proportionallyDown" inset="2" id="7Bn-cL-ViN">
2122
<behavior key="behavior" lightByBackground="YES" lightByGray="YES"/>
22-
<font key="font" metaFont="system"/>
23+
<font key="font" metaFont="menu"/>
2324
<menu key="menu" id="7ac-8i-oPa"/>
2425
</popUpButtonCell>
2526
</popUpButton>
2627
<popUpButton verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="V5w-Eq-ICP">
27-
<rect key="frame" x="18" y="68" width="319" height="25"/>
28+
<rect key="frame" x="17" y="66" width="313" height="25"/>
2829
<popUpButtonCell key="cell" type="push" bezelStyle="rounded" alignment="left" lineBreakMode="truncatingTail" borderStyle="borderAndBezel" imageScaling="proportionallyDown" inset="2" id="5MF-QB-kBW">
2930
<behavior key="behavior" lightByBackground="YES" lightByGray="YES"/>
30-
<font key="font" metaFont="system"/>
31+
<font key="font" metaFont="menu"/>
3132
<menu key="menu" id="D8h-GC-UC3"/>
3233
</popUpButtonCell>
3334
</popUpButton>
@@ -44,7 +45,7 @@
4445
</textFieldCell>
4546
</textField>
4647
<button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="yEf-Yg-oqG">
47-
<rect key="frame" x="264" y="3" width="76" height="32"/>
48+
<rect key="frame" x="263" y="3" width="70" height="32"/>
4849
<buttonCell key="cell" type="push" title="Join" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="guU-jX-Wkg">
4950
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
5051
<font key="font" metaFont="system"/>
@@ -54,7 +55,7 @@
5455
</connections>
5556
</button>
5657
<button hidden="YES" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="ddJ-7d-bc6">
57-
<rect key="frame" x="264" y="3" width="76" height="32"/>
58+
<rect key="frame" x="263" y="3" width="70" height="32"/>
5859
<buttonCell key="cell" type="push" title="Leave" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="4rc-r1-Ay6">
5960
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
6061
<font key="font" metaFont="system"/>
@@ -64,32 +65,32 @@
6465
</connections>
6566
</button>
6667
<popUpButton verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="kOG-V2-gqP">
67-
<rect key="frame" x="342" y="68" width="105" height="25"/>
68+
<rect key="frame" x="333" y="66" width="107" height="25"/>
6869
<constraints>
6970
<constraint firstAttribute="width" constant="100" id="iMm-Su-tF5"/>
7071
</constraints>
7172
<popUpButtonCell key="cell" type="push" bezelStyle="rounded" alignment="left" lineBreakMode="truncatingTail" borderStyle="borderAndBezel" imageScaling="proportionallyDown" inset="2" id="f2f-yn-N9u">
7273
<behavior key="behavior" lightByBackground="YES" lightByGray="YES"/>
73-
<font key="font" metaFont="system"/>
74+
<font key="font" metaFont="menu"/>
7475
<menu key="menu" id="gXU-eH-vAU"/>
7576
</popUpButtonCell>
7677
</popUpButton>
7778
<popUpButton verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="ER1-7Z-LZg">
78-
<rect key="frame" x="452" y="68" width="69" height="25"/>
79+
<rect key="frame" x="443" y="66" width="71" height="25"/>
7980
<constraints>
8081
<constraint firstAttribute="width" constant="64" id="04I-1q-bb1"/>
8182
</constraints>
8283
<popUpButtonCell key="cell" type="push" bezelStyle="rounded" alignment="left" lineBreakMode="truncatingTail" borderStyle="borderAndBezel" imageScaling="proportionallyDown" inset="2" id="tmb-Aw-YTO">
8384
<behavior key="behavior" lightByBackground="YES" lightByGray="YES"/>
84-
<font key="font" metaFont="system"/>
85+
<font key="font" metaFont="menu"/>
8586
<menu key="menu" id="jDX-fe-nCX"/>
8687
</popUpButtonCell>
8788
</popUpButton>
8889
<popUpButton verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="3Eb-5H-nWp">
89-
<rect key="frame" x="342" y="37" width="105" height="25"/>
90+
<rect key="frame" x="333" y="36" width="107" height="25"/>
9091
<popUpButtonCell key="cell" type="push" title="1V1" bezelStyle="rounded" alignment="left" lineBreakMode="truncatingTail" state="on" borderStyle="borderAndBezel" imageScaling="proportionallyDown" inset="2" selectedItem="Iws-j3-l2h" id="mUj-th-4z5">
9192
<behavior key="behavior" lightByBackground="YES" lightByGray="YES"/>
92-
<font key="font" metaFont="system"/>
93+
<font key="font" metaFont="menu"/>
9394
<menu key="menu" id="LQo-uG-rRO">
9495
<items>
9596
<menuItem title="1V1" state="on" id="Iws-j3-l2h"/>
@@ -103,11 +104,11 @@
103104
<action selector="onLayoutChanged:" target="YjT-yy-DnJ" id="zAL-9Z-bsX"/>
104105
</connections>
105106
</popUpButton>
106-
<popUpButton verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="04f-84-lGj">
107-
<rect key="frame" x="342" y="7" width="105" height="25"/>
107+
<popUpButton verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="04f-84-lGj" customClass="RolePicker" customModule="APIExample" customModuleProvider="target">
108+
<rect key="frame" x="333" y="6" width="107" height="25"/>
108109
<popUpButtonCell key="cell" type="push" bezelStyle="rounded" alignment="left" lineBreakMode="truncatingTail" borderStyle="borderAndBezel" imageScaling="proportionallyDown" inset="2" id="Lpb-l7-tF9">
109110
<behavior key="behavior" lightByBackground="YES" lightByGray="YES"/>
110-
<font key="font" metaFont="system"/>
111+
<font key="font" metaFont="menu"/>
111112
<menu key="menu" id="L5f-yn-jkF"/>
112113
</popUpButtonCell>
113114
</popUpButton>

macOS/APIExample/Examples/Basic/JoinChannelVideo/JoinChannelVideo.swift

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ import Cocoa
99
import AgoraRtcKit
1010
import AGEVideoLayout
1111

12-
class JoinChannelVideoMain: BaseViewController {
12+
class JoinChannelVideoMain: BaseViewController, AgoraState {
13+
14+
var agoraKit: AgoraRtcEngineKit!
1315
var videos: [VideoView] = []
1416

1517
@IBOutlet weak var container: AGEVideoContainer!
@@ -21,23 +23,19 @@ class JoinChannelVideoMain: BaseViewController {
2123
@IBOutlet weak var resolutionPicker: NSPopUpButton!
2224
@IBOutlet weak var fpsPicker: NSPopUpButton!
2325
@IBOutlet weak var layoutPicker: NSPopUpButton!
24-
@IBOutlet weak var rolePicker: NSPopUpButton!
25-
var agoraKit: AgoraRtcEngineKit!
26+
@IBOutlet weak var rolePicker: RolePicker!
27+
2628
var cameras:[AgoraRtcDeviceInfo] = [] {
2729
didSet {
2830
DispatchQueue.main.async {[unowned self] in
29-
self.cameraPicker.addItems(withTitles: self.cameras.map({ (device: AgoraRtcDeviceInfo) -> String in
30-
return (device.deviceName ?? "")
31-
}))
31+
self.cameraPicker.addItems(withTitles: self.cameras.map {$0.deviceName ?? "unknown"})
3232
}
3333
}
3434
}
3535
var mics:[AgoraRtcDeviceInfo] = [] {
3636
didSet {
3737
DispatchQueue.main.async {[unowned self] in
38-
self.micPicker.addItems(withTitles: self.mics.map({ (device: AgoraRtcDeviceInfo) -> String in
39-
return (device.deviceName ?? "")
40-
}))
38+
self.micPicker.addItems(withTitles: self.mics.map {$0.deviceName ?? "unknown"})
4139
}
4240
}
4341
}
@@ -63,13 +61,14 @@ class JoinChannelVideoMain: BaseViewController {
6361
// prepare fps picker
6462
fpsPicker.addItems(withTitles: Configs.Fps.map { "\($0)fps" })
6563
fpsPicker.selectItem(at: GlobalSettings.shared.fpsSetting.selectedOption().value)
66-
rolePicker.addItems(withTitles: AgoraClientRole.allValues().map({$0.description()}))
6764

6865
// set up agora instance when view loaded
6966
let config = AgoraRtcEngineConfig()
7067
config.appId = KeyCenter.AppId
7168
config.areaCode = GlobalSettings.shared.area.rawValue
7269
agoraKit = AgoraRtcEngineKit.sharedEngine(with: config, delegate: self)
70+
71+
rolePicker.agoraState = self
7372
// this is mandatory to get camera list
7473
agoraKit.enableVideo()
7574

@@ -82,7 +81,7 @@ class JoinChannelVideoMain: BaseViewController {
8281
}
8382

8483
override func viewWillBeRemovedFromSplitView() {
85-
if(isJoined) {
84+
if isJoined {
8685
agoraKit.leaveChannel { (stats:AgoraChannelStats) in
8786
LogUtils.log(message: "Left channel", level: .info)
8887
}
@@ -101,15 +100,16 @@ class JoinChannelVideoMain: BaseViewController {
101100
// set live broadcaster mode
102101
agoraKit.setChannelProfile(.liveBroadcasting)
103102
// set myself as broadcaster to stream video/audio
104-
agoraKit.setClientRole(AgoraClientRole.allValues()[rolePicker.indexOfSelectedItem])
103+
agoraKit.setClientRole(rolePicker.role)
105104

106105
// enable video module and set up video encoding configs
107106
let resolution = Configs.Resolutions[resolutionPicker.indexOfSelectedItem]
108-
agoraKit.setVideoEncoderConfiguration(AgoraVideoEncoderConfiguration(size: resolution.size(),
109-
frameRate: AgoraVideoFrameRate(rawValue: Configs.Fps[fpsPicker.indexOfSelectedItem]) ?? .fps15,
110-
bitrate: AgoraVideoBitrateStandard,
111-
orientationMode: .adaptative))
112-
107+
agoraKit.setVideoEncoderConfiguration(
108+
AgoraVideoEncoderConfiguration(size: resolution.size(),
109+
frameRate: AgoraVideoFrameRate(rawValue: Configs.Fps[fpsPicker.indexOfSelectedItem]) ?? .fps15,
110+
bitrate: AgoraVideoBitrateStandard,
111+
orientationMode: .adaptative)
112+
)
113113

114114
// set up local video to render your local camera preview
115115
let localVideo = videos[0]

0 commit comments

Comments
 (0)