diff --git a/BeanCovertor.swift b/BeanCovertor.swift index 6ffef37e5..0973defe2 100644 --- a/BeanCovertor.swift +++ b/BeanCovertor.swift @@ -11,22 +11,22 @@ import AgoraRtcKit func mapToPoint(_ map: Dictionary) -> CGPoint { var point = CGPoint() - if let x = map["x"] as? Int { - point.x = CGFloat(x) + if let x = map["x"] as? NSNumber { + point.x = CGFloat(truncating: x) } - if let y = map["y"] as? Int { - point.y = CGFloat(y) + if let y = map["y"] as? NSNumber { + point.y = CGFloat(truncating: y) } return point } func mapToSize(_ map: Dictionary) -> CGSize { var size = CGSize() - if let width = map["width"] as? Int { - size.width = CGFloat(width) + if let width = map["width"] as? NSNumber { + size.width = CGFloat(truncating: width) } - if let height = map["height"] as? Int { - size.height = CGFloat(height) + if let height = map["height"] as? NSNumber { + size.height = CGFloat(truncating: height) } return size } @@ -43,30 +43,30 @@ func mapToVideoEncoderConfiguration(_ map: Dictionary) -> AgoraVide if let dimensions = map["dimensions"] as? Dictionary { config.dimensions = mapToSize(dimensions) } - if let frameRate = map["frameRate"] as? Int { - config.frameRate = frameRate + if let frameRate = map["frameRate"] as? NSNumber { + config.frameRate = frameRate.intValue } - if let minFrameRate = map["minFrameRate"] as? Int { - config.minFrameRate = minFrameRate + if let minFrameRate = map["minFrameRate"] as? NSNumber { + config.minFrameRate = minFrameRate.intValue } - if let bitrate = map["bitrate"] as? Int { - config.bitrate = bitrate + if let bitrate = map["bitrate"] as? NSNumber { + config.bitrate = bitrate.intValue } - if let minBitrate = map["minBitrate"] as? Int { - config.minBitrate = minBitrate + if let minBitrate = map["minBitrate"] as? NSNumber { + config.minBitrate = minBitrate.intValue } - if let orientationMode = map["orientationMode"] as? Int { - if let orientationMode = AgoraVideoOutputOrientationMode(rawValue: orientationMode) { + if let orientationMode = map["orientationMode"] as? NSNumber { + if let orientationMode = AgoraVideoOutputOrientationMode(rawValue: orientationMode.intValue) { config.orientationMode = orientationMode } } - if let degradationPreference = map["degradationPrefer"] as? Int { - if let degradationPreference = AgoraDegradationPreference(rawValue: degradationPreference) { + if let degradationPreference = map["degradationPrefer"] as? NSNumber { + if let degradationPreference = AgoraDegradationPreference(rawValue: degradationPreference.intValue) { config.degradationPreference = degradationPreference } } - if let mirrorMode = map["mirrorMode"] as? Int { - if let mirrorMode = AgoraVideoMirrorMode(rawValue: UInt(mirrorMode)) { + if let mirrorMode = map["mirrorMode"] as? NSNumber { + if let mirrorMode = AgoraVideoMirrorMode(rawValue: mirrorMode.uintValue) { config.mirrorMode = mirrorMode } } @@ -75,19 +75,19 @@ func mapToVideoEncoderConfiguration(_ map: Dictionary) -> AgoraVide func mapToBeautyOptions(_ map: Dictionary) -> AgoraBeautyOptions { let options = AgoraBeautyOptions() - if let lighteningContrastLevel = map["lighteningContrastLevel"] as? Int { - if let lighteningContrastLevel = AgoraLighteningContrastLevel(rawValue: UInt(lighteningContrastLevel)) { + if let lighteningContrastLevel = map["lighteningContrastLevel"] as? NSNumber { + if let lighteningContrastLevel = AgoraLighteningContrastLevel(rawValue: lighteningContrastLevel.uintValue) { options.lighteningContrastLevel = lighteningContrastLevel } } - if let lighteningLevel = map["lighteningLevel"] as? Float { - options.lighteningLevel = lighteningLevel + if let lighteningLevel = map["lighteningLevel"] as? NSNumber { + options.lighteningLevel = lighteningLevel.floatValue } - if let smoothnessLevel = map["smoothnessLevel"] as? Float { - options.smoothnessLevel = smoothnessLevel + if let smoothnessLevel = map["smoothnessLevel"] as? NSNumber { + options.smoothnessLevel = smoothnessLevel.floatValue } - if let rednessLevel = map["rednessLevel"] as? Float { - options.rednessLevel = rednessLevel + if let rednessLevel = map["rednessLevel"] as? NSNumber { + options.rednessLevel = rednessLevel.floatValue } return options } @@ -105,45 +105,45 @@ func mapToAgoraImage(_ map: Dictionary) -> AgoraImage { func mapToTranscodingUser(_ map: Dictionary) -> AgoraLiveTranscodingUser { let user = AgoraLiveTranscodingUser() - if let uid = map["uid"] as? Int { - user.uid = UInt(uid) + if let uid = map["uid"] as? NSNumber { + user.uid = uid.uintValue } user.rect = mapToRect(map) - if let zOrder = map["zOrder"] as? Int { - user.zOrder = zOrder + if let zOrder = map["zOrder"] as? NSNumber { + user.zOrder = zOrder.intValue } - if let alpha = map["alpha"] as? Double { - user.alpha = alpha + if let alpha = map["alpha"] as? NSNumber { + user.alpha = alpha.doubleValue } - if let audioChannel = map["audioChannel"] as? Int { - user.audioChannel = audioChannel + if let audioChannel = map["audioChannel"] as? NSNumber { + user.audioChannel = audioChannel.intValue } return user } func mapToColor(_ map: Dictionary) -> UIColor { return UIColor( - red: CGFloat(map["red"] as! Int), - green: CGFloat(map["green"] as! Int), - blue: CGFloat(map["blue"] as! Int), - alpha: 1.0 + red: CGFloat((map["red"] as! NSNumber).intValue), + green: CGFloat((map["green"] as! NSNumber).intValue), + blue: CGFloat((map["blue"] as! NSNumber).intValue), + alpha: 1.0 ) } func mapToLiveTranscoding(_ map: Dictionary) -> AgoraLiveTranscoding { let transcoding = AgoraLiveTranscoding.default() transcoding.size = mapToSize(map) - if let videoBitrate = map["videoBitrate"] as? Int { - transcoding.videoBitrate = videoBitrate + if let videoBitrate = map["videoBitrate"] as? NSNumber { + transcoding.videoBitrate = videoBitrate.intValue } - if let videoFramerate = map["videoFramerate"] as? Int { - transcoding.videoFramerate = videoFramerate + if let videoFramerate = map["videoFramerate"] as? NSNumber { + transcoding.videoFramerate = videoFramerate.intValue } if let lowLatency = map["lowLatency"] as? Bool { transcoding.lowLatency = lowLatency } - if let videoGop = map["videoGop"] as? Int { - transcoding.videoGop = videoGop + if let videoGop = map["videoGop"] as? NSNumber { + transcoding.videoGop = videoGop.intValue } if let watermark = map["watermark"] as? Dictionary { transcoding.watermark = mapToAgoraImage(watermark) @@ -151,24 +151,24 @@ func mapToLiveTranscoding(_ map: Dictionary) -> AgoraLiveTranscodin if let backgroundImage = map["backgroundImage"] as? Dictionary { transcoding.backgroundImage = mapToAgoraImage(backgroundImage) } - if let audioSampleRate = map["audioSampleRate"] as? Int { - if let audioSampleRate = AgoraAudioSampleRateType(rawValue: audioSampleRate) { + if let audioSampleRate = map["audioSampleRate"] as? NSNumber { + if let audioSampleRate = AgoraAudioSampleRateType(rawValue: audioSampleRate.intValue) { transcoding.audioSampleRate = audioSampleRate } } - if let audioBitrate = map["audioBitrate"] as? Int { - transcoding.audioBitrate = audioBitrate + if let audioBitrate = map["audioBitrate"] as? NSNumber { + transcoding.audioBitrate = audioBitrate.intValue } - if let audioChannels = map["audioChannels"] as? Int { - transcoding.audioChannels = audioChannels + if let audioChannels = map["audioChannels"] as? NSNumber { + transcoding.audioChannels = audioChannels.intValue } - if let audioCodecProfile = map["audioCodecProfile"] as? Int { - if let audioCodecProfile = AgoraAudioCodecProfileType(rawValue: audioCodecProfile) { + if let audioCodecProfile = map["audioCodecProfile"] as? NSNumber { + if let audioCodecProfile = AgoraAudioCodecProfileType(rawValue: audioCodecProfile.intValue) { transcoding.audioCodecProfile = audioCodecProfile } } - if let videoCodecProfile = map["videoCodecProfile"] as? Int { - if let videoCodecProfile = AgoraVideoCodecProfileType(rawValue: videoCodecProfile) { + if let videoCodecProfile = map["videoCodecProfile"] as? NSNumber { + if let videoCodecProfile = AgoraVideoCodecProfileType(rawValue: videoCodecProfile.intValue) { transcoding.videoCodecProfile = videoCodecProfile } } @@ -196,8 +196,8 @@ func mapToChannelMediaInfo(_ map: Dictionary) -> AgoraChannelMediaR if let token = map["token"] as? String { info.token = token } - if let uid = map["uid"] as? UInt { - info.uid = uid + if let uid = map["uid"] as? NSNumber { + info.uid = uid.uintValue } return info } @@ -226,11 +226,11 @@ func mapToLastmileProbeConfig(_ map: Dictionary) -> AgoraLastmilePr if let probeDownlink = map["probeDownlink"] as? Bool { config.probeDownlink = probeDownlink } - if let expectedUplinkBitrate = map["expectedUplinkBitrate"] as? Int { - config.expectedUplinkBitrate = UInt(expectedUplinkBitrate) + if let expectedUplinkBitrate = map["expectedUplinkBitrate"] as? NSNumber { + config.expectedUplinkBitrate = expectedUplinkBitrate.uintValue } - if let expectedDownlinkBitrate = map["expectedDownlinkBitrate"] as? Int { - config.expectedDownlinkBitrate = UInt(expectedDownlinkBitrate) + if let expectedDownlinkBitrate = map["expectedDownlinkBitrate"] as? NSNumber { + config.expectedDownlinkBitrate = expectedDownlinkBitrate.uintValue } return config } @@ -252,33 +252,41 @@ func mapToWatermarkOptions(_ map: Dictionary) -> WatermarkOptions { func mapToLiveInjectStreamConfig(_ map: Dictionary) -> AgoraLiveInjectStreamConfig { let config = AgoraLiveInjectStreamConfig.default() config.size = mapToSize(map) - if let videoGop = map["videoGop"] as? Int { - config.videoGop = videoGop + if let videoGop = map["videoGop"] as? NSNumber { + config.videoGop = videoGop.intValue } - if let videoFramerate = map["videoFramerate"] as? Int { - config.videoFramerate = videoFramerate + if let videoFramerate = map["videoFramerate"] as? NSNumber { + config.videoFramerate = videoFramerate.intValue } - if let videoBitrate = map["videoBitrate"] as? Int { - config.videoBitrate = videoBitrate + if let videoBitrate = map["videoBitrate"] as? NSNumber { + config.videoBitrate = videoBitrate.intValue } - if let audioSampleRate = map["audioSampleRate"] as? Int { - if let audioSampleRate = AgoraAudioSampleRateType(rawValue: audioSampleRate) { + if let audioSampleRate = map["audioSampleRate"] as? NSNumber { + if let audioSampleRate = AgoraAudioSampleRateType(rawValue: audioSampleRate.intValue) { config.audioSampleRate = audioSampleRate } } - if let audioBitrate = map["audioBitrate"] as? Int { - config.audioBitrate = audioBitrate + if let audioBitrate = map["audioBitrate"] as? NSNumber { + config.audioBitrate = audioBitrate.intValue } - if let audioChannels = map["audioChannels"] as? Int { - config.audioChannels = audioChannels + if let audioChannels = map["audioChannels"] as? NSNumber { + config.audioChannels = audioChannels.intValue } return config } 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? NSNumber { + if let preference = AgoraCameraCaptureOutputPreference(rawValue: preference.intValue) { + config.preference = preference + } + } + if let cameraDirection = map["cameraDirection"] as? NSNumber { + if let cameraDirection = AgoraCameraDirection(rawValue: cameraDirection.intValue) { + config.cameraDirection = cameraDirection + } + } return config } @@ -293,15 +301,24 @@ 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? NSNumber { + config.areaCode = areaCode.uintValue + } + return config +} + func mapToEncryptionConfig(_ map: Dictionary) -> AgoraEncryptionConfig { - let encryptionConfig = AgoraEncryptionConfig() - if let encryptionMode = map["encryptionMode"] as? Int { - if let encryptionMode = AgoraEncryptionMode(rawValue: encryptionMode) { - encryptionConfig.encryptionMode = encryptionMode + let config = AgoraEncryptionConfig() + if let encryptionMode = map["encryptionMode"] as? NSNumber { + if let encryptionMode = AgoraEncryptionMode(rawValue: encryptionMode.intValue) { + config.encryptionMode = encryptionMode } } if let encryptionKey = map["encryptionKey"] as? String { - encryptionConfig.encryptionKey = encryptionKey + config.encryptionKey = encryptionKey } - return encryptionConfig + return config } 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 60367599d..5e4d7c22c 100644 --- a/RtcChannel.swift +++ b/RtcChannel.swift @@ -163,19 +163,16 @@ 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) { - callback.code(self[params["channelId"] as! String]?.setClientRole(AgoraClientRole(rawValue: params["role"] as! Int)!)) + let role = AgoraClientRole(rawValue: (params["role"] as! NSNumber).intValue)! + callback.code(self[params["channelId"] as! String]?.setClientRole(role)) } @objc func joinChannel(_ params: NSDictionary, _ callback: Callback) { - callback.code(self[params["channelId"] as! String]?.join(byToken: params["token"] as? String, info: params["optionalInfo"] as? String, uid: params["optionalUid"] as! UInt, options: mapToChannelMediaOptions(params["options"] as! Dictionary))) + callback.code(self[params["channelId"] as! String]?.join(byToken: params["token"] as? String, info: params["optionalInfo"] as? String, uid: (params["optionalUid"] as! NSNumber).uintValue, options: mapToChannelMediaOptions(params["options"] as! Dictionary))) } @objc func joinChannelWithUserAccount(_ params: NSDictionary, _ callback: Callback) { @@ -211,11 +208,11 @@ class RtcChannelManager: NSObject, RtcChannelInterface { } @objc func adjustUserPlaybackSignalVolume(_ params: NSDictionary, _ callback: Callback) { - callback.code(self[params["channelId"] as! String]?.adjustUserPlaybackSignalVolume(params["uid"] as! UInt, volume: params["volume"] as! Int32)) + callback.code(self[params["channelId"] as! String]?.adjustUserPlaybackSignalVolume((params["uid"] as! NSNumber).uintValue, volume: (params["volume"] as! NSNumber).int32Value)) } @objc func muteRemoteAudioStream(_ params: NSDictionary, _ callback: Callback) { - callback.code(self[params["channelId"] as! String]?.muteRemoteAudioStream(params["uid"] as! UInt, mute: params["muted"] as! Bool)) + callback.code(self[params["channelId"] as! String]?.muteRemoteAudioStream((params["uid"] as! NSNumber).uintValue, mute: params["muted"] as! Bool)) } @objc func muteAllRemoteAudioStreams(_ params: NSDictionary, _ callback: Callback) { @@ -227,7 +224,7 @@ class RtcChannelManager: NSObject, RtcChannelInterface { } @objc func muteRemoteVideoStream(_ params: NSDictionary, _ callback: Callback) { - callback.code(self[params["channelId"] as! String]?.muteRemoteVideoStream(params["uid"] as! UInt, mute: params["muted"] as! Bool)) + callback.code(self[params["channelId"] as! String]?.muteRemoteVideoStream((params["uid"] as! NSNumber).uintValue, mute: params["muted"] as! Bool)) } @objc func muteAllRemoteVideoStreams(_ params: NSDictionary, _ callback: Callback) { @@ -239,7 +236,7 @@ class RtcChannelManager: NSObject, RtcChannelInterface { } @objc func setRemoteVoicePosition(_ params: NSDictionary, _ callback: Callback) { - callback.code(self[params["channelId"] as! String]?.setRemoteVoicePosition(params["uid"] as! UInt, pan: params["pan"] as! Double, gain: params["gain"] as! Double)) + callback.code(self[params["channelId"] as! String]?.setRemoteVoicePosition((params["uid"] as! NSNumber).uintValue, pan: (params["pan"] as! NSNumber).doubleValue, gain: (params["gain"] as! NSNumber).doubleValue)) } @objc func setLiveTranscoding(_ params: NSDictionary, _ callback: Callback) { @@ -267,45 +264,46 @@ class RtcChannelManager: NSObject, RtcChannelInterface { } @objc func setRemoteVideoStreamType(_ params: NSDictionary, _ callback: Callback) { - callback.code(self[params["channelId"] as! String]?.setRemoteVideoStream(params["uid"] as! UInt, type: AgoraVideoStreamType(rawValue: params["streamType"] as! Int)!)) + callback.code(self[params["channelId"] as! String]?.setRemoteVideoStream((params["uid"] as! NSNumber).uintValue, type: AgoraVideoStreamType(rawValue: (params["streamType"] as! NSNumber).intValue)!)) } @objc func setRemoteDefaultVideoStreamType(_ params: NSDictionary, _ callback: Callback) { - callback.code(self[params["channelId"] as! String]?.setRemoteDefaultVideoStreamType(AgoraVideoStreamType(rawValue: params["streamType"] as! Int)!)) + callback.code(self[params["channelId"] as! String]?.setRemoteDefaultVideoStreamType(AgoraVideoStreamType(rawValue: (params["streamType"] as! NSNumber).intValue)!)) } @objc func setRemoteUserPriority(_ params: NSDictionary, _ callback: Callback) { - callback.code(self[params["channelId"] as! String]?.setRemoteUserPriority(params["uid"] as! UInt, type: AgoraUserPriority(rawValue: params["userPriority"] as! Int)!)) + callback.code(self[params["channelId"] as! String]?.setRemoteUserPriority((params["uid"] as! NSNumber).uintValue, type: AgoraUserPriority(rawValue: (params["userPriority"] as! NSNumber).intValue)!)) } @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) { callback.resolve(mediaObserverMap[params["channelId"] as! String]) { - $0.setMaxMetadataSize(params["size"] as! Int) + $0.setMaxMetadataSize((params["size"] as! NSNumber).intValue) } } @@ -321,7 +319,7 @@ class RtcChannelManager: NSObject, RtcChannelInterface { @objc func setEncryptionMode(_ params: NSDictionary, _ callback: Callback) { var encryptionMode = "" - switch params["encryptionMode"] as! Int { + switch (params["encryptionMode"] as! NSNumber).intValue { case AgoraEncryptionMode.AES128XTS.rawValue: encryptionMode = "aes-128-xts" case AgoraEncryptionMode.AES128ECB.rawValue: @@ -346,25 +344,12 @@ 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 - } + 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! NSNumber).intValue, data: (params["message"] as! String).data(using: .utf8)!)) } } diff --git a/RtcEngine.swift b/RtcEngine.swift index e8bf9c70d..097e8d318 100644 --- a/RtcEngine.swift +++ b/RtcEngine.swift @@ -359,33 +359,37 @@ 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) - callback.code(engine?.setAppType(AgoraRtcAppType(rawValue: params["appType"] as! UInt)!)) + engine = AgoraRtcEngineKit.sharedEngine(with: mapToRtcEngineConfig(params["config"] as! Dictionary), delegate: delegate) + callback.code(engine?.setAppType(AgoraRtcAppType(rawValue: (params["appType"] as! NSNumber).uintValue)!)) } @objc func destroy(_ callback: Callback) { - callback.resolve(engine) { [weak self] ignore in + callback.resolve(engine) { [weak self] _ in self?.Release() } } @objc func setChannelProfile(_ params: NSDictionary, _ callback: Callback) { - callback.code(engine?.setChannelProfile(AgoraChannelProfile(rawValue: params["profile"] as! Int)!)) + callback.code(engine?.setChannelProfile(AgoraChannelProfile(rawValue: (params["profile"] as! NSNumber).intValue)!)) } @objc func setClientRole(_ params: NSDictionary, _ callback: Callback) { - callback.code(engine?.setClientRole(AgoraClientRole(rawValue: params["role"] as! Int)!)) + let role = AgoraClientRole(rawValue: (params["role"] as! NSNumber).intValue)! + callback.code(engine?.setClientRole(role)) } @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! NSNumber + callback.code(engine?.joinChannel(byToken: token, channelId: channelName, info: optionalInfo, uid: optionalUid.uintValue)) } @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 + callback.code(engine?.switchChannel(byToken: token, channelId: channelName)) } @objc func leaveChannel(_ callback: Callback) { @@ -407,7 +411,7 @@ class RtcEngineManager: NSObject, RtcEngineInterface { } @objc func sendCustomReportMessage(_ params: NSDictionary, _ callback: Callback) { - callback.code(engine?.sendCustomReportMessage(params["id"] as! String, category: params["category"] as! String, event: params["event"] as! String, label: params["label"] as! String, value: params["value"] as! Int)) + callback.code(engine?.sendCustomReportMessage(params["id"] as! String, category: params["category"] as! String, event: params["event"] as! String, label: params["label"] as! String, value: (params["value"] as! NSNumber).intValue)) } @objc func getCallId(_ callback: Callback) { @@ -417,7 +421,7 @@ class RtcEngineManager: NSObject, RtcEngineInterface { } @objc func rate(_ params: NSDictionary, _ callback: Callback) { - callback.code(engine?.rate(params["callId"] as! String, rating: params["rating"] as! Int, description: params["description"] as? String)) + callback.code(engine?.rate(params["callId"] as! String, rating: (params["rating"] as! NSNumber).intValue, description: params["description"] as? String)) } @objc func complain(_ params: NSDictionary, _ callback: Callback) { @@ -429,11 +433,11 @@ class RtcEngineManager: NSObject, RtcEngineInterface { } @objc func setLogFilter(_ params: NSDictionary, _ callback: Callback) { - callback.code(engine?.setLogFilter(params["filter"] as! UInt)) + callback.code(engine?.setLogFilter((params["filter"] as! NSNumber).uintValue)) } @objc func setLogFileSize(_ params: NSDictionary, _ callback: Callback) { - callback.code(engine?.setLogFileSize((params["fileSizeInKBytes"] as! UInt))) + callback.code(engine?.setLogFileSize((params["fileSizeInKBytes"] as! NSNumber).uintValue)) } @objc func getNativeHandle(_ callback: Callback) { @@ -451,7 +455,10 @@ 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 + callback.code(engine?.joinChannel(byUserAccount: userAccount, token: token, channelId: channelName)) } @objc func getUserInfoByUserAccount(_ params: NSDictionary, _ callback: Callback) { @@ -462,7 +469,7 @@ class RtcEngineManager: NSObject, RtcEngineInterface { @objc func getUserInfoByUid(_ params: NSDictionary, _ callback: Callback) { callback.resolve(engine) { - $0.getUserInfo(byUid: params["uid"] as! UInt, withError: nil)?.toMap() + $0.getUserInfo(byUid: (params["uid"] as! NSNumber).uintValue, withError: nil)?.toMap() } } @@ -475,19 +482,19 @@ class RtcEngineManager: NSObject, RtcEngineInterface { } @objc func setAudioProfile(_ params: NSDictionary, _ callback: Callback) { - callback.code(engine?.setAudioProfile(AgoraAudioProfile(rawValue: params["profile"] as! Int)!, scenario: AgoraAudioScenario(rawValue: params["scenario"] as! Int)!)) + callback.code(engine?.setAudioProfile(AgoraAudioProfile(rawValue: (params["profile"] as! NSNumber).intValue)!, scenario: AgoraAudioScenario(rawValue: (params["scenario"] as! NSNumber).intValue)!)) } @objc func adjustRecordingSignalVolume(_ params: NSDictionary, _ callback: Callback) { - callback.code(engine?.adjustRecordingSignalVolume(params["volume"] as! Int)) + callback.code(engine?.adjustRecordingSignalVolume((params["volume"] as! NSNumber).intValue)) } @objc func adjustUserPlaybackSignalVolume(_ params: NSDictionary, _ callback: Callback) { - callback.code(engine?.adjustUserPlaybackSignalVolume(params["uid"] as! UInt, volume: params["volume"] as! Int32)) + callback.code(engine?.adjustUserPlaybackSignalVolume((params["uid"] as! NSNumber).uintValue, volume: (params["volume"] as! NSNumber).int32Value)) } @objc func adjustPlaybackSignalVolume(_ params: NSDictionary, _ callback: Callback) { - callback.code(engine?.adjustPlaybackSignalVolume(params["volume"] as! Int)) + callback.code(engine?.adjustPlaybackSignalVolume((params["volume"] as! NSNumber).intValue)) } @objc func enableLocalAudio(_ params: NSDictionary, _ callback: Callback) { @@ -499,7 +506,7 @@ class RtcEngineManager: NSObject, RtcEngineInterface { } @objc func muteRemoteAudioStream(_ params: NSDictionary, _ callback: Callback) { - callback.code(engine?.muteRemoteAudioStream(params["uid"] as! UInt, mute: params["muted"] as! Bool)) + callback.code(engine?.muteRemoteAudioStream((params["uid"] as! NSNumber).uintValue, mute: params["muted"] as! Bool)) } @objc func muteAllRemoteAudioStreams(_ params: NSDictionary, _ callback: Callback) { @@ -511,7 +518,7 @@ class RtcEngineManager: NSObject, RtcEngineInterface { } @objc func enableAudioVolumeIndication(_ params: NSDictionary, _ callback: Callback) { - callback.code(engine?.enableAudioVolumeIndication(params["interval"] as! Int, smooth: params["smooth"] as! Int, report_vad: params["report_vad"] as! Bool)) + callback.code(engine?.enableAudioVolumeIndication((params["interval"] as! NSNumber).intValue, smooth: (params["smooth"] as! NSNumber).intValue, report_vad: params["report_vad"] as! Bool)) } @objc func enableVideo(_ callback: Callback) { @@ -543,7 +550,7 @@ class RtcEngineManager: NSObject, RtcEngineInterface { } @objc func muteRemoteVideoStream(_ params: NSDictionary, _ callback: Callback) { - callback.code(engine?.muteRemoteVideoStream(params["uid"] as! UInt, mute: params["muted"] as! Bool)) + callback.code(engine?.muteRemoteVideoStream((params["uid"] as! NSNumber).uintValue, mute: params["muted"] as! Bool)) } @objc func muteAllRemoteVideoStreams(_ params: NSDictionary, _ callback: Callback) { @@ -559,7 +566,7 @@ class RtcEngineManager: NSObject, RtcEngineInterface { } @objc func startAudioMixing(_ params: NSDictionary, _ callback: Callback) { - callback.code(engine?.startAudioMixing(params["filePath"] as! String, loopback: params["loopback"] as! Bool, replace: params["replace"] as! Bool, cycle: params["cycle"] as! Int)) + callback.code(engine?.startAudioMixing(params["filePath"] as! String, loopback: params["loopback"] as! Bool, replace: params["replace"] as! Bool, cycle: (params["cycle"] as! NSNumber).intValue)) } @objc func stopAudioMixing(_ callback: Callback) { @@ -575,15 +582,15 @@ class RtcEngineManager: NSObject, RtcEngineInterface { } @objc func adjustAudioMixingVolume(_ params: NSDictionary, _ callback: Callback) { - callback.code(engine?.adjustAudioMixingVolume(params["volume"] as! Int)) + callback.code(engine?.adjustAudioMixingVolume((params["volume"] as! NSNumber).intValue)) } @objc func adjustAudioMixingPlayoutVolume(_ params: NSDictionary, _ callback: Callback) { - callback.code(engine?.adjustAudioMixingPlayoutVolume(params["volume"] as! Int)) + callback.code(engine?.adjustAudioMixingPlayoutVolume((params["volume"] as! NSNumber).intValue)) } @objc func adjustAudioMixingPublishVolume(_ params: NSDictionary, _ callback: Callback) { - callback.code(engine?.adjustAudioMixingPublishVolume(params["volume"] as! Int)) + callback.code(engine?.adjustAudioMixingPublishVolume((params["volume"] as! NSNumber).intValue)) } @objc func getAudioMixingPlayoutVolume(_ callback: Callback) { @@ -611,11 +618,11 @@ class RtcEngineManager: NSObject, RtcEngineInterface { } @objc func setAudioMixingPosition(_ params: NSDictionary, _ callback: Callback) { - callback.code(engine?.setAudioMixingPosition(params["pos"] as! Int)) + callback.code(engine?.setAudioMixingPosition((params["pos"] as! NSNumber).intValue)) } @objc func setAudioMixingPitch(_ params: NSDictionary, _ callback: Callback) { - callback.code(engine?.setAudioMixingPitch(params["pitch"] as! Int)) + callback.code(engine?.setAudioMixingPitch((params["pitch"] as! NSNumber).intValue)) } @objc func getEffectsVolume(_ callback: Callback) { @@ -625,19 +632,19 @@ class RtcEngineManager: NSObject, RtcEngineInterface { } @objc func setEffectsVolume(_ params: NSDictionary, _ callback: Callback) { - callback.code(engine?.setEffectsVolume(params["volume"] as! Double)) + callback.code(engine?.setEffectsVolume((params["volume"] as! NSNumber).doubleValue)) } @objc func setVolumeOfEffect(_ params: NSDictionary, _ callback: Callback) { - callback.code(engine?.setVolumeOfEffect(params["soundId"] as! Int32, withVolume: params["volume"] as! Double)) + callback.code(engine?.setVolumeOfEffect((params["soundId"] as! NSNumber).int32Value, withVolume: (params["volume"] as! NSNumber).doubleValue)) } @objc func playEffect(_ params: NSDictionary, _ callback: Callback) { - callback.code(engine?.playEffect(params["soundId"] as! Int32, filePath: params["filePath"] as? String, loopCount: params["loopCount"] as! Int32, pitch: params["pitch"] as! Double, pan: params["pan"] as! Double, gain: params["gain"] as! Double, publish: params["publish"] as! Bool)) + callback.code(engine?.playEffect((params["soundId"] as! NSNumber).int32Value, filePath: params["filePath"] as? String, loopCount: (params["loopCount"] as! NSNumber).int32Value, pitch: (params["pitch"] as! NSNumber).doubleValue, pan: (params["pan"] as! NSNumber).doubleValue, gain: (params["gain"] as! NSNumber).doubleValue, publish: params["publish"] as! Bool)) } @objc func stopEffect(_ params: NSDictionary, _ callback: Callback) { - callback.code(engine?.stopEffect(params["soundId"] as! Int32)) + callback.code(engine?.stopEffect((params["soundId"] as! NSNumber).int32Value)) } @objc func stopAllEffects(_ callback: Callback) { @@ -645,15 +652,15 @@ class RtcEngineManager: NSObject, RtcEngineInterface { } @objc func preloadEffect(_ params: NSDictionary, _ callback: Callback) { - callback.code(engine?.preloadEffect(params["soundId"] as! Int32, filePath: params["filePath"] as? String)) + callback.code(engine?.preloadEffect((params["soundId"] as! NSNumber).int32Value, filePath: params["filePath"] as? String)) } @objc func unloadEffect(_ params: NSDictionary, _ callback: Callback) { - callback.code(engine?.unloadEffect(params["soundId"] as! Int32)) + callback.code(engine?.unloadEffect((params["soundId"] as! NSNumber).int32Value)) } @objc func pauseEffect(_ params: NSDictionary, _ callback: Callback) { - callback.code(engine?.pauseEffect(params["soundId"] as! Int32)) + callback.code(engine?.pauseEffect((params["soundId"] as! NSNumber).int32Value)) } @objc func pauseAllEffects(_ callback: Callback) { @@ -661,7 +668,7 @@ class RtcEngineManager: NSObject, RtcEngineInterface { } @objc func resumeEffect(_ params: NSDictionary, _ callback: Callback) { - callback.code(engine?.resumeEffect(params["soundId"] as! Int32)) + callback.code(engine?.resumeEffect((params["soundId"] as! NSNumber).int32Value)) } @objc func resumeAllEffects(_ callback: Callback) { @@ -670,28 +677,28 @@ class RtcEngineManager: NSObject, RtcEngineInterface { @objc func setAudioSessionOperationRestriction(_ params: NSDictionary, _ callback: Callback) { callback.resolve(engine) { - $0.setAudioSessionOperationRestriction(AgoraAudioSessionOperationRestriction(rawValue: params["restriction"] as! UInt)) + $0.setAudioSessionOperationRestriction(AgoraAudioSessionOperationRestriction(rawValue: (params["restriction"] as! NSNumber).uintValue)) } } @objc func setLocalVoiceChanger(_ params: NSDictionary, _ callback: Callback) { - callback.code(engine?.setLocalVoiceChanger(AgoraAudioVoiceChanger(rawValue: params["voiceChanger"] as! Int)!)) + callback.code(engine?.setLocalVoiceChanger(AgoraAudioVoiceChanger(rawValue: (params["voiceChanger"] as! NSNumber).intValue)!)) } @objc func setLocalVoiceReverbPreset(_ params: NSDictionary, _ callback: Callback) { - callback.code(engine?.setLocalVoiceReverbPreset(AgoraAudioReverbPreset(rawValue: params["preset"] as! Int)!)) + callback.code(engine?.setLocalVoiceReverbPreset(AgoraAudioReverbPreset(rawValue: (params["preset"] as! NSNumber).intValue)!)) } @objc func setLocalVoicePitch(_ params: NSDictionary, _ callback: Callback) { - callback.code(engine?.setLocalVoicePitch(params["pitch"] as! Double)) + callback.code(engine?.setLocalVoicePitch((params["pitch"] as! NSNumber).doubleValue)) } @objc func setLocalVoiceEqualization(_ params: NSDictionary, _ callback: Callback) { - callback.code(engine?.setLocalVoiceEqualizationOf(AgoraAudioEqualizationBandFrequency(rawValue: params["bandFrequency"] as! Int)!, withGain: params["bandGain"] as! Int)) + callback.code(engine?.setLocalVoiceEqualizationOf(AgoraAudioEqualizationBandFrequency(rawValue: (params["bandFrequency"] as! NSNumber).intValue)!, withGain: (params["bandGain"] as! NSNumber).intValue)) } @objc func setLocalVoiceReverb(_ params: NSDictionary, _ callback: Callback) { - callback.code(engine?.setLocalVoiceReverbOf(AgoraAudioReverbType(rawValue: params["reverbKey"] as! Int)!, withValue: params["value"] as! Int)) + callback.code(engine?.setLocalVoiceReverbOf(AgoraAudioReverbType(rawValue: (params["reverbKey"] as! NSNumber).intValue)!, withValue: (params["value"] as! NSNumber).intValue)) } @objc func enableSoundPositionIndication(_ params: NSDictionary, _ callback: Callback) { @@ -699,7 +706,7 @@ class RtcEngineManager: NSObject, RtcEngineInterface { } @objc func setRemoteVoicePosition(_ params: NSDictionary, _ callback: Callback) { - callback.code(engine?.setRemoteVoicePosition(params["uid"] as! UInt, pan: params["pan"] as! Double, gain: params["gain"] as! Double)) + callback.code(engine?.setRemoteVoicePosition((params["uid"] as! NSNumber).uintValue, pan: (params["pan"] as! NSNumber).doubleValue, gain: (params["gain"] as! NSNumber).doubleValue)) } @objc func setLiveTranscoding(_ params: NSDictionary, _ callback: Callback) { @@ -745,7 +752,7 @@ class RtcEngineManager: NSObject, RtcEngineInterface { } @objc func setInEarMonitoringVolume(_ params: NSDictionary, _ callback: Callback) { - callback.code(engine?.setInEarMonitoringVolume(params["volume"] as! Int)) + callback.code(engine?.setInEarMonitoringVolume((params["volume"] as! NSNumber).intValue)) } @objc func enableDualStreamMode(_ params: NSDictionary, _ callback: Callback) { @@ -753,27 +760,27 @@ class RtcEngineManager: NSObject, RtcEngineInterface { } @objc func setRemoteVideoStreamType(_ params: NSDictionary, _ callback: Callback) { - callback.code(engine?.setRemoteVideoStream(params["uid"] as! UInt, type: AgoraVideoStreamType(rawValue: params["streamType"] as! Int)!)) + callback.code(engine?.setRemoteVideoStream((params["uid"] as! NSNumber).uintValue, type: AgoraVideoStreamType(rawValue: (params["streamType"] as! NSNumber).intValue)!)) } @objc func setRemoteDefaultVideoStreamType(_ params: NSDictionary, _ callback: Callback) { - callback.code(engine?.setRemoteDefaultVideoStreamType(AgoraVideoStreamType(rawValue: params["streamType"] as! Int)!)) + callback.code(engine?.setRemoteDefaultVideoStreamType(AgoraVideoStreamType(rawValue: (params["streamType"] as! NSNumber).intValue)!)) } @objc func setLocalPublishFallbackOption(_ params: NSDictionary, _ callback: Callback) { - callback.code(engine?.setLocalPublishFallbackOption(AgoraStreamFallbackOptions(rawValue: params["option"] as! Int)!)) + callback.code(engine?.setLocalPublishFallbackOption(AgoraStreamFallbackOptions(rawValue: (params["option"] as! NSNumber).intValue)!)) } @objc func setRemoteSubscribeFallbackOption(_ params: NSDictionary, _ callback: Callback) { - callback.code(engine?.setRemoteSubscribeFallbackOption(AgoraStreamFallbackOptions(rawValue: params["option"] as! Int)!)) + callback.code(engine?.setRemoteSubscribeFallbackOption(AgoraStreamFallbackOptions(rawValue: (params["option"] as! NSNumber).intValue)!)) } @objc func setRemoteUserPriority(_ params: NSDictionary, _ callback: Callback) { - callback.code(engine?.setRemoteUserPriority(params["uid"] as! UInt, type: AgoraUserPriority(rawValue: params["userPriority"] as! Int)!)) + callback.code(engine?.setRemoteUserPriority((params["uid"] as! NSNumber).uintValue, type: AgoraUserPriority(rawValue: (params["userPriority"] as! NSNumber).intValue)!)) } @objc func startEchoTest(_ params: NSDictionary, _ callback: Callback) { - callback.code(engine?.startEchoTest(withInterval: params["intervalInSeconds"] as! Int)) + callback.code(engine?.startEchoTest(withInterval: (params["intervalInSeconds"] as! NSNumber).intValue)) } @objc func stopEchoTest(_ callback: Callback) { @@ -797,33 +804,29 @@ 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) { callback.resolve(mediaObserver) { - $0.setMaxMetadataSize(params["size"] as! Int) + $0.setMaxMetadataSize((params["size"] as! NSNumber).intValue) } } @@ -847,7 +850,7 @@ class RtcEngineManager: NSObject, RtcEngineInterface { @objc func setEncryptionMode(_ params: NSDictionary, _ callback: Callback) { var encryptionMode = "" - switch params["encryptionMode"] as! Int { + switch (params["encryptionMode"] as! NSNumber).intValue { case AgoraEncryptionMode.AES128XTS.rawValue: encryptionMode = "aes-128-xts" case AgoraEncryptionMode.AES128ECB.rawValue: @@ -864,7 +867,7 @@ class RtcEngineManager: NSObject, RtcEngineInterface { } @objc func startAudioRecording(_ params: NSDictionary, _ callback: Callback) { - callback.code(engine?.startAudioRecording(params["filePath"] as! String, sampleRate: params["sampleRate"] as! Int, quality: AgoraAudioRecordingQuality(rawValue: params["quality"] as! Int)!)) + callback.code(engine?.startAudioRecording(params["filePath"] as! String, sampleRate: (params["sampleRate"] as! NSNumber).intValue, quality: AgoraAudioRecordingQuality(rawValue: (params["quality"] as! NSNumber).intValue)!)) } @objc func stopAudioRecording(_ callback: Callback) { @@ -913,7 +916,7 @@ class RtcEngineManager: NSObject, RtcEngineInterface { @objc func setCameraZoomFactor(_ params: NSDictionary, _ callback: Callback) { callback.resolve(engine) { - $0.setCameraZoomFactor(CGFloat(params["factor"] as! Float)) + $0.setCameraZoomFactor(CGFloat(truncating: params["factor"] as! NSNumber)) return nil } } @@ -924,14 +927,14 @@ class RtcEngineManager: NSObject, RtcEngineInterface { @objc func setCameraFocusPositionInPreview(_ params: NSDictionary, _ callback: Callback) { callback.resolve(engine) { - $0.setCameraFocusPositionInPreview(CGPoint(x: params["positionX"] as! Double, y: params["positionY"] as! Double)) + $0.setCameraFocusPositionInPreview(CGPoint(x: (params["positionX"] as! NSNumber).doubleValue, y: (params["positionY"] as! NSNumber).doubleValue)) return nil } } @objc func setCameraExposurePosition(_ params: NSDictionary, _ callback: Callback) { callback.resolve(engine) { - $0.setCameraExposurePosition(CGPoint(x: params["positionXinView"] as! Double, y: params["positionYinView"] as! Double)) + $0.setCameraExposurePosition(CGPoint(x: (params["positionXinView"] as! NSNumber).doubleValue, y: (params["positionYinView"] as! NSNumber).doubleValue)) return nil } } @@ -958,25 +961,11 @@ 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 - } + 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(code) + callback.code(engine?.sendStreamMessage((params["streamId"] as! NSNumber).intValue, data: (params["message"] as! String).data(using: .utf8)!)) } } diff --git a/RtcSurfaceView.swift b/RtcSurfaceView.swift index 9ae740cab..89b4f9826 100644 --- a/RtcSurfaceView.swift +++ b/RtcSurfaceView.swift @@ -37,10 +37,10 @@ class RtcSurfaceView: UIView { removeObserver(self, forKeyPath: observerForKeyPath(), context: nil) } - func setData(_ engine: AgoraRtcEngineKit, _ channel: AgoraRtcChannel?, _ uid: Int) { + func setData(_ engine: AgoraRtcEngineKit, _ channel: AgoraRtcChannel?, _ uid: UInt) { self.channel = channel canvas.channelId = channel?.getId() - canvas.uid = UInt(uid) + canvas.uid = uid setupVideoCanvas(engine) } @@ -73,13 +73,13 @@ class RtcSurfaceView: UIView { } } - func setRenderMode(_ engine: AgoraRtcEngineKit, _ renderMode: Int) { - canvas.renderMode = AgoraVideoRenderMode(rawValue: UInt(renderMode))! + func setRenderMode(_ engine: AgoraRtcEngineKit, _ renderMode: UInt) { + canvas.renderMode = AgoraVideoRenderMode(rawValue: renderMode)! setupRenderMode(engine) } - func setMirrorMode(_ engine: AgoraRtcEngineKit, _ mirrorMode: Int) { - canvas.mirrorMode = AgoraVideoMirrorMode(rawValue: UInt(mirrorMode))! + func setMirrorMode(_ engine: AgoraRtcEngineKit, _ mirrorMode: UInt) { + canvas.mirrorMode = AgoraVideoMirrorMode(rawValue: mirrorMode)! setupRenderMode(engine) }