diff --git a/BeanCovertor.swift b/BeanCovertor.swift index bbb869ac7..c9690eac7 100644 --- a/BeanCovertor.swift +++ b/BeanCovertor.swift @@ -277,8 +277,22 @@ func mapToLiveInjectStreamConfig(_ map: Dictionary) -> AgoraLiveInj func mapToCameraCapturerConfiguration(_ map: Dictionary) -> AgoraCameraCapturerConfiguration { let config = AgoraCameraCapturerConfiguration() - config.preference = AgoraCameraCaptureOutputPreference(rawValue: map["preference"] as! Int)! - config.cameraDirection = AgoraCameraDirection(rawValue: map["cameraDirection"] as! Int)! + if let preference = map["preference"] as? Int { + if let preference = AgoraCameraCaptureOutputPreference(rawValue: preference) { + config.preference = preference + } + } + if let captureWidth = map["captureWidth"] as? Int32 { + config.captureWidth = captureWidth + } + if let captureHeight = map["captureHeight"] as? Int32 { + config.captureHeight = captureHeight + } + if let cameraDirection = map["cameraDirection"] as? Int { + if let cameraDirection = AgoraCameraDirection(rawValue: cameraDirection) { + config.cameraDirection = cameraDirection + } + } return config } @@ -293,25 +307,62 @@ func mapToChannelMediaOptions(_ map: Dictionary) -> AgoraRtcChannel return options } +func mapToRtcEngineConfig(_ map: Dictionary) -> AgoraRtcEngineConfig { + let config = AgoraRtcEngineConfig() + config.appId = map["appId"] as? String + if let areaCode = map["areaCode"] as? UInt { + config.areaCode = areaCode + } + if let logConfig = map["logConfig"] as? Dictionary { + config.logConfig = mapToLogConfig(logConfig) + } + return config +} + func mapToEncryptionConfig(_ map: Dictionary) -> AgoraEncryptionConfig { - let encryptionConfig = AgoraEncryptionConfig() + let config = AgoraEncryptionConfig() if let encryptionMode = map["encryptionMode"] as? Int { if let encryptionMode = AgoraEncryptionMode(rawValue: encryptionMode) { - encryptionConfig.encryptionMode = encryptionMode + config.encryptionMode = encryptionMode } } if let encryptionKey = map["encryptionKey"] as? String { - encryptionConfig.encryptionKey = encryptionKey + config.encryptionKey = encryptionKey } - return encryptionConfig + return config } func mapToClientRoleOptions(_ map: Dictionary) -> AgoraClientRoleOptions { - let clientRoleOptions = AgoraClientRoleOptions() + let options = AgoraClientRoleOptions() if let audienceLatencyLevel = map["audienceLatencyLevel"] as? Int { if let audienceLatencyLevel = AgoraAudienceLatencyLevelType(rawValue: audienceLatencyLevel) { - clientRoleOptions.audienceLatencyLevel = audienceLatencyLevel + options.audienceLatencyLevel = audienceLatencyLevel } } - return clientRoleOptions + return options +} + +func mapToLogConfig(_ map: Dictionary) -> AgoraLogConfig { + let config = AgoraLogConfig() + config.filePath = map["filePath"] as? String + if let fileSize = map["fileSize"] as? Int { + config.fileSize = fileSize + } + if let level = map["level"] as? Int { + if let level = AgoraLogLevel.init(rawValue: level) { + config.level = level; + } + } + return config +} + +func mapToDataStreamConfig(_ map: Dictionary) -> AgoraDataStreamConfig { + let config = AgoraDataStreamConfig() + if let syncWithAudio = map["syncWithAudio"] as? Bool { + config.syncWithAudio = syncWithAudio + } + if let ordered = map["ordered"] as? Bool { + config.ordered = ordered + } + return config } diff --git a/Extensions.swift b/Extensions.swift index 6f69f1596..8c66a06c5 100644 --- a/Extensions.swift +++ b/Extensions.swift @@ -84,7 +84,9 @@ extension AgoraRtcRemoteAudioStats { "totalFrozenTime": totalFrozenTime, "frozenRate": frozenRate, "totalActiveTime": totalActiveTime, - "publishDuration": publishDuration + "publishDuration": publishDuration, + "qoeQuality": qoeQuality, + "qualityChangedReason": qualityChangedReason ] } } @@ -105,7 +107,8 @@ extension AgoraRtcLocalVideoStats { "encodedFrameCount": encodedFrameCount, "codecType": codecType.rawValue, "txPacketLossRate": txPacketLossRate, - "captureFrameRate": captureFrameRate + "captureFrameRate": captureFrameRate, + "captureBrightnessLevel": captureBrightnessLevel.rawValue ] } } diff --git a/MediaObserver.swift b/MediaObserver.swift index 0e853048f..d11a45705 100644 --- a/MediaObserver.swift +++ b/MediaObserver.swift @@ -11,7 +11,7 @@ import AgoraRtcKit class MediaObserver: NSObject { private var emitter: (_ data: Dictionary?) -> Void - private var maxMetadataSize = 0 + private var maxMetadataSize = 1024 private var metadataList = [String]() init(_ emitter: @escaping (_ data: Dictionary?) -> Void) { diff --git a/RtcChannel.swift b/RtcChannel.swift index 08944703c..c2d5abf6c 100644 --- a/RtcChannel.swift +++ b/RtcChannel.swift @@ -51,6 +51,7 @@ protocol RtcChannelAudioInterface { func muteAllRemoteAudioStreams(_ params: NSDictionary, _ callback: Callback) + @available(*, deprecated) func setDefaultMuteAllRemoteAudioStreams(_ params: NSDictionary, _ callback: Callback) } @@ -59,7 +60,10 @@ protocol RtcChannelVideoInterface { func muteAllRemoteVideoStreams(_ params: NSDictionary, _ callback: Callback) + @available(*, deprecated) func setDefaultMuteAllRemoteVideoStreams(_ params: NSDictionary, _ callback: Callback) + + func enableRemoteSuperResolution(_ params: NSDictionary, callback: Callback) } protocol RtcChannelVoicePositionInterface { @@ -103,8 +107,10 @@ protocol RtcChannelMediaMetadataInterface { } protocol RtcChannelEncryptionInterface { + @available(*, deprecated) func setEncryptionSecret(_ params: NSDictionary, _ callback: Callback) + @available(*, deprecated) func setEncryptionMode(_ params: NSDictionary, _ callback: Callback) func enableEncryption(_ params: NSDictionary, _ callback: Callback) @@ -163,11 +169,7 @@ class RtcChannelManager: NSObject, RtcChannelInterface { } @objc func destroy(_ params: NSDictionary, _ callback: Callback) { - var code: Int32? = -Int32(AgoraErrorCode.notInitialized.rawValue) - if let it = self[params["channelId"] as! String] { - code = rtcChannelMap.removeValue(forKey: it.getId()!)?.destroy() - } - callback.code(code) + callback.code(rtcChannelMap.removeValue(forKey:params["channelId"] as! String)?.destroy()) } @objc func setClientRole(_ params: NSDictionary, _ callback: Callback) { @@ -284,28 +286,29 @@ class RtcChannelManager: NSObject, RtcChannelInterface { } @objc func registerMediaMetadataObserver(_ params: NSDictionary, _ callback: Callback) { - var code = -AgoraErrorCode.notInitialized.rawValue - if let it = self[params["channelId"] as! String] { - let mediaObserver = MediaObserver { [weak self] in - self?.emitter(RtcEngineEvents.MetadataReceived, $0) + let channelId = params["channelId"] as! String + let mediaObserver = MediaObserver { [weak self] in + if var data = $0 { + data["channelId"] = channelId; + self?.emitter(RtcEngineEvents.MetadataReceived, data) } - if it.setMediaMetadataDelegate(mediaObserver, with: .video) { - mediaObserverMap[it.getId()!] = mediaObserver - code = AgoraErrorCode.noError.rawValue + } + callback.resolve(self[channelId]) { + if $0.setMediaMetadataDelegate(mediaObserver, with: .video) { + mediaObserverMap[channelId] = mediaObserver } + return nil } - callback.code(Int32(code)) } @objc func unregisterMediaMetadataObserver(_ params: NSDictionary, _ callback: Callback) { - var code = -AgoraErrorCode.notInitialized.rawValue - if let it = self[params["channelId"] as! String] { - if it.setMediaMetadataDelegate(nil, with: .video) { - mediaObserverMap.removeValue(forKey: it.getId()!) - code = AgoraErrorCode.noError.rawValue + let channelId = params["channelId"] as! String + callback.resolve(self[channelId]) { + if $0.setMediaMetadataDelegate(nil, with: .video) { + mediaObserverMap.removeValue(forKey: channelId) } + return nil } - callback.code(Int32(code)) } @objc func setMaxMetadataSize(_ params: NSDictionary, _ callback: Callback) { @@ -351,25 +354,20 @@ class RtcChannelManager: NSObject, RtcChannelInterface { } @objc func createDataStream(_ params: NSDictionary, _ callback: Callback) { - var code: Int32 = -Int32(AgoraErrorCode.notInitialized.rawValue) + let channel = self[params["channelId"] as! String] var streamId = 0 - if let it = self[params["channelId"] as! String] { - code = it.createDataStream(&streamId, reliable: params["reliable"] as! Bool, ordered: params["ordered"] as! Bool) - } - callback.code(code) { ignore in - streamId + if let config = params["config"] as? Dictionary { + callback.code(channel?.createDataStream(&streamId, config: mapToDataStreamConfig(config))) { _ in streamId } + return } + callback.code(channel?.createDataStream(&streamId, reliable: params["reliable"] as! Bool, ordered: params["ordered"] as! Bool)) { _ in streamId } } @objc func sendStreamMessage(_ params: NSDictionary, _ callback: Callback) { - var code: Int32 = -Int32(AgoraErrorCode.notInitialized.rawValue) - if let it = self[params["channelId"] as! String] { - if let data = (params["message"] as! String).data(using: .utf8) { - code = it.sendStreamMessage(params["streamId"] as! Int, data: data) - } else { - code = -Int32(AgoraErrorCode.invalidArgument.rawValue) - } - } - callback.code(code) + callback.code(self[params["channelId"] as! String]?.sendStreamMessage(params["streamId"] as! Int, data: (params["message"] as! String).data(using: .utf8)!)) + } + + @objc func enableRemoteSuperResolution(_ params: NSDictionary, callback: Callback) { + callback.code(self[params["channelId"] as! String]?.enableRemoteSuperResolution(params["uid"] as! UInt, enabled: params["enable"] as! Bool)) } } diff --git a/RtcChannelEvent.swift b/RtcChannelEvent.swift index 47144ae9a..a7d01d930 100644 --- a/RtcChannelEvent.swift +++ b/RtcChannelEvent.swift @@ -45,6 +45,7 @@ class RtcChannelEvents { static let AudioSubscribeStateChanged = "AudioSubscribeStateChanged" static let VideoSubscribeStateChanged = "VideoSubscribeStateChanged" static let RtmpStreamingEvent = "RtmpStreamingEvent" + static let UserSuperResolutionEnabled = "UserSuperResolutionEnabled" static func toMap() -> Dictionary { return [ @@ -83,6 +84,7 @@ class RtcChannelEvents { "AudioSubscribeStateChanged": AudioSubscribeStateChanged, "VideoSubscribeStateChanged": VideoSubscribeStateChanged, "RtmpStreamingEvent": RtmpStreamingEvent, + "UserSuperResolutionEnabled": UserSuperResolutionEnabled ] } } @@ -240,4 +242,8 @@ extension RtcChannelEventHandler: AgoraRtcChannelDelegate { func rtcChannel(_ rtcChannel: AgoraRtcChannel, rtmpStreamingEventWithUrl url: String, eventCode: AgoraRtmpStreamingEvent) { callback(RtcChannelEvents.RtmpStreamingEvent, rtcChannel, url, eventCode.rawValue) } + + func rtcChannel(_ rtcChannel: AgoraRtcChannel, superResolutionEnabledOfUid uid: UInt, enabled: Bool, reason: AgoraSuperResolutionStateReason) { + callback(RtcChannelEvents.UserSuperResolutionEnabled, rtcChannel, uid, enabled, reason.rawValue) + } } diff --git a/RtcEngine.swift b/RtcEngine.swift index c3921c735..f840ac41a 100644 --- a/RtcEngine.swift +++ b/RtcEngine.swift @@ -60,15 +60,28 @@ protocol RtcEngineInterface: func complain(_ params: NSDictionary, _ callback: Callback) + @available(*, deprecated) func setLogFile(_ params: NSDictionary, _ callback: Callback) + @available(*, deprecated) func setLogFilter(_ params: NSDictionary, _ callback: Callback) + @available(*, deprecated) func setLogFileSize(_ params: NSDictionary, _ callback: Callback) func setParameters(_ params: NSDictionary, _ callback: Callback) + + func getSdkVersion(callback: Callback) + + func getErrorDescription(_ params: NSDictionary, callback: Callback) func getNativeHandle(_ callback: Callback) + + func enableDeepLearningDenoise(_ params: NSDictionary, callback: Callback) + + func setCloudProxy(_ params: NSDictionary, callback: Callback) + + func uploadLogFile(callback: Callback) } protocol RtcEngineUserInfoInterface { @@ -102,6 +115,7 @@ protocol RtcEngineAudioInterface { func muteAllRemoteAudioStreams(_ params: NSDictionary, _ callback: Callback) + @available(*, deprecated) func setDefaultMuteAllRemoteAudioStreams(_ params: NSDictionary, _ callback: Callback) func enableAudioVolumeIndication(_ params: NSDictionary, _ callback: Callback) @@ -126,9 +140,12 @@ protocol RtcEngineVideoInterface { func muteAllRemoteVideoStreams(_ params: NSDictionary, _ callback: Callback) + @available(*, deprecated) func setDefaultMuteAllRemoteVideoStreams(_ params: NSDictionary, _ callback: Callback) func setBeautyEffectOptions(_ params: NSDictionary, _ callback: Callback) + + func enableRemoteSuperResolution(_ params: NSDictionary, callback: Callback) } protocol RtcEngineAudioMixingInterface { @@ -205,6 +222,8 @@ protocol RtcEngineVoiceChangerInterface { func setVoiceBeautifierPreset(_ params: NSDictionary, _ callback: Callback) func setAudioEffectParameters(_ params: NSDictionary, _ callback: Callback) + + func setVoiceBeautifierParameters(_ params: NSDictionary, callback: Callback) } protocol RtcEngineVoicePositionInterface { @@ -369,15 +388,12 @@ class RtcEngineManager: NSObject, RtcEngineInterface { delegate = RtcEngineEventHandler() { [weak self] in self?.emitter($0, $1) } - let config = AgoraRtcEngineConfig() - config.appId = params["appId"] as? String - config.areaCode = (params["areaCode"] as! NSNumber).uintValue - engine = AgoraRtcEngineKit.sharedEngine(with: config, delegate: delegate) + engine = AgoraRtcEngineKit.sharedEngine(with: mapToRtcEngineConfig(params["config"] as! Dictionary), delegate: delegate) callback.code(engine?.setAppType(AgoraRtcAppType(rawValue: params["appType"] as! UInt)!)) } @objc func destroy(_ callback: Callback) { - callback.resolve(engine) { [weak self] ignore in + callback.resolve(engine) { [weak self] _ in self?.Release() } } @@ -396,11 +412,25 @@ class RtcEngineManager: NSObject, RtcEngineInterface { } @objc func joinChannel(_ params: NSDictionary, _ callback: Callback) { - callback.code(engine?.joinChannel(byToken: params["token"] as? String, channelId: params["channelName"] as! String, info: params["optionalInfo"] as? String, uid: params["optionalUid"] as! UInt)) + let token = params["token"] as? String + let channelName = params["channelName"] as! String + let optionalInfo = params["optionalInfo"] as? String + let optionalUid = params["optionalUid"] as! UInt + if let options = params["options"] as? Dictionary { + callback.code(engine?.joinChannel(byToken: token, channelId: channelName, info: optionalInfo, uid: optionalUid, options: mapToChannelMediaOptions(options))) + return + } + callback.code(engine?.joinChannel(byToken: token, channelId: channelName, info: optionalInfo, uid: optionalUid)) } @objc func switchChannel(_ params: NSDictionary, _ callback: Callback) { - callback.code(engine?.switchChannel(byToken: params["token"] as? String, channelId: params["channelName"] as! String)) + let token = params["token"] as? String + let channelName = params["channelName"] as! String + if let options = params["options"] as? Dictionary { + callback.code(engine?.switchChannel(byToken: token, channelId: channelName, options: mapToChannelMediaOptions(options))) + return + } + callback.code(engine?.switchChannel(byToken: token, channelId: channelName)) } @objc func leaveChannel(_ callback: Callback) { @@ -466,7 +496,14 @@ class RtcEngineManager: NSObject, RtcEngineInterface { } @objc func joinChannelWithUserAccount(_ params: NSDictionary, _ callback: Callback) { - callback.code(engine?.joinChannel(byUserAccount: params["userAccount"] as! String, token: params["token"] as? String, channelId: params["channelName"] as! String)) + let userAccount = params["userAccount"] as! String + let token = params["token"] as? String + let channelName = params["channelName"] as! String + if let options = params["options"] as? Dictionary { + callback.code(engine?.joinChannel(byUserAccount: userAccount, token: token, channelId: channelName, options: mapToChannelMediaOptions(options))) + return + } + callback.code(engine?.joinChannel(byUserAccount: userAccount, token: token, channelId: channelName)) } @objc func getUserInfoByUserAccount(_ params: NSDictionary, _ callback: Callback) { @@ -824,28 +861,24 @@ class RtcEngineManager: NSObject, RtcEngineInterface { } @objc func registerMediaMetadataObserver(_ callback: Callback) { - var code = -AgoraErrorCode.notInitialized.rawValue - if let `engine` = engine { - let mediaObserver = MediaObserver { [weak self] in - self?.emitter(RtcEngineEvents.MetadataReceived, $0) - } - if engine.setMediaMetadataDelegate(mediaObserver, with: .video) { + let mediaObserver = MediaObserver { [weak self] in + self?.emitter(RtcEngineEvents.MetadataReceived, $0) + } + callback.resolve(engine) { + if $0.setMediaMetadataDelegate(mediaObserver, with: .video) { self.mediaObserver = mediaObserver - code = AgoraErrorCode.noError.rawValue } + return nil } - callback.code(Int32(code)) } @objc func unregisterMediaMetadataObserver(_ callback: Callback) { - var code = -AgoraErrorCode.notInitialized.rawValue - if let it = engine { - if it.setMediaMetadataDelegate(nil, with: .video) { + callback.resolve(engine) { + if $0.setMediaMetadataDelegate(nil, with: .video) { self.mediaObserver = nil - code = AgoraErrorCode.noError.rawValue } + return nil } - callback.code(Int32(code)) } @objc func setMaxMetadataSize(_ params: NSDictionary, _ callback: Callback) { @@ -985,25 +1018,45 @@ class RtcEngineManager: NSObject, RtcEngineInterface { } @objc func createDataStream(_ params: NSDictionary, _ callback: Callback) { - var code: Int32 = -Int32(AgoraErrorCode.notInitialized.rawValue) var streamId = 0 - if let it = engine { - code = it.createDataStream(&streamId, reliable: params["reliable"] as! Bool, ordered: params["ordered"] as! Bool) - } - callback.code(code) { ignore in - streamId + if let config = params["config"] as? Dictionary { + callback.code(engine?.createDataStream(&streamId, config: mapToDataStreamConfig(config))) { _ in streamId } + return } + callback.code(engine?.createDataStream(&streamId, reliable: params["reliable"] as! Bool, ordered: params["ordered"] as! Bool)) { _ in streamId } } @objc func sendStreamMessage(_ params: NSDictionary, _ callback: Callback) { - var code: Int32 = -Int32(AgoraErrorCode.notInitialized.rawValue) - if let it = engine { - if let data = (params["message"] as! String).data(using: .utf8) { - code = it.sendStreamMessage(params["streamId"] as! Int, data: data) - } else { - code = -Int32(AgoraErrorCode.invalidArgument.rawValue) - } + callback.code(engine?.sendStreamMessage(params["streamId"] as! Int, data: (params["message"] as! String).data(using: .utf8)!)) + } + + @objc func setVoiceBeautifierParameters(_ params: NSDictionary, callback: Callback) { + callback.code(engine?.setVoiceBeautifierParameters(AgoraVoiceBeautifierPreset.init(rawValue: params["preset"] as! Int)!, param1: params["param1"] as! Int32, param2: params["param2"] as! Int32)) + } + + @objc func getSdkVersion(callback: Callback) { + callback.success(AgoraRtcEngineKit.getSdkVersion()) + } + + @objc func getErrorDescription(_ params: NSDictionary, callback: Callback) { + callback.success(AgoraRtcEngineKit.getErrorDescription(params["code"] as! Int)) + } + + @objc func enableDeepLearningDenoise(_ params: NSDictionary, callback: Callback) { + callback.code(engine?.enableDeepLearningDenoise(params["enabled"] as! Bool)) + } + + @objc func setCloudProxy(_ params: NSDictionary, callback: Callback) { + callback.code(engine?.setCloudProxy(AgoraCloudProxyType.init(rawValue: params["proxyType"] as! UInt)!)) + } + + @objc func uploadLogFile(callback: Callback) { + callback.resolve(engine) { + return $0.uploadLogFile() } - callback.code(code) + } + + @objc func enableRemoteSuperResolution(_ params: NSDictionary, callback: Callback) { + callback.code(engine?.enableRemoteSuperResolution(params["uid"] as! UInt, enabled: params["enabled"] as! Bool)) } } diff --git a/RtcEngineEvent.swift b/RtcEngineEvent.swift index ed926d7d0..241c1685d 100644 --- a/RtcEngineEvent.swift +++ b/RtcEngineEvent.swift @@ -87,6 +87,8 @@ class RtcEngineEvents { static let AudioSubscribeStateChanged = "AudioSubscribeStateChanged" static let VideoSubscribeStateChanged = "VideoSubscribeStateChanged" static let RtmpStreamingEvent = "RtmpStreamingEvent" + static let UserSuperResolutionEnabled = "UserSuperResolutionEnabled" + static let UploadLogResult = "UploadLogResult" static func toMap() -> Dictionary { return [ @@ -167,6 +169,8 @@ class RtcEngineEvents { "AudioSubscribeStateChanged": AudioSubscribeStateChanged, "VideoSubscribeStateChanged": VideoSubscribeStateChanged, "RtmpStreamingEvent": RtmpStreamingEvent, + "UserSuperResolutionEnabled": UserSuperResolutionEnabled, + "UploadLogResult": UploadLogResult ] } } @@ -497,4 +501,12 @@ extension RtcEngineEventHandler: AgoraRtcEngineDelegate { func rtcEngine(_ engine: AgoraRtcEngineKit, rtmpStreamingEventWithUrl url: String, eventCode: AgoraRtmpStreamingEvent) { callback(RtcEngineEvents.RtmpStreamingEvent, url, eventCode.rawValue) } + + func rtcEngine(_ engine: AgoraRtcEngineKit, superResolutionEnabledOfUid uid: UInt, enabled: Bool, reason: AgoraSuperResolutionStateReason) { + callback(RtcEngineEvents.UserSuperResolutionEnabled, uid, enabled, reason.rawValue) + } + + func rtcEngine(_ engine: AgoraRtcEngineKit, uploadLogResultRequestId requestId: String, success: Bool, reason: AgoraUploadErrorReason) { + callback(RtcEngineEvents.UploadLogResult, requestId, success, reason.rawValue) + } }