Skip to content

Commit 98c4331

Browse files
committed
fix: type cast error
1 parent 836f3b4 commit 98c4331

File tree

4 files changed

+174
-174
lines changed

4 files changed

+174
-174
lines changed

BeanCovertor.swift

+94-94
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,22 @@ import AgoraRtcKit
1111

1212
func mapToPoint(_ map: Dictionary<String, Any>) -> CGPoint {
1313
var point = CGPoint()
14-
if let x = map["x"] as? Int {
15-
point.x = CGFloat(x)
14+
if let x = map["x"] as? NSNumber {
15+
point.x = CGFloat(truncating: x)
1616
}
17-
if let y = map["y"] as? Int {
18-
point.y = CGFloat(y)
17+
if let y = map["y"] as? NSNumber {
18+
point.y = CGFloat(truncating: y)
1919
}
2020
return point
2121
}
2222

2323
func mapToSize(_ map: Dictionary<String, Any>) -> CGSize {
2424
var size = CGSize()
25-
if let width = map["width"] as? Int {
26-
size.width = CGFloat(width)
25+
if let width = map["width"] as? NSNumber {
26+
size.width = CGFloat(truncating: width)
2727
}
28-
if let height = map["height"] as? Int {
29-
size.height = CGFloat(height)
28+
if let height = map["height"] as? NSNumber {
29+
size.height = CGFloat(truncating: height)
3030
}
3131
return size
3232
}
@@ -43,30 +43,30 @@ func mapToVideoEncoderConfiguration(_ map: Dictionary<String, Any>) -> AgoraVide
4343
if let dimensions = map["dimensions"] as? Dictionary<String, Any> {
4444
config.dimensions = mapToSize(dimensions)
4545
}
46-
if let frameRate = map["frameRate"] as? Int {
47-
config.frameRate = frameRate
46+
if let frameRate = map["frameRate"] as? NSNumber {
47+
config.frameRate = frameRate.intValue
4848
}
49-
if let minFrameRate = map["minFrameRate"] as? Int {
50-
config.minFrameRate = minFrameRate
49+
if let minFrameRate = map["minFrameRate"] as? NSNumber {
50+
config.minFrameRate = minFrameRate.intValue
5151
}
52-
if let bitrate = map["bitrate"] as? Int {
53-
config.bitrate = bitrate
52+
if let bitrate = map["bitrate"] as? NSNumber {
53+
config.bitrate = bitrate.intValue
5454
}
55-
if let minBitrate = map["minBitrate"] as? Int {
56-
config.minBitrate = minBitrate
55+
if let minBitrate = map["minBitrate"] as? NSNumber {
56+
config.minBitrate = minBitrate.intValue
5757
}
58-
if let orientationMode = map["orientationMode"] as? Int {
59-
if let orientationMode = AgoraVideoOutputOrientationMode(rawValue: orientationMode) {
58+
if let orientationMode = map["orientationMode"] as? NSNumber {
59+
if let orientationMode = AgoraVideoOutputOrientationMode(rawValue: orientationMode.intValue) {
6060
config.orientationMode = orientationMode
6161
}
6262
}
63-
if let degradationPreference = map["degradationPrefer"] as? Int {
64-
if let degradationPreference = AgoraDegradationPreference(rawValue: degradationPreference) {
63+
if let degradationPreference = map["degradationPrefer"] as? NSNumber {
64+
if let degradationPreference = AgoraDegradationPreference(rawValue: degradationPreference.intValue) {
6565
config.degradationPreference = degradationPreference
6666
}
6767
}
68-
if let mirrorMode = map["mirrorMode"] as? Int {
69-
if let mirrorMode = AgoraVideoMirrorMode(rawValue: UInt(mirrorMode)) {
68+
if let mirrorMode = map["mirrorMode"] as? NSNumber {
69+
if let mirrorMode = AgoraVideoMirrorMode(rawValue: mirrorMode.uintValue) {
7070
config.mirrorMode = mirrorMode
7171
}
7272
}
@@ -75,19 +75,19 @@ func mapToVideoEncoderConfiguration(_ map: Dictionary<String, Any>) -> AgoraVide
7575

7676
func mapToBeautyOptions(_ map: Dictionary<String, Any>) -> AgoraBeautyOptions {
7777
let options = AgoraBeautyOptions()
78-
if let lighteningContrastLevel = map["lighteningContrastLevel"] as? Int {
79-
if let lighteningContrastLevel = AgoraLighteningContrastLevel(rawValue: UInt(lighteningContrastLevel)) {
78+
if let lighteningContrastLevel = map["lighteningContrastLevel"] as? NSNumber {
79+
if let lighteningContrastLevel = AgoraLighteningContrastLevel(rawValue: lighteningContrastLevel.uintValue) {
8080
options.lighteningContrastLevel = lighteningContrastLevel
8181
}
8282
}
83-
if let lighteningLevel = map["lighteningLevel"] as? Float {
84-
options.lighteningLevel = lighteningLevel
83+
if let lighteningLevel = map["lighteningLevel"] as? NSNumber {
84+
options.lighteningLevel = lighteningLevel.floatValue
8585
}
86-
if let smoothnessLevel = map["smoothnessLevel"] as? Float {
87-
options.smoothnessLevel = smoothnessLevel
86+
if let smoothnessLevel = map["smoothnessLevel"] as? NSNumber {
87+
options.smoothnessLevel = smoothnessLevel.floatValue
8888
}
89-
if let rednessLevel = map["rednessLevel"] as? Float {
90-
options.rednessLevel = rednessLevel
89+
if let rednessLevel = map["rednessLevel"] as? NSNumber {
90+
options.rednessLevel = rednessLevel.floatValue
9191
}
9292
return options
9393
}
@@ -105,70 +105,70 @@ func mapToAgoraImage(_ map: Dictionary<String, Any>) -> AgoraImage {
105105

106106
func mapToTranscodingUser(_ map: Dictionary<String, Any>) -> AgoraLiveTranscodingUser {
107107
let user = AgoraLiveTranscodingUser()
108-
if let uid = map["uid"] as? Int {
109-
user.uid = UInt(uid)
108+
if let uid = map["uid"] as? NSNumber {
109+
user.uid = uid.uintValue
110110
}
111111
user.rect = mapToRect(map)
112-
if let zOrder = map["zOrder"] as? Int {
113-
user.zOrder = zOrder
112+
if let zOrder = map["zOrder"] as? NSNumber {
113+
user.zOrder = zOrder.intValue
114114
}
115-
if let alpha = map["alpha"] as? Double {
116-
user.alpha = alpha
115+
if let alpha = map["alpha"] as? NSNumber {
116+
user.alpha = alpha.doubleValue
117117
}
118-
if let audioChannel = map["audioChannel"] as? Int {
119-
user.audioChannel = audioChannel
118+
if let audioChannel = map["audioChannel"] as? NSNumber {
119+
user.audioChannel = audioChannel.intValue
120120
}
121121
return user
122122
}
123123

124124
func mapToColor(_ map: Dictionary<String, Any>) -> UIColor {
125125
return UIColor(
126-
red: CGFloat(map["red"] as! Int),
127-
green: CGFloat(map["green"] as! Int),
128-
blue: CGFloat(map["blue"] as! Int),
129-
alpha: 1.0
126+
red: CGFloat((map["red"] as! NSNumber).intValue),
127+
green: CGFloat((map["green"] as! NSNumber).intValue),
128+
blue: CGFloat((map["blue"] as! NSNumber).intValue),
129+
alpha: 1.0
130130
)
131131
}
132132

133133
func mapToLiveTranscoding(_ map: Dictionary<String, Any>) -> AgoraLiveTranscoding {
134134
let transcoding = AgoraLiveTranscoding.default()
135135
transcoding.size = mapToSize(map)
136-
if let videoBitrate = map["videoBitrate"] as? Int {
137-
transcoding.videoBitrate = videoBitrate
136+
if let videoBitrate = map["videoBitrate"] as? NSNumber {
137+
transcoding.videoBitrate = videoBitrate.intValue
138138
}
139-
if let videoFramerate = map["videoFramerate"] as? Int {
140-
transcoding.videoFramerate = videoFramerate
139+
if let videoFramerate = map["videoFramerate"] as? NSNumber {
140+
transcoding.videoFramerate = videoFramerate.intValue
141141
}
142142
if let lowLatency = map["lowLatency"] as? Bool {
143143
transcoding.lowLatency = lowLatency
144144
}
145-
if let videoGop = map["videoGop"] as? Int {
146-
transcoding.videoGop = videoGop
145+
if let videoGop = map["videoGop"] as? NSNumber {
146+
transcoding.videoGop = videoGop.intValue
147147
}
148148
if let watermark = map["watermark"] as? Dictionary<String, Any> {
149149
transcoding.watermark = mapToAgoraImage(watermark)
150150
}
151151
if let backgroundImage = map["backgroundImage"] as? Dictionary<String, Any> {
152152
transcoding.backgroundImage = mapToAgoraImage(backgroundImage)
153153
}
154-
if let audioSampleRate = map["audioSampleRate"] as? Int {
155-
if let audioSampleRate = AgoraAudioSampleRateType(rawValue: audioSampleRate) {
154+
if let audioSampleRate = map["audioSampleRate"] as? NSNumber {
155+
if let audioSampleRate = AgoraAudioSampleRateType(rawValue: audioSampleRate.intValue) {
156156
transcoding.audioSampleRate = audioSampleRate
157157
}
158158
}
159-
if let audioBitrate = map["audioBitrate"] as? Int {
160-
transcoding.audioBitrate = audioBitrate
159+
if let audioBitrate = map["audioBitrate"] as? NSNumber {
160+
transcoding.audioBitrate = audioBitrate.intValue
161161
}
162-
if let audioChannels = map["audioChannels"] as? Int {
163-
transcoding.audioChannels = audioChannels
162+
if let audioChannels = map["audioChannels"] as? NSNumber {
163+
transcoding.audioChannels = audioChannels.intValue
164164
}
165-
if let audioCodecProfile = map["audioCodecProfile"] as? Int {
166-
if let audioCodecProfile = AgoraAudioCodecProfileType(rawValue: audioCodecProfile) {
165+
if let audioCodecProfile = map["audioCodecProfile"] as? NSNumber {
166+
if let audioCodecProfile = AgoraAudioCodecProfileType(rawValue: audioCodecProfile.intValue) {
167167
transcoding.audioCodecProfile = audioCodecProfile
168168
}
169169
}
170-
if let videoCodecProfile = map["videoCodecProfile"] as? Int {
171-
if let videoCodecProfile = AgoraVideoCodecProfileType(rawValue: videoCodecProfile) {
170+
if let videoCodecProfile = map["videoCodecProfile"] as? NSNumber {
171+
if let videoCodecProfile = AgoraVideoCodecProfileType(rawValue: videoCodecProfile.intValue) {
172172
transcoding.videoCodecProfile = videoCodecProfile
173173
}
174174
}
@@ -196,8 +196,8 @@ func mapToChannelMediaInfo(_ map: Dictionary<String, Any>) -> AgoraChannelMediaR
196196
if let token = map["token"] as? String {
197197
info.token = token
198198
}
199-
if let uid = map["uid"] as? UInt {
200-
info.uid = uid
199+
if let uid = map["uid"] as? NSNumber {
200+
info.uid = uid.uintValue
201201
}
202202
return info
203203
}
@@ -226,11 +226,11 @@ func mapToLastmileProbeConfig(_ map: Dictionary<String, Any>) -> AgoraLastmilePr
226226
if let probeDownlink = map["probeDownlink"] as? Bool {
227227
config.probeDownlink = probeDownlink
228228
}
229-
if let expectedUplinkBitrate = map["expectedUplinkBitrate"] as? Int {
230-
config.expectedUplinkBitrate = UInt(expectedUplinkBitrate)
229+
if let expectedUplinkBitrate = map["expectedUplinkBitrate"] as? NSNumber {
230+
config.expectedUplinkBitrate = expectedUplinkBitrate.uintValue
231231
}
232-
if let expectedDownlinkBitrate = map["expectedDownlinkBitrate"] as? Int {
233-
config.expectedDownlinkBitrate = UInt(expectedDownlinkBitrate)
232+
if let expectedDownlinkBitrate = map["expectedDownlinkBitrate"] as? NSNumber {
233+
config.expectedDownlinkBitrate = expectedDownlinkBitrate.uintValue
234234
}
235235
return config
236236
}
@@ -252,44 +252,44 @@ func mapToWatermarkOptions(_ map: Dictionary<String, Any>) -> WatermarkOptions {
252252
func mapToLiveInjectStreamConfig(_ map: Dictionary<String, Any>) -> AgoraLiveInjectStreamConfig {
253253
let config = AgoraLiveInjectStreamConfig.default()
254254
config.size = mapToSize(map)
255-
if let videoGop = map["videoGop"] as? Int {
256-
config.videoGop = videoGop
255+
if let videoGop = map["videoGop"] as? NSNumber {
256+
config.videoGop = videoGop.intValue
257257
}
258-
if let videoFramerate = map["videoFramerate"] as? Int {
259-
config.videoFramerate = videoFramerate
258+
if let videoFramerate = map["videoFramerate"] as? NSNumber {
259+
config.videoFramerate = videoFramerate.intValue
260260
}
261-
if let videoBitrate = map["videoBitrate"] as? Int {
262-
config.videoBitrate = videoBitrate
261+
if let videoBitrate = map["videoBitrate"] as? NSNumber {
262+
config.videoBitrate = videoBitrate.intValue
263263
}
264-
if let audioSampleRate = map["audioSampleRate"] as? Int {
265-
if let audioSampleRate = AgoraAudioSampleRateType(rawValue: audioSampleRate) {
264+
if let audioSampleRate = map["audioSampleRate"] as? NSNumber {
265+
if let audioSampleRate = AgoraAudioSampleRateType(rawValue: audioSampleRate.intValue) {
266266
config.audioSampleRate = audioSampleRate
267267
}
268268
}
269-
if let audioBitrate = map["audioBitrate"] as? Int {
270-
config.audioBitrate = audioBitrate
269+
if let audioBitrate = map["audioBitrate"] as? NSNumber {
270+
config.audioBitrate = audioBitrate.intValue
271271
}
272-
if let audioChannels = map["audioChannels"] as? Int {
273-
config.audioChannels = audioChannels
272+
if let audioChannels = map["audioChannels"] as? NSNumber {
273+
config.audioChannels = audioChannels.intValue
274274
}
275275
return config
276276
}
277277

278278
func mapToCameraCapturerConfiguration(_ map: Dictionary<String, Any>) -> AgoraCameraCapturerConfiguration {
279279
let config = AgoraCameraCapturerConfiguration()
280-
if let preference = map["preference"] as? Int {
281-
if let preference = AgoraCameraCaptureOutputPreference(rawValue: preference) {
280+
if let preference = map["preference"] as? NSNumber {
281+
if let preference = AgoraCameraCaptureOutputPreference(rawValue: preference.intValue) {
282282
config.preference = preference
283283
}
284284
}
285-
if let captureWidth = map["captureWidth"] as? Int32 {
286-
config.captureWidth = captureWidth
285+
if let captureWidth = map["captureWidth"] as? NSNumber {
286+
config.captureWidth = captureWidth.int32Value
287287
}
288-
if let captureHeight = map["captureHeight"] as? Int32 {
289-
config.captureHeight = captureHeight
288+
if let captureHeight = map["captureHeight"] as? NSNumber {
289+
config.captureHeight = captureHeight.int32Value
290290
}
291-
if let cameraDirection = map["cameraDirection"] as? Int {
292-
if let cameraDirection = AgoraCameraDirection(rawValue: cameraDirection) {
291+
if let cameraDirection = map["cameraDirection"] as? NSNumber {
292+
if let cameraDirection = AgoraCameraDirection(rawValue: cameraDirection.intValue) {
293293
config.cameraDirection = cameraDirection
294294
}
295295
}
@@ -310,8 +310,8 @@ func mapToChannelMediaOptions(_ map: Dictionary<String, Any>) -> AgoraRtcChannel
310310
func mapToRtcEngineConfig(_ map: Dictionary<String, Any>) -> AgoraRtcEngineConfig {
311311
let config = AgoraRtcEngineConfig()
312312
config.appId = map["appId"] as? String
313-
if let areaCode = map["areaCode"] as? UInt {
314-
config.areaCode = areaCode
313+
if let areaCode = map["areaCode"] as? NSNumber {
314+
config.areaCode = areaCode.uintValue
315315
}
316316
if let logConfig = map["logConfig"] as? Dictionary<String, Any> {
317317
config.logConfig = mapToLogConfig(logConfig)
@@ -321,8 +321,8 @@ func mapToRtcEngineConfig(_ map: Dictionary<String, Any>) -> AgoraRtcEngineConfi
321321

322322
func mapToEncryptionConfig(_ map: Dictionary<String, Any>) -> AgoraEncryptionConfig {
323323
let config = AgoraEncryptionConfig()
324-
if let encryptionMode = map["encryptionMode"] as? Int {
325-
if let encryptionMode = AgoraEncryptionMode(rawValue: encryptionMode) {
324+
if let encryptionMode = map["encryptionMode"] as? NSNumber {
325+
if let encryptionMode = AgoraEncryptionMode(rawValue: encryptionMode.intValue) {
326326
config.encryptionMode = encryptionMode
327327
}
328328
}
@@ -334,8 +334,8 @@ func mapToEncryptionConfig(_ map: Dictionary<String, Any>) -> AgoraEncryptionCon
334334

335335
func mapToClientRoleOptions(_ map: Dictionary<String, Any>) -> AgoraClientRoleOptions {
336336
let options = AgoraClientRoleOptions()
337-
if let audienceLatencyLevel = map["audienceLatencyLevel"] as? Int {
338-
if let audienceLatencyLevel = AgoraAudienceLatencyLevelType(rawValue: audienceLatencyLevel) {
337+
if let audienceLatencyLevel = map["audienceLatencyLevel"] as? NSNumber {
338+
if let audienceLatencyLevel = AgoraAudienceLatencyLevelType(rawValue: audienceLatencyLevel.intValue) {
339339
options.audienceLatencyLevel = audienceLatencyLevel
340340
}
341341
}
@@ -345,11 +345,11 @@ func mapToClientRoleOptions(_ map: Dictionary<String, Any>) -> AgoraClientRoleOp
345345
func mapToLogConfig(_ map: Dictionary<String, Any>) -> AgoraLogConfig {
346346
let config = AgoraLogConfig()
347347
config.filePath = map["filePath"] as? String
348-
if let fileSize = map["fileSize"] as? Int {
349-
config.fileSize = fileSize
348+
if let fileSize = map["fileSize"] as? NSNumber {
349+
config.fileSize = fileSize.intValue
350350
}
351-
if let level = map["level"] as? Int {
352-
if let level = AgoraLogLevel.init(rawValue: level) {
351+
if let level = map["level"] as? NSNumber {
352+
if let level = AgoraLogLevel.init(rawValue: level.intValue) {
353353
config.level = level;
354354
}
355355
}

0 commit comments

Comments
 (0)