Skip to content

Commit

Permalink
fix(uid compatible): int to uint
Browse files Browse the repository at this point in the history
  • Loading branch information
RoJoHub committed May 7, 2021
1 parent 2bac9da commit cdc9eae
Show file tree
Hide file tree
Showing 10 changed files with 83 additions and 72 deletions.
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ def kotlin_version = getExtOrDefault('kotlinVersion')
dependencies {
// noinspection GradleDynamicVersion
api 'com.facebook.react:react-native:+'
api 'com.github.agorabuilder:native-full-sdk:3.4.1'
api 'com.github.agorabuilder:native-full-sdk:3.4.1.1'

implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
}
4 changes: 2 additions & 2 deletions android/src/main/java/io/agora/rtc/base/BeanCovertor.kt
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ fun mapToAgoraImage(map: Map<*, *>): AgoraImage {

fun mapToTranscodingUser(map: Map<*, *>): TranscodingUser {
return TranscodingUser().apply {
(map["uid"] as? Number)?.let { uid = it.toInt() }
map["uid"]?.toSDKUInt()?.let { uid = it }
(map["x"] as? Number)?.let { x = it.toInt() }
(map["y"] as? Number)?.let { y = it.toInt() }
(map["width"] as? Number)?.let { width = it.toInt() }
Expand Down Expand Up @@ -105,7 +105,7 @@ fun mapToChannelMediaInfo(map: Map<*, *>): ChannelMediaInfo {
return ChannelMediaInfo(
map["channelName"] as? String,
map["token"] as? String,
(map["uid"] as Number).toInt()
map["uid"]?.toSDKUInt()!!
)
}

Expand Down
17 changes: 13 additions & 4 deletions android/src/main/java/io/agora/rtc/base/Extensions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import io.agora.rtc.models.UserInfo

fun UserInfo.toMap(): Map<String, Any?> {
return hashMapOf(
"uid" to uid,
"uid" to uid.toJSUInt(),
"userAccount" to userAccount
)
}
Expand Down Expand Up @@ -59,7 +59,7 @@ fun Rect.toMap(): Map<String, Any?> {

fun RemoteAudioStats.toMap(): Map<String, Any?> {
return hashMapOf(
"uid" to uid,
"uid" to uid.toJSUInt(),
"quality" to quality,
"networkTransportDelay" to networkTransportDelay,
"jitterBufferDelay" to jitterBufferDelay,
Expand Down Expand Up @@ -99,7 +99,7 @@ fun LocalVideoStats.toMap(): Map<String, Any?> {

fun RemoteVideoStats.toMap(): Map<String, Any?> {
return hashMapOf(
"uid" to uid,
"uid" to uid.toJSUInt(),
"delay" to delay,
"width" to width,
"height" to height,
Expand All @@ -117,7 +117,7 @@ fun RemoteVideoStats.toMap(): Map<String, Any?> {

fun AudioVolumeInfo.toMap(): Map<String, Any?> {
return hashMapOf(
"uid" to uid,
"uid" to uid.toJSUInt(),
"volume" to volume,
"vad" to vad,
"channelId" to channelId
Expand Down Expand Up @@ -158,3 +158,12 @@ fun AgoraFacePositionInfo.toMap(): Map<String, Any?> {
fun Array<out AgoraFacePositionInfo>.toMapList(): List<Map<String, Any?>> {
return List(size) { this[it].toMap() }
}

@ExperimentalUnsignedTypes
fun Any.toSDKUInt(): Int? {
return (this as? Number)?.toLong()?.toUInt()?.toInt()
}

fun Int.toJSUInt(): Long {
return this.toUInt().toLong();
}
2 changes: 1 addition & 1 deletion android/src/main/java/io/agora/rtc/base/MediaObserver.kt
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class MediaObserver(

override fun onMetadataReceived(buffer: ByteArray, uid: Int, timeStampMs: Long) {
emit(hashMapOf(
"data" to arrayListOf(String(buffer), uid, timeStampMs)
"data" to arrayListOf(String(buffer), uid.toJSUInt(), timeStampMs)
))
}
}
16 changes: 8 additions & 8 deletions android/src/main/java/io/agora/rtc/base/RtcChannel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ class RtcChannelManager(
}

override fun joinChannel(params: Map<String, *>, callback: Callback) {
callback.code(this[params["channelId"] as String]?.joinChannel(params["token"] as? String, params["optionalInfo"] as? String, (params["optionalUid"] as Number).toInt(), mapToChannelMediaOptions(params["options"] as Map<*, *>)))
callback.code(this[params["channelId"] as String]?.joinChannel(params["token"] as? String, params["optionalInfo"] as? String, params["optionalUid"]?.toSDKUInt()!!, mapToChannelMediaOptions(params["options"] as Map<*, *>)))
}

override fun joinChannelWithUserAccount(params: Map<String, *>, callback: Callback) {
Expand Down Expand Up @@ -191,11 +191,11 @@ class RtcChannelManager(
}

override fun adjustUserPlaybackSignalVolume(params: Map<String, *>, callback: Callback) {
callback.code(this[params["channelId"] as String]?.adjustUserPlaybackSignalVolume((params["uid"] as Number).toInt(), (params["volume"] as Number).toInt()))
callback.code(this[params["channelId"] as String]?.adjustUserPlaybackSignalVolume(params["uid"]?.toSDKUInt()!!, (params["volume"] as Number).toInt()))
}

override fun muteRemoteAudioStream(params: Map<String, *>, callback: Callback) {
callback.code(this[params["channelId"] as String]?.muteRemoteAudioStream((params["uid"] as Number).toInt(), params["muted"] as Boolean))
callback.code(this[params["channelId"] as String]?.muteRemoteAudioStream(params["uid"]?.toSDKUInt()!!, params["muted"] as Boolean))
}

override fun muteAllRemoteAudioStreams(params: Map<String, *>, callback: Callback) {
Expand All @@ -207,7 +207,7 @@ class RtcChannelManager(
}

override fun muteRemoteVideoStream(params: Map<String, *>, callback: Callback) {
callback.code(this[params["channelId"] as String]?.muteRemoteVideoStream((params["uid"] as Number).toInt(), params["muted"] as Boolean))
callback.code(this[params["channelId"] as String]?.muteRemoteVideoStream(params["uid"]?.toSDKUInt()!!, params["muted"] as Boolean))
}

override fun muteAllRemoteVideoStreams(params: Map<String, *>, callback: Callback) {
Expand All @@ -219,11 +219,11 @@ class RtcChannelManager(
}

override fun enableRemoteSuperResolution(params: Map<String, *>, callback: Callback) {
callback.code(this[params["channelId"] as String]?.enableRemoteSuperResolution((params["uid"] as Number).toInt(), params["enable"] as Boolean))
callback.code(this[params["channelId"] as String]?.enableRemoteSuperResolution(params["uid"]?.toSDKUInt()!!, params["enable"] as Boolean))
}

override fun setRemoteVoicePosition(params: Map<String, *>, callback: Callback) {
callback.code(this[params["channelId"] as String]?.setRemoteVoicePosition((params["uid"] as Number).toInt(), (params["pan"] as Number).toDouble(), (params["gain"] as Number).toDouble()))
callback.code(this[params["channelId"] as String]?.setRemoteVoicePosition(params["uid"]?.toSDKUInt()!!, (params["pan"] as Number).toDouble(), (params["gain"] as Number).toDouble()))
}

override fun setLiveTranscoding(params: Map<String, *>, callback: Callback) {
Expand Down Expand Up @@ -251,15 +251,15 @@ class RtcChannelManager(
}

override fun setRemoteVideoStreamType(params: Map<String, *>, callback: Callback) {
callback.code(this[params["channelId"] as String]?.setRemoteVideoStreamType((params["uid"] as Number).toInt(), (params["streamType"] as Number).toInt()))
callback.code(this[params["channelId"] as String]?.setRemoteVideoStreamType(params["uid"]?.toSDKUInt()!!, (params["streamType"] as Number).toInt()))
}

override fun setRemoteDefaultVideoStreamType(params: Map<String, *>, callback: Callback) {
callback.code(this[params["channelId"] as String]?.setRemoteDefaultVideoStreamType((params["streamType"] as Number).toInt()))
}

override fun setRemoteUserPriority(params: Map<String, *>, callback: Callback) {
callback.code(this[params["channelId"] as String]?.setRemoteUserPriority((params["uid"] as Number).toInt(), (params["userPriority"] as Number).toInt()))
callback.code(this[params["channelId"] as String]?.setRemoteUserPriority(params["uid"]?.toSDKUInt()!!, (params["userPriority"] as Number).toInt()))
}

override fun registerMediaMetadataObserver(params: Map<String, *>, callback: Callback) {
Expand Down
32 changes: 16 additions & 16 deletions android/src/main/java/io/agora/rtc/base/RtcChannelEvent.kt
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,11 @@ class RtcChannelEventHandler(
}

override fun onJoinChannelSuccess(rtcChannel: RtcChannel?, uid: Int, elapsed: Int) {
callback(RtcChannelEvents.JoinChannelSuccess, rtcChannel, rtcChannel?.channelId(), uid, elapsed)
callback(RtcChannelEvents.JoinChannelSuccess, rtcChannel, rtcChannel?.channelId(), uid.toJSUInt(), elapsed)
}

override fun onRejoinChannelSuccess(rtcChannel: RtcChannel?, uid: Int, elapsed: Int) {
callback(RtcChannelEvents.RejoinChannelSuccess, rtcChannel, rtcChannel?.channelId(), uid, elapsed)
callback(RtcChannelEvents.RejoinChannelSuccess, rtcChannel, rtcChannel?.channelId(), uid.toJSUInt(), elapsed)
}

override fun onLeaveChannel(rtcChannel: RtcChannel?, stats: IRtcEngineEventHandler.RtcStats?) {
Expand All @@ -128,11 +128,11 @@ class RtcChannelEventHandler(
}

override fun onUserJoined(rtcChannel: RtcChannel?, uid: Int, elapsed: Int) {
callback(RtcChannelEvents.UserJoined, rtcChannel, uid, elapsed)
callback(RtcChannelEvents.UserJoined, rtcChannel, uid.toJSUInt(), elapsed)
}

override fun onUserOffline(rtcChannel: RtcChannel?, uid: Int, @Annotations.AgoraUserOfflineReason reason: Int) {
callback(RtcChannelEvents.UserOffline, rtcChannel, uid, reason)
callback(RtcChannelEvents.UserOffline, rtcChannel, uid.toJSUInt(), reason)
}

override fun onConnectionStateChanged(rtcChannel: RtcChannel?, @Annotations.AgoraConnectionStateType state: Int, @Annotations.AgoraConnectionChangedReason reason: Int) {
Expand All @@ -152,35 +152,35 @@ class RtcChannelEventHandler(
}

override fun onActiveSpeaker(rtcChannel: RtcChannel?, uid: Int) {
callback(RtcChannelEvents.ActiveSpeaker, rtcChannel, uid)
callback(RtcChannelEvents.ActiveSpeaker, rtcChannel, uid.toJSUInt())
}

override fun onVideoSizeChanged(rtcChannel: RtcChannel?, uid: Int, width: Int, height: Int, @IntRange(from = 0, to = 360) rotation: Int) {
callback(RtcChannelEvents.VideoSizeChanged, rtcChannel, uid, width, height, rotation)
callback(RtcChannelEvents.VideoSizeChanged, rtcChannel, uid.toJSUInt(), width, height, rotation)
}

override fun onRemoteVideoStateChanged(rtcChannel: RtcChannel?, uid: Int, @Annotations.AgoraVideoRemoteState state: Int, @Annotations.AgoraVideoRemoteStateReason reason: Int, elapsed: Int) {
callback(RtcChannelEvents.RemoteVideoStateChanged, rtcChannel, uid, state, reason, elapsed)
callback(RtcChannelEvents.RemoteVideoStateChanged, rtcChannel, uid.toJSUInt(), state, reason, elapsed)
}

override fun onRemoteAudioStateChanged(rtcChannel: RtcChannel?, uid: Int, @Annotations.AgoraAudioRemoteState state: Int, @Annotations.AgoraAudioRemoteStateReason reason: Int, elapsed: Int) {
callback(RtcChannelEvents.RemoteAudioStateChanged, rtcChannel, uid, state, reason, elapsed)
callback(RtcChannelEvents.RemoteAudioStateChanged, rtcChannel, uid.toJSUInt(), state, reason, elapsed)
}

override fun onLocalPublishFallbackToAudioOnly(rtcChannel: RtcChannel?, isFallbackOrRecover: Boolean) {
callback(RtcChannelEvents.LocalPublishFallbackToAudioOnly, rtcChannel, isFallbackOrRecover)
}

override fun onRemoteSubscribeFallbackToAudioOnly(rtcChannel: RtcChannel?, uid: Int, isFallbackOrRecover: Boolean) {
callback(RtcChannelEvents.RemoteSubscribeFallbackToAudioOnly, rtcChannel, uid, isFallbackOrRecover)
callback(RtcChannelEvents.RemoteSubscribeFallbackToAudioOnly, rtcChannel, uid.toJSUInt(), isFallbackOrRecover)
}

override fun onRtcStats(rtcChannel: RtcChannel?, stats: IRtcEngineEventHandler.RtcStats?) {
callback(RtcChannelEvents.RtcStats, rtcChannel, stats?.toMap())
}

override fun onNetworkQuality(rtcChannel: RtcChannel?, uid: Int, @Annotations.AgoraNetworkQuality txQuality: Int, @Annotations.AgoraNetworkQuality rxQuality: Int) {
callback(RtcChannelEvents.NetworkQuality, rtcChannel, uid, txQuality, rxQuality)
callback(RtcChannelEvents.NetworkQuality, rtcChannel, uid.toJSUInt(), txQuality, rxQuality)
}

override fun onRemoteVideoStats(rtcChannel: RtcChannel?, stats: IRtcEngineEventHandler.RemoteVideoStats?) {
Expand All @@ -200,15 +200,15 @@ class RtcChannelEventHandler(
}

override fun onStreamInjectedStatus(rtcChannel: RtcChannel?, url: String?, uid: Int, @Annotations.AgoraInjectStreamStatus status: Int) {
callback(RtcChannelEvents.StreamInjectedStatus, rtcChannel, url, uid, status)
callback(RtcChannelEvents.StreamInjectedStatus, rtcChannel, url, uid.toJSUInt(), status)
}

override fun onStreamMessage(rtcChannel: RtcChannel?, uid: Int, streamId: Int, data: ByteArray?) {
callback(RtcChannelEvents.StreamMessage, rtcChannel, uid, streamId, data?.let { String(it, Charsets.UTF_8) })
callback(RtcChannelEvents.StreamMessage, rtcChannel, uid.toJSUInt(), streamId, data?.let { String(it, Charsets.UTF_8) })
}

override fun onStreamMessageError(rtcChannel: RtcChannel?, uid: Int, streamId: Int, @Annotations.AgoraErrorCode error: Int, missed: Int, cached: Int) {
callback(RtcChannelEvents.StreamMessageError, rtcChannel, uid, streamId, error, missed, cached)
callback(RtcChannelEvents.StreamMessageError, rtcChannel, uid.toJSUInt(), streamId, error, missed, cached)
}

override fun onChannelMediaRelayStateChanged(rtcChannel: RtcChannel?, @Annotations.AgoraChannelMediaRelayState state: Int, @Annotations.AgoraChannelMediaRelayError code: Int) {
Expand All @@ -228,18 +228,18 @@ class RtcChannelEventHandler(
}

override fun onAudioSubscribeStateChanged(rtcChannel: RtcChannel?, uid: Int, @Annotations.AgoraStreamSubscribeState oldState: Int, @Annotations.AgoraStreamSubscribeState newState: Int, elapseSinceLastState: Int) {
callback(RtcChannelEvents.AudioSubscribeStateChanged, rtcChannel, rtcChannel?.channelId(), uid, oldState, newState, elapseSinceLastState)
callback(RtcChannelEvents.AudioSubscribeStateChanged, rtcChannel, rtcChannel?.channelId(), uid.toJSUInt(), oldState, newState, elapseSinceLastState)
}

override fun onVideoSubscribeStateChanged(rtcChannel: RtcChannel?, uid: Int, @Annotations.AgoraStreamSubscribeState oldState: Int, @Annotations.AgoraStreamSubscribeState newState: Int, elapseSinceLastState: Int) {
callback(RtcChannelEvents.VideoSubscribeStateChanged, rtcChannel, rtcChannel?.channelId(), uid, oldState, newState, elapseSinceLastState)
callback(RtcChannelEvents.VideoSubscribeStateChanged, rtcChannel, rtcChannel?.channelId(), uid.toJSUInt(), oldState, newState, elapseSinceLastState)
}

override fun onRtmpStreamingEvent(rtcChannel: RtcChannel?, url: String?, @Annotations.AgoraRtmpStreamingEvent errCode: Int) {
callback(RtcChannelEvents.RtmpStreamingEvent, rtcChannel, url, errCode)
}

override fun onUserSuperResolutionEnabled(rtcChannel: RtcChannel?, uid: Int, enabled: Boolean, @Annotations.AgoraSuperResolutionStateReason reason: Int) {
callback(RtcChannelEvents.UserSuperResolutionEnabled, rtcChannel, uid, enabled, reason)
callback(RtcChannelEvents.UserSuperResolutionEnabled, rtcChannel, uid.toJSUInt(), enabled, reason)
}
}
18 changes: 9 additions & 9 deletions android/src/main/java/io/agora/rtc/base/RtcEngine.kt
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ class RtcEngineManager(
val token = params["token"] as? String
val channelName = params["channelName"] as String
val optionalInfo = params["optionalInfo"] as? String
val optionalUid = (params["optionalUid"] as Number).toInt()
val optionalUid = params["optionalUid"]?.toSDKUInt()!!
(params["options"] as? Map<*, *>)?.let {
callback.code(engine?.joinChannel(token, channelName, optionalInfo, optionalUid, mapToChannelMediaOptions(it)))
return@joinChannel
Expand Down Expand Up @@ -523,7 +523,7 @@ class RtcEngineManager(
override fun getUserInfoByUid(params: Map<String, *>, callback: Callback) {
callback.resolve(engine) {
val userInfo = UserInfo()
it.getUserInfoByUid((params["uid"] as Number).toInt(), userInfo)
it.getUserInfoByUid(params["uid"]?.toSDKUInt()!!, userInfo)
userInfo.toMap()
}
}
Expand All @@ -545,7 +545,7 @@ class RtcEngineManager(
}

override fun adjustUserPlaybackSignalVolume(params: Map<String, *>, callback: Callback) {
callback.code(engine?.adjustUserPlaybackSignalVolume((params["uid"] as Number).toInt(), (params["volume"] as Number).toInt()))
callback.code(engine?.adjustUserPlaybackSignalVolume(params["uid"]?.toSDKUInt()!!, (params["volume"] as Number).toInt()))
}

override fun adjustPlaybackSignalVolume(params: Map<String, *>, callback: Callback) {
Expand All @@ -561,7 +561,7 @@ class RtcEngineManager(
}

override fun muteRemoteAudioStream(params: Map<String, *>, callback: Callback) {
callback.code(engine?.muteRemoteAudioStream((params["uid"] as Number).toInt(), params["muted"] as Boolean))
callback.code(engine?.muteRemoteAudioStream(params["uid"]?.toSDKUInt()!!, params["muted"] as Boolean))
}

override fun muteAllRemoteAudioStreams(params: Map<String, *>, callback: Callback) {
Expand Down Expand Up @@ -617,7 +617,7 @@ class RtcEngineManager(
}

override fun muteRemoteVideoStream(params: Map<String, *>, callback: Callback) {
callback.code(engine?.muteRemoteVideoStream((params["uid"] as Number).toInt(), params["muted"] as Boolean))
callback.code(engine?.muteRemoteVideoStream(params["uid"]?.toSDKUInt()!!, params["muted"] as Boolean))
}

override fun muteAllRemoteVideoStreams(params: Map<String, *>, callback: Callback) {
Expand All @@ -633,7 +633,7 @@ class RtcEngineManager(
}

override fun enableRemoteSuperResolution(params: Map<String, *>, callback: Callback) {
callback.code(engine?.enableRemoteSuperResolution((params["uid"] as Number).toInt(), params["enable"] as Boolean))
callback.code(engine?.enableRemoteSuperResolution(params["uid"]?.toSDKUInt()!!, params["enable"] as Boolean))
}

override fun startAudioMixing(params: Map<String, *>, callback: Callback) {
Expand Down Expand Up @@ -811,7 +811,7 @@ class RtcEngineManager(
}

override fun setRemoteVoicePosition(params: Map<String, *>, callback: Callback) {
callback.code(engine?.setRemoteVoicePosition((params["uid"] as Number).toInt(), (params["pan"] as Number).toDouble(), (params["gain"] as Number).toDouble()))
callback.code(engine?.setRemoteVoicePosition(params["uid"]?.toSDKUInt()!!, (params["pan"] as Number).toDouble(), (params["gain"] as Number).toDouble()))
}

override fun setLiveTranscoding(params: Map<String, *>, callback: Callback) {
Expand Down Expand Up @@ -863,7 +863,7 @@ class RtcEngineManager(
}

override fun setRemoteVideoStreamType(params: Map<String, *>, callback: Callback) {
callback.code(engine?.setRemoteVideoStreamType((params["uid"] as Number).toInt(), (params["streamType"] as Number).toInt()))
callback.code(engine?.setRemoteVideoStreamType(params["uid"]?.toSDKUInt()!!, (params["streamType"] as Number).toInt()))
}

override fun setRemoteDefaultVideoStreamType(params: Map<String, *>, callback: Callback) {
Expand All @@ -879,7 +879,7 @@ class RtcEngineManager(
}

override fun setRemoteUserPriority(params: Map<String, *>, callback: Callback) {
callback.code(engine?.setRemoteUserPriority((params["uid"] as Number).toInt(), (params["userPriority"] as Number).toInt()))
callback.code(engine?.setRemoteUserPriority(params["uid"]?.toSDKUInt()!!, (params["userPriority"] as Number).toInt()))
}

override fun startEchoTest(params: Map<String, *>, callback: Callback) {
Expand Down
Loading

0 comments on commit cdc9eae

Please sign in to comment.