Skip to content

Commit 93309f9

Browse files
author
Xia Ning
committed
adapt SDK 3.4.5
1 parent 59d6989 commit 93309f9

6 files changed

Lines changed: 90 additions & 9 deletions

File tree

macOS/APIExample/Commons/AgoraExtension.swift

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,21 @@ extension AgoraClientRole {
8787
}
8888
}
8989

90+
extension AgoraVideoBackgroundSourceType {
91+
func description() -> String {
92+
switch self {
93+
case .none: return "None".localized
94+
case .color: return "Colored Background".localized
95+
case .img: return "Image Background".localized
96+
default:
97+
return "\(self.rawValue)"
98+
}
99+
}
100+
static func allValues() -> [AgoraVideoBackgroundSourceType] {
101+
return [.none, .color, .img]
102+
}
103+
}
104+
90105
extension AgoraAudioScenario {
91106
func description() -> String {
92107
switch self {
@@ -109,17 +124,15 @@ extension AgoraAudioScenario {
109124
extension AgoraEncryptionMode {
110125
func description() -> String {
111126
switch self {
112-
case .AES128XTS: return "AES128XTS"
113-
case .AES256XTS: return "AES256XTS"
114-
case .AES128ECB: return "AES128ECB"
115-
case .SM4128ECB: return "SM4128ECB"
127+
case .AES128GCM2: return "AES128GCM2"
128+
case .AES256GCM2: return "AES256GCM2"
116129
default:
117130
return "\(self.rawValue)"
118131
}
119132
}
120133

121134
static func allValues() -> [AgoraEncryptionMode] {
122-
return [.AES128XTS, .AES256XTS, .AES128ECB, .SM4128ECB]
135+
return [.AES128GCM2, .AES256GCM2]
123136
}
124137
}
125138

macOS/APIExample/Examples/Advanced/JoinMultiChannel/JoinMultiChannel.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,8 @@ class JoinMultipleChannel: BaseViewController {
117117
let mediaOptions = AgoraRtcChannelMediaOptions()
118118
mediaOptions.autoSubscribeAudio = true
119119
mediaOptions.autoSubscribeVideo = true
120+
mediaOptions.publishLocalAudio = false
121+
mediaOptions.publishLocalVideo = false
120122

121123
var channel: AgoraRtcChannel?
122124
if channel2 == nil {

macOS/APIExample/Examples/Advanced/StreamEncryption/StreamEncryption.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,7 @@ class StreamEncryption: BaseViewController {
243243
let config = AgoraEncryptionConfig()
244244
config.encryptionMode = selectedEncrption!
245245
config.encryptionKey = encryptionSecretField.stringValue
246+
config.encryptionKdfSalt = getEncryptionSaltFromServer()
246247
let ret = agoraKit.enableEncryption(true, encryptionConfig: config)
247248
if ret != 0 {
248249
// for errors please take a look at:
@@ -296,6 +297,11 @@ class StreamEncryption: BaseViewController {
296297
}
297298
}
298299

300+
func getEncryptionSaltFromServer() -> Data {
301+
302+
return "EncryptionKdfSaltInBase64Strings".data(using: .utf8)!
303+
}
304+
299305
func layoutVideos(_ count: Int) {
300306
videos = []
301307
for i in 0...count - 1 {

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,15 @@
4949
<autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMinY="YES"/>
5050
</view>
5151
<view id="zNc-vL-43g" customClass="Picker" customModule="APIExample" customModuleProvider="target">
52-
<rect key="frame" x="27" y="183" width="260" height="50"/>
52+
<rect key="frame" x="27" y="223" width="260" height="50"/>
53+
<autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMinY="YES"/>
54+
</view>
55+
<view id="Pvr-Dh-TRD" customClass="Picker" customModule="APIExample" customModuleProvider="target">
56+
<rect key="frame" x="27" y="107" width="260" height="50"/>
5357
<autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMinY="YES"/>
5458
</view>
5559
<view id="SX5-NX-wxs" customClass="Picker" customModule="APIExample" customModuleProvider="target">
56-
<rect key="frame" x="27" y="232" width="260" height="50"/>
60+
<rect key="frame" x="27" y="165" width="260" height="50"/>
5761
<autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMinY="YES"/>
5862
</view>
5963
</subviews>
@@ -126,6 +130,7 @@
126130
<outlet property="Container" destination="r7G-ng-73B" id="YGH-31-sQ1"/>
127131
<outlet property="channelField" destination="cOW-S1-5WE" id="jDn-mo-xGn"/>
128132
<outlet property="joinChannelButton" destination="Wck-kx-dah" id="7Zo-gi-hFo"/>
133+
<outlet property="selectBackgroundPicker" destination="Pvr-Dh-TRD" id="9nr-pb-br2"/>
129134
<outlet property="selectCameraPicker" destination="Wvv-X8-f7U" id="pNv-K1-sH1"/>
130135
<outlet property="selectFpsPicker" destination="jHK-UU-E1C" id="agM-jd-ePJ"/>
131136
<outlet property="selectLayoutPicker" destination="SX5-NX-wxs" id="Xf2-oi-ivY"/>

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

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,28 @@ class JoinChannelVideoMain: BaseViewController {
218218
}
219219
}
220220

221+
/**
222+
--- Background Picker ---
223+
*/
224+
@IBOutlet weak var selectBackgroundPicker: Picker!
225+
private let backgroundTypes = AgoraVideoBackgroundSourceType.allValues()
226+
var selectedBackgroundType: AgoraVideoBackgroundSourceType? {
227+
let index = self.selectBackgroundPicker.indexOfSelectedItem
228+
if index >= 0 && index < backgroundTypes.count {
229+
return backgroundTypes[index]
230+
} else {
231+
return nil
232+
}
233+
}
234+
func initSelectBackgroundPicker() {
235+
selectBackgroundPicker.label.stringValue = "Camera Background Setting".localized
236+
selectBackgroundPicker.picker.addItems(withTitles: backgroundTypes.map { $0.description() })
237+
selectBackgroundPicker.onSelectChanged {
238+
guard self.selectedBackgroundType != nil else { return }
239+
self.setBackground()
240+
}
241+
}
242+
221243
/**
222244
--- Channel TextField ---
223245
*/
@@ -259,17 +281,36 @@ class JoinChannelVideoMain: BaseViewController {
259281
config.areaCode = GlobalSettings.shared.area.rawValue
260282
agoraKit = AgoraRtcEngineKit.sharedEngine(with: config, delegate: self)
261283
agoraKit.enableVideo()
262-
284+
setBackground()
263285
initSelectCameraPicker()
264286
initSelectResolutionPicker()
265287
initSelectFpsPicker()
266288
initSelectMicsPicker()
267289
initSelectLayoutPicker()
268290
initSelectRolePicker()
291+
initSelectBackgroundPicker()
269292
initChannelField()
270293
initJoinChannelButton()
271294
}
272295

296+
private func setBackground(){
297+
let backgroundSource = AgoraVideoBackgroundSource()
298+
backgroundSource.backgroundSourceType = selectedBackgroundType ?? .none
299+
switch self.selectedBackgroundType {
300+
case .color:
301+
backgroundSource.color = 0x000000
302+
case .img:
303+
if let resourcePath = Bundle.main.resourcePath {
304+
let imgName = "bg.jpg"
305+
let path = resourcePath + "/" + imgName
306+
backgroundSource.source = path
307+
}
308+
default:
309+
break
310+
}
311+
agoraKit.enableVideoBackgroundSubstitution(true, backData: backgroundSource)
312+
}
313+
273314
func layoutVideos(_ count: Int) {
274315
videos = []
275316
for i in 0...count - 1 {
@@ -425,7 +466,7 @@ extension JoinChannelVideoMain: AgoraRtcEngineDelegate {
425466
videoCanvas.uid = uid
426467
// the view to be binded
427468
videoCanvas.view = remoteVideo.videocanvas
428-
videoCanvas.renderMode = .hidden
469+
videoCanvas.renderMode = .fit
429470
agoraKit.setupRemoteVideo(videoCanvas)
430471
remoteVideo.uid = uid
431472
} else {
@@ -485,4 +526,13 @@ extension JoinChannelVideoMain: AgoraRtcEngineDelegate {
485526
func rtcEngine(_ engine: AgoraRtcEngineKit, remoteAudioStats stats: AgoraRtcRemoteAudioStats) {
486527
videos.first(where: { $0.uid == stats.uid })?.statsInfo?.updateAudioStats(stats)
487528
}
529+
530+
/// Reports the video background substitution success or failed.
531+
/// @param enabled whether background substitution is enabled.
532+
/// @param reason The reason of the background substitution callback. See [AgoraVideoBackgroundSourceStateReason](AgoraVideoBackgroundSourceStateReason).
533+
func rtcEngine(_ engine: AgoraRtcEngineKit, videoBackgroundSourceEnabled enabled: Bool, reason: AgoraVideoBackgroundSourceStateReason) {
534+
if reason != .vbsStateReasonSuccess {
535+
LogUtils.log(message: "background substitution failed to enabled for \(reason.rawValue)", level: .warning)
536+
}
537+
}
488538
}

macOS/APIExample/Localizable.strings

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,3 +156,8 @@
156156
"Sending" = "发送中";
157157
"Raw Audio Data" = "音频裸数据";
158158
"Video Source" = "视频源选择";
159+
"Sending" = "发送中";
160+
"None" = "无背景";
161+
"Colored Background" = "纯色背景";
162+
"Image Background" = "图片背景";
163+
"Camera Background Setting" = "主播背景设置";

0 commit comments

Comments
 (0)