Skip to content

Commit 938df2a

Browse files
author
zhaoyongqiang
committed
iOS Add the configuration privatization function
1 parent 96dbf46 commit 938df2a

39 files changed

Lines changed: 336 additions & 29 deletions

File tree

iOS/APIExample/APIExample.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@
136136
A7CA48C424553CF700507435 /* Popover.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = A7CA48C224553CF600507435 /* Popover.storyboard */; };
137137
B9C914453E92C7F49C93E1F5 /* Pods_APIExample.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8551A4BC255CE49B383BC575 /* Pods_APIExample.framework */; };
138138
CBCDE23FB64E60D6A79F3723 /* Pods_Agora_ScreenShare_Extension.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 09E72C5D1AABD812866E41A6 /* Pods_Agora_ScreenShare_Extension.framework */; };
139+
E72055EA28F943520030E6D1 /* Util.swift in Sources */ = {isa = PBXBuildFile; fileRef = E72055E928F943520030E6D1 /* Util.swift */; };
139140
E721600F28D3314B006431BD /* AlertManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = E721600E28D3314B006431BD /* AlertManager.swift */; };
140141
E728B84728B5FFCB00674A4A /* PictureInPicture.strings in Resources */ = {isa = PBXBuildFile; fileRef = E728B84228B5FFCB00674A4A /* PictureInPicture.strings */; };
141142
E728B84828B5FFCB00674A4A /* PictureInPicture.swift in Sources */ = {isa = PBXBuildFile; fileRef = E728B84428B5FFCB00674A4A /* PictureInPicture.swift */; };
@@ -385,6 +386,7 @@
385386
A7CA48C324553CF600507435 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Popover.storyboard; sourceTree = "<group>"; };
386387
BC25C1A6D9E6B8827D095985 /* Pods_SimpleFilter.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_SimpleFilter.framework; sourceTree = BUILT_PRODUCTS_DIR; };
387388
CC6D08A23527C200339E4FD6 /* Pods-SimpleAudioFilter.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-SimpleAudioFilter.release.xcconfig"; path = "Target Support Files/Pods-SimpleAudioFilter/Pods-SimpleAudioFilter.release.xcconfig"; sourceTree = "<group>"; };
389+
E72055E928F943520030E6D1 /* Util.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Util.swift; sourceTree = "<group>"; };
388390
E721600E28D3314B006431BD /* AlertManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AlertManager.swift; sourceTree = "<group>"; };
389391
E728B84328B5FFCB00674A4A /* zh-Hans */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "zh-Hans"; path = "zh-Hans.lproj/PictureInPicture.strings"; sourceTree = "<group>"; };
390392
E728B84428B5FFCB00674A4A /* PictureInPicture.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PictureInPicture.swift; sourceTree = "<group>"; };
@@ -838,6 +840,7 @@
838840
children = (
839841
67B8C7B32805757200195106 /* MediaUtils.h */,
840842
67B8C7B42805757200195106 /* MediaUtils.m */,
843+
E72055E928F943520030E6D1 /* Util.swift */,
841844
);
842845
path = Utils;
843846
sourceTree = "<group>";
@@ -1379,6 +1382,7 @@
13791382
8407E0942472320800AC5DE8 /* (null) in Sources */,
13801383
8B5E5B50274CB68E0040E97D /* RhythmPlayer.swift in Sources */,
13811384
036C42B524D2A3C600A59000 /* AgoraMetalRender.swift in Sources */,
1385+
E72055EA28F943520030E6D1 /* Util.swift in Sources */,
13821386
03DF1D9324CFC29700DF7151 /* ExternalAudio.mm in Sources */,
13831387
036CBA4625198F1A00D74FAD /* AgoraCustomEncryption.mm in Sources */,
13841388
E7899BDE2861673600851463 /* CreateDataStream.swift in Sources */,

iOS/APIExample/APIExample/Base.lproj/Main.storyboard

Lines changed: 101 additions & 7 deletions
Large diffs are not rendered by default.

iOS/APIExample/APIExample/Common/GlobalSettings.swift

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class GlobalSettings {
4444
// For the regions that Agora supports, see https://docs.agora.io/en/Interactive%20Broadcast/API%20Reference/oc/Constants/AgoraAreaCode.html. After specifying the region, the SDK connects to the Agora servers within that region.
4545
var area:AgoraAreaCodeType = .global
4646
static let shared = GlobalSettings()
47-
var settings:[String:SettingItem] = [
47+
var settings:[String: SettingItem] = [
4848
"resolution": SettingItem(selected: 3, options: [
4949
SettingItemOption(idx: 0, label: "90x90", value: CGSize(width: 90, height: 90)),
5050
SettingItemOption(idx: 1, label: "160x120", value: CGSize(width: 160, height: 120)),
@@ -69,11 +69,26 @@ class GlobalSettings {
6969
SettingItemOption(idx: 1, label: "audience", value: AgoraClientRole.audience)
7070
]),
7171
]
72-
7372
func getSetting(key:String) -> SettingItem? {
7473
return settings[key]
7574
}
7675

76+
var cache: [String: Any] = [:]
77+
78+
func getCache(key: String) -> String {
79+
(cache[key] as? String) ?? ""
80+
}
81+
func getCache(key: String) -> Bool {
82+
guard let cache = cache[key] as? String,
83+
let value = cache == "1" ? true : false else { return false }
84+
return value
85+
}
86+
func getCache(key: String) -> Int {
87+
guard let cache = cache[key] as? String,
88+
let value = Int(cache) else { return 0 }
89+
return value
90+
}
91+
7792
func getUserRole() -> AgoraClientRole {
7893
let item = settings["role"]
7994
return (item?.selectedOption().value as? AgoraClientRole) ?? .broadcaster

iOS/APIExample/APIExample/Common/Settings/SettingsCells.swift

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,3 +134,60 @@ class SettingsSelectParam: SettingsBaseParam {
134134
super.init(key: key, label: label, type: "SelectCell")
135135
}
136136
}
137+
138+
class SettingsTextFieldCell : SettingsBaseCell
139+
{
140+
@IBOutlet weak var settingLabel: UILabel!
141+
@IBOutlet weak var textField: UITextField!
142+
143+
override func configure(configs: SettingsBaseParam) {
144+
super.configure(configs: configs)
145+
146+
guard let param = configs as? SettingsTextFieldParam else {return}
147+
settingLabel.text = param.label
148+
textField.placeholder = param.placeholder
149+
textField.text = param.text
150+
}
151+
152+
@IBAction func onTextFieldChanged(_ sender: UITextField) {
153+
guard let configs = self.configs as? SettingsTextFieldParam else {return}
154+
delegate?.didChangeValue(type: "SettingsTextFieldCell", key: configs.key, value: sender.text ?? "")
155+
}
156+
}
157+
158+
class SettingsTextFieldParam: SettingsBaseParam {
159+
var text: String?
160+
var placeholder: String?
161+
init(key: String, label: String, text: String? = nil, placeHolder: String? = nil) {
162+
super.init(key: key, label: label, type: "TextFieldCell")
163+
self.text = text
164+
self.placeholder = placeHolder
165+
}
166+
}
167+
168+
class SettingsSwitchCell : SettingsBaseCell
169+
{
170+
@IBOutlet weak var settingLabel: UILabel!
171+
@IBOutlet weak var uiSwitch: UISwitch!
172+
173+
override func configure(configs: SettingsBaseParam) {
174+
super.configure(configs: configs)
175+
176+
guard let param = configs as? SettingsSwitchParam else {return}
177+
settingLabel.text = param.label
178+
uiSwitch.isOn = param.isOn
179+
}
180+
181+
@IBAction func onSwitchChanged(sender: UISwitch){
182+
guard let configs = self.configs as? SettingsSwitchParam else {return}
183+
delegate?.didChangeValue(type: "SettingsSwitchCell", key: configs.key, value: "\(uiSwitch.isOn ? 1 : 0)")
184+
}
185+
}
186+
187+
class SettingsSwitchParam: SettingsBaseParam {
188+
var isOn: Bool = false
189+
init(key: String, label: String, isOn: Bool = false) {
190+
super.init(key: key, label: label, type: "SwitchCell")
191+
self.isOn = isOn
192+
}
193+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
//
2+
// Util.swift
3+
// APIExample
4+
//
5+
// Created by zhaoyongqiang on 2022/10/14.
6+
// Copyright © 2022 Agora Corp. All rights reserved.
7+
//
8+
9+
import UIKit
10+
11+
enum Util {
12+
13+
/// Configuring Privatization Parameters
14+
static func configPrivatization(agoraKit: AgoraRtcEngineKit) {
15+
if !GlobalSettings.shared.getCache(key: "ip").isEmpty {
16+
let localAccessPointConfig = AgoraLocalAccessPointConfiguration()
17+
localAccessPointConfig.ipList = ["\(GlobalSettings.shared.getCache(key: "ip"))"]
18+
localAccessPointConfig.mode = .localOnly
19+
if GlobalSettings.shared.getCache(key: "report") {
20+
let advancedConfig = AdvancedConfigInfo()
21+
let logUploadServer = LogUploadServerInfo()
22+
logUploadServer.serverDomain = GlobalSettings.shared.getCache(key: "log_server_domain")
23+
logUploadServer.serverPort = GlobalSettings.shared.getCache(key: "log_server_port")
24+
logUploadServer.serverPath = GlobalSettings.shared.getCache(key: "log_server_path")
25+
logUploadServer.serverHttps = GlobalSettings.shared.getCache(key: "log_server_https")
26+
advancedConfig.logUploadServer = logUploadServer
27+
localAccessPointConfig.advancedConfig = advancedConfig
28+
}
29+
agoraKit.setLocalAccessPoint(withConfig: localAccessPointConfig)
30+
}
31+
}
32+
}

iOS/APIExample/APIExample/Examples/Advanced/AudioMixing/AudioMixing.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,8 @@ class AudioMixingMain: BaseViewController {
106106
config.audioScenario = audioScenario
107107

108108
agoraKit = AgoraRtcEngineKit.sharedEngine(with: config, delegate: self)
109+
// Configuring Privatization Parameters
110+
Util.configPrivatization(agoraKit: agoraKit)
109111
agoraKit.setLogFile(LogUtils.sdkLogPath())
110112

111113
// make myself a broadcaster

iOS/APIExample/APIExample/Examples/Advanced/ContentInspect/ContentInspect.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ class ContentInspectViewController: BaseViewController {
3232
guard let channelId = configs["channelName"] as? String else {return}
3333

3434
agoraKit = AgoraRtcEngineKit.sharedEngine(withAppId: KeyCenter.AppId, delegate: self)
35+
// Configuring Privatization Parameters
36+
Util.configPrivatization(agoraKit: agoraKit)
37+
3538
agoraKit.enableVideo()
3639
agoraKit.enableAudio()
3740

iOS/APIExample/APIExample/Examples/Advanced/CreateDataStream/CreateDataStream.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ class CreateDataStreamMain: BaseViewController {
6565
config.areaCode = GlobalSettings.shared.area
6666
config.channelProfile = .liveBroadcasting
6767
agoraKit = AgoraRtcEngineKit.sharedEngine(with: config, delegate: self)
68+
// Configuring Privatization Parameters
69+
Util.configPrivatization(agoraKit: agoraKit)
70+
6871
agoraKit.setLogFile(LogUtils.sdkLogPath())
6972

7073
// get channel name from configs

iOS/APIExample/APIExample/Examples/Advanced/CustomAudioRender/CustomAudioRender.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ class CustomAudioRenderMain: BaseViewController {
5555
config.areaCode = GlobalSettings.shared.area
5656
config.channelProfile = .liveBroadcasting
5757
agoraKit = AgoraRtcEngineKit.sharedEngine(with: config, delegate: self)
58+
// Configuring Privatization Parameters
59+
Util.configPrivatization(agoraKit: agoraKit)
5860
agoraKit.setLogFile(LogUtils.sdkLogPath())
5961

6062
guard let channelName = configs["channelName"] as? String else {return}

iOS/APIExample/APIExample/Examples/Advanced/CustomAudioSource/CustomAudioSource.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ class CustomAudioSourceMain: BaseViewController {
5555
config.areaCode = GlobalSettings.shared.area
5656
config.channelProfile = .liveBroadcasting
5757
agoraKit = AgoraRtcEngineKit.sharedEngine(with: config, delegate: self)
58+
// Configuring Privatization Parameters
59+
Util.configPrivatization(agoraKit: agoraKit)
5860
agoraKit.setLogFile(LogUtils.sdkLogPath())
5961

6062
guard let channelName = configs["channelName"] as? String else {

0 commit comments

Comments
 (0)