Skip to content

Commit b422ce8

Browse files
committed
feat: support 3.3.0 for iOS
1 parent c8a08e5 commit b422ce8

7 files changed

+204
-81
lines changed

BeanCovertor.swift

+60-9
Original file line numberDiff line numberDiff line change
@@ -277,8 +277,22 @@ func mapToLiveInjectStreamConfig(_ map: Dictionary<String, Any>) -> AgoraLiveInj
277277

278278
func mapToCameraCapturerConfiguration(_ map: Dictionary<String, Any>) -> AgoraCameraCapturerConfiguration {
279279
let config = AgoraCameraCapturerConfiguration()
280-
config.preference = AgoraCameraCaptureOutputPreference(rawValue: map["preference"] as! Int)!
281-
config.cameraDirection = AgoraCameraDirection(rawValue: map["cameraDirection"] as! Int)!
280+
if let preference = map["preference"] as? Int {
281+
if let preference = AgoraCameraCaptureOutputPreference(rawValue: preference) {
282+
config.preference = preference
283+
}
284+
}
285+
if let captureWidth = map["captureWidth"] as? Int32 {
286+
config.captureWidth = captureWidth
287+
}
288+
if let captureHeight = map["captureHeight"] as? Int32 {
289+
config.captureHeight = captureHeight
290+
}
291+
if let cameraDirection = map["cameraDirection"] as? Int {
292+
if let cameraDirection = AgoraCameraDirection(rawValue: cameraDirection) {
293+
config.cameraDirection = cameraDirection
294+
}
295+
}
282296
return config
283297
}
284298

@@ -293,25 +307,62 @@ func mapToChannelMediaOptions(_ map: Dictionary<String, Any>) -> AgoraRtcChannel
293307
return options
294308
}
295309

310+
func mapToRtcEngineConfig(_ map: Dictionary<String, Any>) -> AgoraRtcEngineConfig {
311+
let config = AgoraRtcEngineConfig()
312+
config.appId = map["appId"] as? String
313+
if let areaCode = map["areaCode"] as? UInt {
314+
config.areaCode = areaCode
315+
}
316+
if let logConfig = map["logConfig"] as? Dictionary<String, Any> {
317+
config.logConfig = mapToLogConfig(logConfig)
318+
}
319+
return config
320+
}
321+
296322
func mapToEncryptionConfig(_ map: Dictionary<String, Any>) -> AgoraEncryptionConfig {
297-
let encryptionConfig = AgoraEncryptionConfig()
323+
let config = AgoraEncryptionConfig()
298324
if let encryptionMode = map["encryptionMode"] as? Int {
299325
if let encryptionMode = AgoraEncryptionMode(rawValue: encryptionMode) {
300-
encryptionConfig.encryptionMode = encryptionMode
326+
config.encryptionMode = encryptionMode
301327
}
302328
}
303329
if let encryptionKey = map["encryptionKey"] as? String {
304-
encryptionConfig.encryptionKey = encryptionKey
330+
config.encryptionKey = encryptionKey
305331
}
306-
return encryptionConfig
332+
return config
307333
}
308334

309335
func mapToClientRoleOptions(_ map: Dictionary<String, Any>) -> AgoraClientRoleOptions {
310-
let clientRoleOptions = AgoraClientRoleOptions()
336+
let options = AgoraClientRoleOptions()
311337
if let audienceLatencyLevel = map["audienceLatencyLevel"] as? Int {
312338
if let audienceLatencyLevel = AgoraAudienceLatencyLevelType(rawValue: audienceLatencyLevel) {
313-
clientRoleOptions.audienceLatencyLevel = audienceLatencyLevel
339+
options.audienceLatencyLevel = audienceLatencyLevel
314340
}
315341
}
316-
return clientRoleOptions
342+
return options
343+
}
344+
345+
func mapToLogConfig(_ map: Dictionary<String, Any>) -> AgoraLogConfig {
346+
let config = AgoraLogConfig()
347+
config.filePath = map["filePath"] as? String
348+
if let fileSize = map["fileSize"] as? Int {
349+
config.fileSize = fileSize
350+
}
351+
if let level = map["level"] as? Int {
352+
if let level = AgoraLogLevel.init(rawValue: level) {
353+
config.level = level;
354+
}
355+
}
356+
return config
357+
}
358+
359+
func mapToDataStreamConfig(_ map: Dictionary<String, Any>) -> AgoraDataStreamConfig {
360+
let config = AgoraDataStreamConfig()
361+
if let syncWithAudio = map["syncWithAudio"] as? Bool {
362+
config.syncWithAudio = syncWithAudio
363+
}
364+
if let ordered = map["ordered"] as? Bool {
365+
config.ordered = ordered
366+
}
367+
return config
317368
}

Extensions.swift

+5-2
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,9 @@ extension AgoraRtcRemoteAudioStats {
8484
"totalFrozenTime": totalFrozenTime,
8585
"frozenRate": frozenRate,
8686
"totalActiveTime": totalActiveTime,
87-
"publishDuration": publishDuration
87+
"publishDuration": publishDuration,
88+
"qoeQuality": qoeQuality,
89+
"qualityChangedReason": qualityChangedReason
8890
]
8991
}
9092
}
@@ -105,7 +107,8 @@ extension AgoraRtcLocalVideoStats {
105107
"encodedFrameCount": encodedFrameCount,
106108
"codecType": codecType.rawValue,
107109
"txPacketLossRate": txPacketLossRate,
108-
"captureFrameRate": captureFrameRate
110+
"captureFrameRate": captureFrameRate,
111+
"captureBrightnessLevel": captureBrightnessLevel.rawValue
109112
]
110113
}
111114
}

MediaObserver.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import AgoraRtcKit
1111

1212
class MediaObserver: NSObject {
1313
private var emitter: (_ data: Dictionary<String, Any?>?) -> Void
14-
private var maxMetadataSize = 0
14+
private var maxMetadataSize = 1024
1515
private var metadataList = [String]()
1616

1717
init(_ emitter: @escaping (_ data: Dictionary<String, Any?>?) -> Void) {

RtcChannel.swift

+32-34
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ protocol RtcChannelAudioInterface {
5151

5252
func muteAllRemoteAudioStreams(_ params: NSDictionary, _ callback: Callback)
5353

54+
@available(*, deprecated)
5455
func setDefaultMuteAllRemoteAudioStreams(_ params: NSDictionary, _ callback: Callback)
5556
}
5657

@@ -59,7 +60,10 @@ protocol RtcChannelVideoInterface {
5960

6061
func muteAllRemoteVideoStreams(_ params: NSDictionary, _ callback: Callback)
6162

63+
@available(*, deprecated)
6264
func setDefaultMuteAllRemoteVideoStreams(_ params: NSDictionary, _ callback: Callback)
65+
66+
func enableRemoteSuperResolution(_ params: NSDictionary, callback: Callback)
6367
}
6468

6569
protocol RtcChannelVoicePositionInterface {
@@ -103,8 +107,10 @@ protocol RtcChannelMediaMetadataInterface {
103107
}
104108

105109
protocol RtcChannelEncryptionInterface {
110+
@available(*, deprecated)
106111
func setEncryptionSecret(_ params: NSDictionary, _ callback: Callback)
107112

113+
@available(*, deprecated)
108114
func setEncryptionMode(_ params: NSDictionary, _ callback: Callback)
109115

110116
func enableEncryption(_ params: NSDictionary, _ callback: Callback)
@@ -163,11 +169,7 @@ class RtcChannelManager: NSObject, RtcChannelInterface {
163169
}
164170

165171
@objc func destroy(_ params: NSDictionary, _ callback: Callback) {
166-
var code: Int32? = -Int32(AgoraErrorCode.notInitialized.rawValue)
167-
if let it = self[params["channelId"] as! String] {
168-
code = rtcChannelMap.removeValue(forKey: it.getId()!)?.destroy()
169-
}
170-
callback.code(code)
172+
callback.code(rtcChannelMap.removeValue(forKey:params["channelId"] as! String)?.destroy())
171173
}
172174

173175
@objc func setClientRole(_ params: NSDictionary, _ callback: Callback) {
@@ -284,28 +286,29 @@ class RtcChannelManager: NSObject, RtcChannelInterface {
284286
}
285287

286288
@objc func registerMediaMetadataObserver(_ params: NSDictionary, _ callback: Callback) {
287-
var code = -AgoraErrorCode.notInitialized.rawValue
288-
if let it = self[params["channelId"] as! String] {
289-
let mediaObserver = MediaObserver { [weak self] in
290-
self?.emitter(RtcEngineEvents.MetadataReceived, $0)
289+
let channelId = params["channelId"] as! String
290+
let mediaObserver = MediaObserver { [weak self] in
291+
if var data = $0 {
292+
data["channelId"] = channelId;
293+
self?.emitter(RtcEngineEvents.MetadataReceived, data)
291294
}
292-
if it.setMediaMetadataDelegate(mediaObserver, with: .video) {
293-
mediaObserverMap[it.getId()!] = mediaObserver
294-
code = AgoraErrorCode.noError.rawValue
295+
}
296+
callback.resolve(self[channelId]) {
297+
if $0.setMediaMetadataDelegate(mediaObserver, with: .video) {
298+
mediaObserverMap[channelId] = mediaObserver
295299
}
300+
return nil
296301
}
297-
callback.code(Int32(code))
298302
}
299303

300304
@objc func unregisterMediaMetadataObserver(_ params: NSDictionary, _ callback: Callback) {
301-
var code = -AgoraErrorCode.notInitialized.rawValue
302-
if let it = self[params["channelId"] as! String] {
303-
if it.setMediaMetadataDelegate(nil, with: .video) {
304-
mediaObserverMap.removeValue(forKey: it.getId()!)
305-
code = AgoraErrorCode.noError.rawValue
305+
let channelId = params["channelId"] as! String
306+
callback.resolve(self[channelId]) {
307+
if $0.setMediaMetadataDelegate(nil, with: .video) {
308+
mediaObserverMap.removeValue(forKey: channelId)
306309
}
310+
return nil
307311
}
308-
callback.code(Int32(code))
309312
}
310313

311314
@objc func setMaxMetadataSize(_ params: NSDictionary, _ callback: Callback) {
@@ -351,25 +354,20 @@ class RtcChannelManager: NSObject, RtcChannelInterface {
351354
}
352355

353356
@objc func createDataStream(_ params: NSDictionary, _ callback: Callback) {
354-
var code: Int32 = -Int32(AgoraErrorCode.notInitialized.rawValue)
357+
let channel = self[params["channelId"] as! String]
355358
var streamId = 0
356-
if let it = self[params["channelId"] as! String] {
357-
code = it.createDataStream(&streamId, reliable: params["reliable"] as! Bool, ordered: params["ordered"] as! Bool)
358-
}
359-
callback.code(code) { ignore in
360-
streamId
359+
if let config = params["config"] as? Dictionary<String, Any> {
360+
callback.code(channel?.createDataStream(&streamId, config: mapToDataStreamConfig(config))) { _ in streamId }
361+
return
361362
}
363+
callback.code(channel?.createDataStream(&streamId, reliable: params["reliable"] as! Bool, ordered: params["ordered"] as! Bool)) { _ in streamId }
362364
}
363365

364366
@objc func sendStreamMessage(_ params: NSDictionary, _ callback: Callback) {
365-
var code: Int32 = -Int32(AgoraErrorCode.notInitialized.rawValue)
366-
if let it = self[params["channelId"] as! String] {
367-
if let data = (params["message"] as! String).data(using: .utf8) {
368-
code = it.sendStreamMessage(params["streamId"] as! Int, data: data)
369-
} else {
370-
code = -Int32(AgoraErrorCode.invalidArgument.rawValue)
371-
}
372-
}
373-
callback.code(code)
367+
callback.code(self[params["channelId"] as! String]?.sendStreamMessage(params["streamId"] as! Int, data: (params["message"] as! String).data(using: .utf8)!))
368+
}
369+
370+
@objc func enableRemoteSuperResolution(_ params: NSDictionary, callback: Callback) {
371+
callback.code(self[params["channelId"] as! String]?.enableRemoteSuperResolution(params["uid"] as! UInt, enabled: params["enable"] as! Bool))
374372
}
375373
}

RtcChannelEvent.swift

+6
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ class RtcChannelEvents {
4545
static let AudioSubscribeStateChanged = "AudioSubscribeStateChanged"
4646
static let VideoSubscribeStateChanged = "VideoSubscribeStateChanged"
4747
static let RtmpStreamingEvent = "RtmpStreamingEvent"
48+
static let UserSuperResolutionEnabled = "UserSuperResolutionEnabled"
4849

4950
static func toMap() -> Dictionary<String, String> {
5051
return [
@@ -83,6 +84,7 @@ class RtcChannelEvents {
8384
"AudioSubscribeStateChanged": AudioSubscribeStateChanged,
8485
"VideoSubscribeStateChanged": VideoSubscribeStateChanged,
8586
"RtmpStreamingEvent": RtmpStreamingEvent,
87+
"UserSuperResolutionEnabled": UserSuperResolutionEnabled
8688
]
8789
}
8890
}
@@ -240,4 +242,8 @@ extension RtcChannelEventHandler: AgoraRtcChannelDelegate {
240242
func rtcChannel(_ rtcChannel: AgoraRtcChannel, rtmpStreamingEventWithUrl url: String, eventCode: AgoraRtmpStreamingEvent) {
241243
callback(RtcChannelEvents.RtmpStreamingEvent, rtcChannel, url, eventCode.rawValue)
242244
}
245+
246+
func rtcChannel(_ rtcChannel: AgoraRtcChannel, superResolutionEnabledOfUid uid: UInt, enabled: Bool, reason: AgoraSuperResolutionStateReason) {
247+
callback(RtcChannelEvents.UserSuperResolutionEnabled, rtcChannel, uid, enabled, reason.rawValue)
248+
}
243249
}

0 commit comments

Comments
 (0)