From 19b9b1d5c9f6301c4115dffcd0049bb68950eb5d Mon Sep 17 00:00:00 2001 From: HUI Date: Mon, 17 May 2021 16:25:59 +0800 Subject: [PATCH] Squashed 'android/src/main/java/io/agora/rtc/base/' changes from 382f858..3aed6ce 3aed6ce fix: startAudioRecording bug 510b405 chore: optimize 4f801b9 chore: optimize ab71f52 chore: optimize startAudioRecording 07f81c7 chore: optimize 5a20e13 style: optimize 858b58f fix(uid compatible): int to uint 8d14d2d feat(upgrade): 3.4.1 be5efea Merge pull request #4 from AgoraLibrary/dev/3.3.0 git-subtree-dir: android/src/main/java/io/agora/rtc/base git-subtree-split: 3aed6cebfdd5dd14504e99c226a2c69b551effa3 --- Annotations.java | 23 ++- BeanCovertor.kt | 51 +++++-- Extensions.kt | 13 +- MediaObserver.kt | 8 +- RtcChannel.kt | 170 +++++++++++++++++---- RtcChannelEvent.kt | 330 ++++++++++++++++++++++++++++++++--------- RtcEngine.kt | 360 +++++++++++++++++++++++++++++++++++++++------ RtcEngineEvent.kt | 283 +++++++++++++++++++++++++++-------- RtcSurfaceView.kt | 7 +- RtcTextureView.kt | 7 +- 10 files changed, 1022 insertions(+), 230 deletions(-) diff --git a/Annotations.java b/Annotations.java index 784a30968..cc59812a8 100644 --- a/Annotations.java +++ b/Annotations.java @@ -98,19 +98,27 @@ public class Annotations { } @IntDef({ - Constants.MEDIA_ENGINE_AUDIO_ERROR_MIXING_OPEN, - Constants.MEDIA_ENGINE_AUDIO_ERROR_MIXING_TOO_FREQUENT, - Constants.MEDIA_ENGINE_AUDIO_EVENT_MIXING_INTERRUPTED_EOF, - AgoraAudioMixingErrorCode.MEDIA_ENGINE_AUDIO_ERROR_OK, - }) - @Retention(RetentionPolicy.SOURCE) - public @interface AgoraAudioMixingErrorCode { + Constants.AUDIO_MIXING_REASON_CAN_NOT_OPEN, + Constants.AUDIO_MIXING_REASON_TOO_FREQUENT_CALL, + Constants.AUDIO_MIXING_REASON_INTERRUPTED_EOF, + Constants.AUDIO_MIXING_REASON_STARTED_BY_USER, + Constants.AUDIO_MIXING_REASON_ONE_LOOP_COMPLETED, + Constants.AUDIO_MIXING_REASON_START_NEW_LOOP, + Constants.AUDIO_MIXING_REASON_ALL_LOOPS_COMPLETED, + Constants.AUDIO_MIXING_REASON_STOPPED_BY_USER, + Constants.AUDIO_MIXING_REASON_PAUSED_BY_USER, + Constants.AUDIO_MIXING_REASON_RESUMED_BY_USER, + AgoraAudioMixingReason.MEDIA_ENGINE_AUDIO_ERROR_OK, + }) + @Retention(RetentionPolicy.SOURCE) + public @interface AgoraAudioMixingReason { int MEDIA_ENGINE_AUDIO_ERROR_OK = 0; } @IntDef({ Constants.MEDIA_ENGINE_AUDIO_EVENT_MIXING_PLAY, Constants.MEDIA_ENGINE_AUDIO_EVENT_MIXING_PAUSED, + Constants.MEDIA_ENGINE_AUDIO_EVENT_MIXING_RESTART, Constants.MEDIA_ENGINE_AUDIO_EVENT_MIXING_STOPPED, Constants.MEDIA_ENGINE_AUDIO_EVENT_MIXING_ERROR, }) @@ -534,6 +542,7 @@ public class Annotations { Constants.LOCAL_VIDEO_STREAM_ERROR_DEVICE_BUSY, Constants.LOCAL_VIDEO_STREAM_ERROR_CAPTURE_FAILURE, Constants.LOCAL_VIDEO_STREAM_ERROR_ENCODE_FAILURE, + Constants.LOCAL_VIDEO_STREAM_ERROR_DEVICE_NOT_FOUND }) @Retention(RetentionPolicy.SOURCE) public @interface AgoraLocalVideoStreamError { diff --git a/BeanCovertor.kt b/BeanCovertor.kt index 3ae90efde..1ecc6f782 100644 --- a/BeanCovertor.kt +++ b/BeanCovertor.kt @@ -2,6 +2,8 @@ package io.agora.rtc.base import android.graphics.Color import io.agora.rtc.RtcEngineConfig +import io.agora.rtc.audio.AgoraRhythmPlayerConfig +import io.agora.rtc.audio.AudioRecordingConfiguration import io.agora.rtc.internal.EncryptionConfig import io.agora.rtc.internal.LastmileProbeConfig import io.agora.rtc.live.LiveInjectStreamConfig @@ -27,7 +29,9 @@ fun mapToVideoEncoderConfiguration(map: Map<*, *>): VideoEncoderConfiguration { (map["bitrate"] as? Number)?.let { bitrate = it.toInt() } (map["minBitrate"] as? Number)?.let { minBitrate = it.toInt() } (map["orientationMode"] as? Number)?.let { orientationMode = intToOrientationMode(it.toInt()) } - (map["degradationPrefer"] as? Number)?.let { degradationPrefer = intToDegradationPreference(it.toInt()) } + (map["degradationPrefer"] as? Number)?.let { + degradationPrefer = intToDegradationPreference(it.toInt()) + } (map["mirrorMode"] as? Number)?.let { mirrorMode = it.toInt() } } } @@ -53,7 +57,7 @@ fun mapToAgoraImage(map: Map<*, *>): AgoraImage { fun mapToTranscodingUser(map: Map<*, *>): TranscodingUser { return TranscodingUser().apply { - (map["uid"] as? Number)?.let { uid = it.toInt() } + (map["uid"] as? Number)?.let { uid = it.toNativeUInt() } (map["x"] as? Number)?.let { x = it.toInt() } (map["y"] as? Number)?.let { y = it.toInt() } (map["width"] as? Number)?.let { width = it.toInt() } @@ -82,11 +86,17 @@ fun mapToLiveTranscoding(map: Map<*, *>): LiveTranscoding { (map["videoGop"] as? Number)?.let { videoGop = it.toInt() } (map["watermark"] as? Map<*, *>)?.let { watermark = mapToAgoraImage(it) } (map["backgroundImage"] as? Map<*, *>)?.let { backgroundImage = mapToAgoraImage(it) } - (map["audioSampleRate"] as? Number)?.let { audioSampleRate = intToLiveTranscodingAudioSampleRate(it.toInt()) } + (map["audioSampleRate"] as? Number)?.let { + audioSampleRate = intToLiveTranscodingAudioSampleRate(it.toInt()) + } (map["audioBitrate"] as? Number)?.let { audioBitrate = it.toInt() } (map["audioChannels"] as? Number)?.let { audioChannels = it.toInt() } - (map["audioCodecProfile"] as? Number)?.let { audioCodecProfile = intToAudioCodecProfile(it.toInt()) } - (map["videoCodecProfile"] as? Number)?.let { videoCodecProfile = intToVideoCodecProfile(it.toInt()) } + (map["audioCodecProfile"] as? Number)?.let { + audioCodecProfile = intToAudioCodecProfile(it.toInt()) + } + (map["videoCodecProfile"] as? Number)?.let { + videoCodecProfile = intToVideoCodecProfile(it.toInt()) + } (map["backgroundColor"] as? Map<*, *>)?.let { backgroundColor = mapToColor(it) } (map["userConfigExtraInfo"] as? String)?.let { userConfigExtraInfo = it } (map["transcodingUsers"] as? List<*>)?.let { list -> @@ -103,7 +113,7 @@ fun mapToChannelMediaInfo(map: Map<*, *>): ChannelMediaInfo { return ChannelMediaInfo( map["channelName"] as? String, map["token"] as? String, - (map["uid"] as Number).toInt() + (map["uid"] as Number).toNativeUInt() ) } @@ -142,8 +152,12 @@ fun mapToRectangle(map: Map<*, *>): WatermarkOptions.Rectangle { fun mapToWatermarkOptions(map: Map<*, *>): WatermarkOptions { return WatermarkOptions().apply { (map["visibleInPreview"] as? Boolean)?.let { visibleInPreview = it } - (map["positionInLandscapeMode"] as? Map<*, *>)?.let { positionInLandscapeMode = mapToRectangle(it) } - (map["positionInPortraitMode"] as? Map<*, *>)?.let { positionInPortraitMode = mapToRectangle(it) } + (map["positionInLandscapeMode"] as? Map<*, *>)?.let { + positionInLandscapeMode = mapToRectangle(it) + } + (map["positionInPortraitMode"] as? Map<*, *>)?.let { + positionInPortraitMode = mapToRectangle(it) + } } } @@ -154,12 +168,22 @@ fun mapToLiveInjectStreamConfig(map: Map<*, *>): LiveInjectStreamConfig { (map["videoGop"] as? Number)?.let { videoGop = it.toInt() } (map["videoFramerate"] as? Number)?.let { videoFramerate = it.toInt() } (map["videoBitrate"] as? Number)?.let { videoBitrate = it.toInt() } - (map["audioSampleRate"] as? Number)?.let { audioSampleRate = intToLiveInjectStreamConfigAudioSampleRate(it.toInt()) } + (map["audioSampleRate"] as? Number)?.let { + audioSampleRate = intToLiveInjectStreamConfigAudioSampleRate(it.toInt()) + } (map["audioBitrate"] as? Number)?.let { audioBitrate = it.toInt() } (map["audioChannels"] as? Number)?.let { audioChannels = it.toInt() } } } +fun mapToRhythmPlayerConfig(map: Map<*, *>): AgoraRhythmPlayerConfig { + return AgoraRhythmPlayerConfig().apply { + (map["beatsPerMeasure"] as? Number)?.let { beatsPerMeasure = it.toInt() } + (map["beatsPerMinute"] as? Number)?.let { beatsPerMinute = it.toInt() } + (map["publish"] as? Boolean)?.let { publish = it } + } +} + fun mapToCameraCapturerConfiguration(map: Map<*, *>): CameraCapturerConfiguration { return CameraCapturerConfiguration( intToCapturerOutputPreference((map["preference"] as Number).toInt()), @@ -186,6 +210,15 @@ fun mapToRtcEngineConfig(map: Map<*, *>): RtcEngineConfig { } } +fun mapToAudioRecordingConfiguration(map: Map<*, *>): AudioRecordingConfiguration { + return AudioRecordingConfiguration().apply { + (map["filePath"] as? String)?.let { filePath = it } + (map["recordingQuality"] as? Number)?.let { recordingQuality = it.toInt() } + (map["recordingPosition"] as? Number)?.let { recordingPosition = it.toInt() } + (map["recordingQuality"] as? Number)?.let { recordingSampleRate = it.toInt() } + } +} + fun mapToEncryptionConfig(map: Map<*, *>): EncryptionConfig { return EncryptionConfig().apply { (map["encryptionMode"] as? Number)?.let { encryptionMode = intToEncryptionMode(it.toInt()) } diff --git a/Extensions.kt b/Extensions.kt index 147593fc0..d6a069a21 100644 --- a/Extensions.kt +++ b/Extensions.kt @@ -6,7 +6,7 @@ import io.agora.rtc.models.UserInfo fun UserInfo.toMap(): Map { return hashMapOf( - "uid" to uid, + "uid" to uid.toUInt().toLong(), "userAccount" to userAccount ) } @@ -59,7 +59,7 @@ fun Rect.toMap(): Map { fun RemoteAudioStats.toMap(): Map { return hashMapOf( - "uid" to uid, + "uid" to uid.toUInt().toLong(), "quality" to quality, "networkTransportDelay" to networkTransportDelay, "jitterBufferDelay" to jitterBufferDelay, @@ -99,7 +99,7 @@ fun LocalVideoStats.toMap(): Map { fun RemoteVideoStats.toMap(): Map { return hashMapOf( - "uid" to uid, + "uid" to uid.toUInt().toLong(), "delay" to delay, "width" to width, "height" to height, @@ -117,7 +117,7 @@ fun RemoteVideoStats.toMap(): Map { fun AudioVolumeInfo.toMap(): Map { return hashMapOf( - "uid" to uid, + "uid" to uid.toUInt().toLong(), "volume" to volume, "vad" to vad, "channelId" to channelId @@ -158,3 +158,8 @@ fun AgoraFacePositionInfo.toMap(): Map { fun Array.toMapList(): List> { return List(size) { this[it].toMap() } } + +@ExperimentalUnsignedTypes +internal fun Number.toNativeUInt(): Int { + return toLong().toUInt().toInt() +} diff --git a/MediaObserver.kt b/MediaObserver.kt index 21f3b20c3..b763cedeb 100644 --- a/MediaObserver.kt +++ b/MediaObserver.kt @@ -31,8 +31,10 @@ class MediaObserver( } override fun onMetadataReceived(buffer: ByteArray, uid: Int, timeStampMs: Long) { - emit(hashMapOf( - "data" to arrayListOf(String(buffer), uid, timeStampMs) - )) + emit( + hashMapOf( + "data" to arrayListOf(String(buffer), uid.toUInt().toLong(), timeStampMs) + ) + ) } } diff --git a/RtcChannel.kt b/RtcChannel.kt index 461a9bda7..49d5e789d 100644 --- a/RtcChannel.kt +++ b/RtcChannel.kt @@ -138,7 +138,12 @@ class RtcChannelManager( override fun create(params: Map, callback: Callback) { callback.resolve(params["engine"] as RtcEngine) { e -> e.createRtcChannel(params["channelId"] as String)?.let { - it.setRtcChannelEventHandler(RtcChannelEventHandler { methodName, data -> emit(methodName, data) }) + it.setRtcChannelEventHandler(RtcChannelEventHandler { methodName, data -> + emit( + methodName, + data + ) + }) rtcChannelMap[it.channelId()] = it } Unit @@ -152,18 +157,36 @@ class RtcChannelManager( override fun setClientRole(params: Map, callback: Callback) { val role = (params["role"] as Number).toInt() (params["options"] as? Map<*, *>)?.let { - callback.code(this[params["channelId"] as String]?.setClientRole(role, mapToClientRoleOptions(it))) + callback.code( + this[params["channelId"] as String]?.setClientRole( + role, + mapToClientRoleOptions(it) + ) + ) return@setClientRole } callback.code(this[params["channelId"] as String]?.setClientRole(role)) } override fun joinChannel(params: Map, 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"] as Number).toNativeUInt(), + mapToChannelMediaOptions(params["options"] as Map<*, *>) + ) + ) } override fun joinChannelWithUserAccount(params: Map, callback: Callback) { - callback.code(this[params["channelId"] as String]?.joinChannelWithUserAccount(params["token"] as? String, params["userAccount"] as String, mapToChannelMediaOptions(params["options"] as Map<*, *>))) + callback.code( + this[params["channelId"] as String]?.joinChannelWithUserAccount( + params["token"] as? String, + params["userAccount"] as String, + mapToChannelMediaOptions(params["options"] as Map<*, *>) + ) + ) } override fun leaveChannel(params: Map, callback: Callback) { @@ -191,11 +214,21 @@ class RtcChannelManager( } override fun adjustUserPlaybackSignalVolume(params: Map, 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"] as Number).toNativeUInt(), + (params["volume"] as Number).toInt() + ) + ) } override fun muteRemoteAudioStream(params: Map, 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"] as Number).toNativeUInt(), + params["muted"] as Boolean + ) + ) } override fun muteAllRemoteAudioStreams(params: Map, callback: Callback) { @@ -207,7 +240,12 @@ class RtcChannelManager( } override fun muteRemoteVideoStream(params: Map, 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"] as Number).toNativeUInt(), + params["muted"] as Boolean + ) + ) } override fun muteAllRemoteVideoStreams(params: Map, callback: Callback) { @@ -219,19 +257,41 @@ class RtcChannelManager( } override fun enableRemoteSuperResolution(params: Map, 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"] as Number).toNativeUInt(), + params["enable"] as Boolean + ) + ) } override fun setRemoteVoicePosition(params: Map, 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"] as Number).toNativeUInt(), + (params["pan"] as Number).toDouble(), + (params["gain"] as Number).toDouble() + ) + ) } override fun setLiveTranscoding(params: Map, callback: Callback) { - callback.code(this[params["channelId"] as String]?.setLiveTranscoding(mapToLiveTranscoding(params["transcoding"] as Map<*, *>))) + callback.code( + this[params["channelId"] as String]?.setLiveTranscoding( + mapToLiveTranscoding( + params["transcoding"] as Map<*, *> + ) + ) + ) } override fun addPublishStreamUrl(params: Map, callback: Callback) { - callback.code(this[params["channelId"] as String]?.addPublishStreamUrl(params["url"] as String, params["transcodingEnabled"] as Boolean)) + callback.code( + this[params["channelId"] as String]?.addPublishStreamUrl( + params["url"] as String, + params["transcodingEnabled"] as Boolean + ) + ) } override fun removePublishStreamUrl(params: Map, callback: Callback) { @@ -239,11 +299,19 @@ class RtcChannelManager( } override fun startChannelMediaRelay(params: Map, callback: Callback) { - callback.code(this[params["channelId"] as String]?.startChannelMediaRelay(mapToChannelMediaRelayConfiguration(params["channelMediaRelayConfiguration"] as Map<*, *>))) + callback.code( + this[params["channelId"] as String]?.startChannelMediaRelay( + mapToChannelMediaRelayConfiguration(params["channelMediaRelayConfiguration"] as Map<*, *>) + ) + ) } override fun updateChannelMediaRelay(params: Map, callback: Callback) { - callback.code(this[params["channelId"] as String]?.updateChannelMediaRelay(mapToChannelMediaRelayConfiguration(params["channelMediaRelayConfiguration"] as Map<*, *>))) + callback.code( + this[params["channelId"] as String]?.updateChannelMediaRelay( + mapToChannelMediaRelayConfiguration(params["channelMediaRelayConfiguration"] as Map<*, *>) + ) + ) } override fun stopChannelMediaRelay(params: Map, callback: Callback) { @@ -251,7 +319,12 @@ class RtcChannelManager( } override fun setRemoteVideoStreamType(params: Map, 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"] as Number).toNativeUInt(), + (params["streamType"] as Number).toInt() + ) + ) } override fun setRemoteDefaultVideoStreamType(params: Map, callback: Callback) { @@ -259,15 +332,27 @@ class RtcChannelManager( } override fun setRemoteUserPriority(params: Map, 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"] as Number).toNativeUInt(), + (params["userPriority"] as Number).toInt() + ) + ) } override fun registerMediaMetadataObserver(params: Map, callback: Callback) { val channelId = params["channelId"] as String val mediaObserver = MediaObserver { data -> - emit(RtcChannelEvents.MetadataReceived, data?.toMutableMap()?.apply { put("channelId", channelId) }) + emit( + RtcChannelEvents.MetadataReceived, + data?.toMutableMap()?.apply { put("channelId", channelId) }) } - callback.code(this[channelId]?.registerMediaMetadataObserver(mediaObserver, IMetadataObserver.VIDEO_METADATA)) { + callback.code( + this[channelId]?.registerMediaMetadataObserver( + mediaObserver, + IMetadataObserver.VIDEO_METADATA + ) + ) { mediaObserverMap[channelId] = mediaObserver Unit } @@ -275,7 +360,12 @@ class RtcChannelManager( override fun unregisterMediaMetadataObserver(params: Map, callback: Callback) { val channelId = params["channelId"] as String - callback.code(this[channelId]?.registerMediaMetadataObserver(null, IMetadataObserver.VIDEO_METADATA)) { + callback.code( + this[channelId]?.registerMediaMetadataObserver( + null, + IMetadataObserver.VIDEO_METADATA + ) + ) { mediaObserverMap.remove(channelId) Unit } @@ -300,20 +390,34 @@ class RtcChannelManager( } override fun setEncryptionMode(params: Map, callback: Callback) { - callback.code(this[params["channelId"] as String]?.setEncryptionMode(when ((params["encryptionMode"] as Number).toInt()) { - EncryptionConfig.EncryptionMode.AES_128_XTS.value -> "aes-128-xts" - EncryptionConfig.EncryptionMode.AES_128_ECB.value -> "aes-128-ecb" - EncryptionConfig.EncryptionMode.AES_256_XTS.value -> "aes-256-xts" - else -> "" - })) + callback.code( + this[params["channelId"] as String]?.setEncryptionMode( + when ((params["encryptionMode"] as Number).toInt()) { + EncryptionConfig.EncryptionMode.AES_128_XTS.value -> "aes-128-xts" + EncryptionConfig.EncryptionMode.AES_128_ECB.value -> "aes-128-ecb" + EncryptionConfig.EncryptionMode.AES_256_XTS.value -> "aes-256-xts" + else -> "" + } + ) + ) } override fun enableEncryption(params: Map, callback: Callback) { - callback.code(this[params["channelId"] as String]?.enableEncryption(params["enabled"] as Boolean, mapToEncryptionConfig(params["config"] as Map<*, *>))) + callback.code( + this[params["channelId"] as String]?.enableEncryption( + params["enabled"] as Boolean, + mapToEncryptionConfig(params["config"] as Map<*, *>) + ) + ) } override fun addInjectStreamUrl(params: Map, callback: Callback) { - callback.code(this[params["channelId"] as String]?.addInjectStreamUrl(params["url"] as String, mapToLiveInjectStreamConfig(params["config"] as Map<*, *>))) + callback.code( + this[params["channelId"] as String]?.addInjectStreamUrl( + params["url"] as String, + mapToLiveInjectStreamConfig(params["config"] as Map<*, *>) + ) + ) } override fun removeInjectStreamUrl(params: Map, callback: Callback) { @@ -326,10 +430,20 @@ class RtcChannelManager( callback.code(channel?.createDataStream(mapToDataStreamConfig(config))) { it } return@createDataStream } - callback.code(channel?.createDataStream(params["reliable"] as Boolean, params["ordered"] as Boolean)) { it } + callback.code( + channel?.createDataStream( + params["reliable"] as Boolean, + params["ordered"] as Boolean + ) + ) { it } } override fun sendStreamMessage(params: Map, callback: Callback) { - callback.code(this[params["channelId"] as String]?.sendStreamMessage((params["streamId"] as Number).toInt(), (params["message"] as String).toByteArray())) + callback.code( + this[params["channelId"] as String]?.sendStreamMessage( + (params["streamId"] as Number).toInt(), + (params["message"] as String).toByteArray() + ) + ) } } diff --git a/RtcChannelEvent.kt b/RtcChannelEvent.kt index 71ff02ae9..83bc3990c 100644 --- a/RtcChannelEvent.kt +++ b/RtcChannelEvent.kt @@ -96,10 +96,12 @@ class RtcChannelEventHandler( private fun callback(methodName: String, channel: RtcChannel?, vararg data: Any?) { channel?.let { - emitter(methodName, hashMapOf( - "channelId" to it.channelId(), - "data" to data.toList() - )) + emitter( + methodName, hashMapOf( + "channelId" to it.channelId(), + "data" to data.toList() + ) + ) } } @@ -112,30 +114,54 @@ 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.toUInt().toLong(), + 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.toUInt().toLong(), + elapsed + ) } override fun onLeaveChannel(rtcChannel: RtcChannel?, stats: IRtcEngineEventHandler.RtcStats?) { callback(RtcChannelEvents.LeaveChannel, rtcChannel, stats?.toMap()) } - override fun onClientRoleChanged(rtcChannel: RtcChannel?, @Annotations.AgoraClientRole oldRole: Int, @Annotations.AgoraClientRole newRole: Int) { + override fun onClientRoleChanged( + rtcChannel: RtcChannel?, + @Annotations.AgoraClientRole oldRole: Int, + @Annotations.AgoraClientRole newRole: Int + ) { callback(RtcChannelEvents.ClientRoleChanged, rtcChannel, oldRole, newRole) } override fun onUserJoined(rtcChannel: RtcChannel?, uid: Int, elapsed: Int) { - callback(RtcChannelEvents.UserJoined, rtcChannel, uid, elapsed) + callback(RtcChannelEvents.UserJoined, rtcChannel, uid.toUInt().toLong(), elapsed) } - override fun onUserOffline(rtcChannel: RtcChannel?, uid: Int, @Annotations.AgoraUserOfflineReason reason: Int) { - callback(RtcChannelEvents.UserOffline, rtcChannel, uid, reason) + override fun onUserOffline( + rtcChannel: RtcChannel?, + uid: Int, + @Annotations.AgoraUserOfflineReason reason: Int + ) { + callback(RtcChannelEvents.UserOffline, rtcChannel, uid.toUInt().toLong(), reason) } - override fun onConnectionStateChanged(rtcChannel: RtcChannel?, @Annotations.AgoraConnectionStateType state: Int, @Annotations.AgoraConnectionChangedReason reason: Int) { + override fun onConnectionStateChanged( + rtcChannel: RtcChannel?, + @Annotations.AgoraConnectionStateType state: Int, + @Annotations.AgoraConnectionChangedReason reason: Int + ) { callback(RtcChannelEvents.ConnectionStateChanged, rtcChannel, state, reason) } @@ -152,46 +178,119 @@ class RtcChannelEventHandler( } override fun onActiveSpeaker(rtcChannel: RtcChannel?, uid: Int) { - callback(RtcChannelEvents.ActiveSpeaker, rtcChannel, uid) - } - - 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) - } - - 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) - } - - 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) - } - - override fun onLocalPublishFallbackToAudioOnly(rtcChannel: RtcChannel?, isFallbackOrRecover: Boolean) { + callback(RtcChannelEvents.ActiveSpeaker, rtcChannel, uid.toUInt().toLong()) + } + + override fun onVideoSizeChanged( + rtcChannel: RtcChannel?, + uid: Int, + width: Int, + height: Int, + @IntRange(from = 0, to = 360) rotation: Int + ) { + callback( + RtcChannelEvents.VideoSizeChanged, + rtcChannel, + uid.toUInt().toLong(), + 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.toUInt().toLong(), + 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.toUInt().toLong(), + 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) + override fun onRemoteSubscribeFallbackToAudioOnly( + rtcChannel: RtcChannel?, + uid: Int, + isFallbackOrRecover: Boolean + ) { + callback( + RtcChannelEvents.RemoteSubscribeFallbackToAudioOnly, + rtcChannel, + uid.toUInt().toLong(), + 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) - } - - override fun onRemoteVideoStats(rtcChannel: RtcChannel?, stats: IRtcEngineEventHandler.RemoteVideoStats?) { + override fun onNetworkQuality( + rtcChannel: RtcChannel?, + uid: Int, + @Annotations.AgoraNetworkQuality txQuality: Int, + @Annotations.AgoraNetworkQuality rxQuality: Int + ) { + callback( + RtcChannelEvents.NetworkQuality, + rtcChannel, + uid.toUInt().toLong(), + txQuality, + rxQuality + ) + } + + override fun onRemoteVideoStats( + rtcChannel: RtcChannel?, + stats: IRtcEngineEventHandler.RemoteVideoStats? + ) { callback(RtcChannelEvents.RemoteVideoStats, rtcChannel, stats?.toMap()) } - override fun onRemoteAudioStats(rtcChannel: RtcChannel?, stats: IRtcEngineEventHandler.RemoteAudioStats?) { + override fun onRemoteAudioStats( + rtcChannel: RtcChannel?, + stats: IRtcEngineEventHandler.RemoteAudioStats? + ) { callback(RtcChannelEvents.RemoteAudioStats, rtcChannel, stats?.toMap()) } - override fun onRtmpStreamingStateChanged(rtcChannel: RtcChannel?, url: String?, @Annotations.AgoraRtmpStreamingState state: Int, @Annotations.AgoraRtmpStreamingErrorCode errCode: Int) { + override fun onRtmpStreamingStateChanged( + rtcChannel: RtcChannel?, + url: String?, + @Annotations.AgoraRtmpStreamingState state: Int, + @Annotations.AgoraRtmpStreamingErrorCode errCode: Int + ) { callback(RtcChannelEvents.RtmpStreamingStateChanged, rtcChannel, url, state, errCode) } @@ -199,47 +298,146 @@ class RtcChannelEventHandler( callback(RtcChannelEvents.TranscodingUpdated, rtcChannel) } - override fun onStreamInjectedStatus(rtcChannel: RtcChannel?, url: String?, uid: Int, @Annotations.AgoraInjectStreamStatus status: Int) { - callback(RtcChannelEvents.StreamInjectedStatus, rtcChannel, url, uid, status) + override fun onStreamInjectedStatus( + rtcChannel: RtcChannel?, + url: String?, + uid: Int, + @Annotations.AgoraInjectStreamStatus status: Int + ) { + callback(RtcChannelEvents.StreamInjectedStatus, rtcChannel, url, uid.toUInt().toLong(), 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) }) - } - - 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) - } - - override fun onChannelMediaRelayStateChanged(rtcChannel: RtcChannel?, @Annotations.AgoraChannelMediaRelayState state: Int, @Annotations.AgoraChannelMediaRelayError code: Int) { + callback( + RtcChannelEvents.StreamMessage, + rtcChannel, + uid.toUInt().toLong(), + 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.toUInt().toLong(), + streamId, + error, + missed, + cached + ) + } + + override fun onChannelMediaRelayStateChanged( + rtcChannel: RtcChannel?, + @Annotations.AgoraChannelMediaRelayState state: Int, + @Annotations.AgoraChannelMediaRelayError code: Int + ) { callback(RtcChannelEvents.ChannelMediaRelayStateChanged, rtcChannel, state, code) } - override fun onChannelMediaRelayEvent(rtcChannel: RtcChannel?, @Annotations.AgoraChannelMediaRelayEvent code: Int) { + override fun onChannelMediaRelayEvent( + rtcChannel: RtcChannel?, + @Annotations.AgoraChannelMediaRelayEvent code: Int + ) { callback(RtcChannelEvents.ChannelMediaRelayEvent, rtcChannel, code) } - override fun onAudioPublishStateChanged(rtcChannel: RtcChannel?, @Annotations.AgoraStreamPublishState oldState: Int, @Annotations.AgoraStreamPublishState newState: Int, elapseSinceLastState: Int) { - callback(RtcChannelEvents.AudioPublishStateChanged, rtcChannel, rtcChannel?.channelId(), oldState, newState, elapseSinceLastState) - } - - override fun onVideoPublishStateChanged(rtcChannel: RtcChannel?, @Annotations.AgoraStreamPublishState oldState: Int, @Annotations.AgoraStreamPublishState newState: Int, elapseSinceLastState: Int) { - callback(RtcChannelEvents.VideoPublishStateChanged, rtcChannel, rtcChannel?.channelId(), oldState, newState, elapseSinceLastState) - } - - 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) - } - - 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) - } - - override fun onRtmpStreamingEvent(rtcChannel: RtcChannel?, url: String?, @Annotations.AgoraRtmpStreamingEvent errCode: Int) { + override fun onAudioPublishStateChanged( + rtcChannel: RtcChannel?, + @Annotations.AgoraStreamPublishState oldState: Int, + @Annotations.AgoraStreamPublishState newState: Int, + elapseSinceLastState: Int + ) { + callback( + RtcChannelEvents.AudioPublishStateChanged, + rtcChannel, + rtcChannel?.channelId(), + oldState, + newState, + elapseSinceLastState + ) + } + + override fun onVideoPublishStateChanged( + rtcChannel: RtcChannel?, + @Annotations.AgoraStreamPublishState oldState: Int, + @Annotations.AgoraStreamPublishState newState: Int, + elapseSinceLastState: Int + ) { + callback( + RtcChannelEvents.VideoPublishStateChanged, + rtcChannel, + rtcChannel?.channelId(), + oldState, + newState, + elapseSinceLastState + ) + } + + override fun onAudioSubscribeStateChanged( + rtcChannel: RtcChannel?, + uid: Int, + @Annotations.AgoraStreamSubscribeState oldState: Int, + @Annotations.AgoraStreamSubscribeState newState: Int, + elapseSinceLastState: Int + ) { + callback( + RtcChannelEvents.AudioSubscribeStateChanged, + rtcChannel, + rtcChannel?.channelId(), + uid.toUInt().toLong(), + 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.toUInt().toLong(), + 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) + override fun onUserSuperResolutionEnabled( + rtcChannel: RtcChannel?, + uid: Int, + enabled: Boolean, + @Annotations.AgoraSuperResolutionStateReason reason: Int + ) { + callback( + RtcChannelEvents.UserSuperResolutionEnabled, + rtcChannel, + uid.toUInt().toLong(), + enabled, + reason + ) } } diff --git a/RtcEngine.kt b/RtcEngine.kt index c245fd2bb..1c649e43c 100644 --- a/RtcEngine.kt +++ b/RtcEngine.kt @@ -101,6 +101,12 @@ class IRtcEngine { fun setDefaultMuteAllRemoteAudioStreams(params: Map, callback: Callback) fun enableAudioVolumeIndication(params: Map, callback: Callback) + + fun startRhythmPlayer(params: Map, callback: Callback) + + fun stopRhythmPlayer(callback: Callback) + + fun configRhythmPlayer(params: Map, callback: Callback) } interface RtcVideoInterface { @@ -149,7 +155,7 @@ class IRtcEngine { fun getAudioMixingPublishVolume(callback: Callback) - fun getAudioMixingDuration(callback: Callback) + fun getAudioMixingDuration(params: Map, callback: Callback) fun getAudioMixingCurrentPosition(callback: Callback) @@ -167,6 +173,12 @@ class IRtcEngine { fun playEffect(params: Map, callback: Callback) + fun setEffectPosition(params: Map, callback: Callback) + + fun getEffectDuration(params: Map, callback: Callback) + + fun getEffectCurrentPosition(params: Map, callback: Callback) + fun stopEffect(params: Map, callback: Callback) fun stopAllEffects(callback: Callback) @@ -395,9 +407,17 @@ 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"] as Number).toNativeUInt() (params["options"] as? Map<*, *>)?.let { - callback.code(engine?.joinChannel(token, channelName, optionalInfo, optionalUid, mapToChannelMediaOptions(it))) + callback.code( + engine?.joinChannel( + token, + channelName, + optionalInfo, + optionalUid, + mapToChannelMediaOptions(it) + ) + ) return@joinChannel } callback.code(engine?.joinChannel(token, channelName, optionalInfo, optionalUid)) @@ -430,7 +450,15 @@ class RtcEngineManager( } override fun sendCustomReportMessage(params: Map, callback: Callback) { - callback.code(engine?.sendCustomReportMessage(params["id"] as String, params["category"] as String, params["event"] as String, params["label"] as String, (params["value"] as Number).toInt())) + callback.code( + engine?.sendCustomReportMessage( + params["id"] as String, + params["category"] as String, + params["event"] as String, + params["label"] as String, + (params["value"] as Number).toInt() + ) + ) } override fun getCallId(callback: Callback) { @@ -438,7 +466,13 @@ class RtcEngineManager( } override fun rate(params: Map, callback: Callback) { - callback.code(engine?.rate(params["callId"] as String, (params["rating"] as Number).toInt(), params["description"] as? String)) + callback.code( + engine?.rate( + params["callId"] as String, + (params["rating"] as Number).toInt(), + params["description"] as? String + ) + ) } override fun complain(params: Map, callback: Callback) { @@ -486,7 +520,12 @@ class RtcEngineManager( } override fun registerLocalUserAccount(params: Map, callback: Callback) { - callback.code(engine?.registerLocalUserAccount(params["appId"] as String, params["userAccount"] as String)) + callback.code( + engine?.registerLocalUserAccount( + params["appId"] as String, + params["userAccount"] as String + ) + ) } override fun joinChannelWithUserAccount(params: Map, callback: Callback) { @@ -494,7 +533,14 @@ class RtcEngineManager( val channelName = params["channelName"] as String val userAccount = params["userAccount"] as String (params["options"] as? Map<*, *>)?.let { - callback.code(engine?.joinChannelWithUserAccount(token, channelName, userAccount, mapToChannelMediaOptions(it))) + callback.code( + engine?.joinChannelWithUserAccount( + token, + channelName, + userAccount, + mapToChannelMediaOptions(it) + ) + ) return@joinChannelWithUserAccount } callback.code(engine?.joinChannelWithUserAccount(token, channelName, userAccount)) @@ -511,7 +557,7 @@ class RtcEngineManager( override fun getUserInfoByUid(params: Map, callback: Callback) { callback.resolve(engine) { val userInfo = UserInfo() - it.getUserInfoByUid((params["uid"] as Number).toInt(), userInfo) + it.getUserInfoByUid((params["uid"] as Number).toNativeUInt(), userInfo) userInfo.toMap() } } @@ -525,7 +571,12 @@ class RtcEngineManager( } override fun setAudioProfile(params: Map, callback: Callback) { - callback.code(engine?.setAudioProfile((params["profile"] as Number).toInt(), (params["scenario"] as Number).toInt())) + callback.code( + engine?.setAudioProfile( + (params["profile"] as Number).toInt(), + (params["scenario"] as Number).toInt() + ) + ) } override fun adjustRecordingSignalVolume(params: Map, callback: Callback) { @@ -533,7 +584,12 @@ class RtcEngineManager( } override fun adjustUserPlaybackSignalVolume(params: Map, callback: Callback) { - callback.code(engine?.adjustUserPlaybackSignalVolume((params["uid"] as Number).toInt(), (params["volume"] as Number).toInt())) + callback.code( + engine?.adjustUserPlaybackSignalVolume( + (params["uid"] as Number).toNativeUInt(), + (params["volume"] as Number).toInt() + ) + ) } override fun adjustPlaybackSignalVolume(params: Map, callback: Callback) { @@ -549,7 +605,12 @@ class RtcEngineManager( } override fun muteRemoteAudioStream(params: Map, callback: Callback) { - callback.code(engine?.muteRemoteAudioStream((params["uid"] as Number).toInt(), params["muted"] as Boolean)) + callback.code( + engine?.muteRemoteAudioStream( + (params["uid"] as Number).toNativeUInt(), + params["muted"] as Boolean + ) + ) } override fun muteAllRemoteAudioStreams(params: Map, callback: Callback) { @@ -561,7 +622,31 @@ class RtcEngineManager( } override fun enableAudioVolumeIndication(params: Map, callback: Callback) { - callback.code(engine?.enableAudioVolumeIndication((params["interval"] as Number).toInt(), (params["smooth"] as Number).toInt(), params["report_vad"] as Boolean)) + callback.code( + engine?.enableAudioVolumeIndication( + (params["interval"] as Number).toInt(), + (params["smooth"] as Number).toInt(), + params["report_vad"] as Boolean + ) + ) + } + + override fun startRhythmPlayer(params: Map, callback: Callback) { + callback.code( + engine?.audioEffectManager?.startRhythmPlayer( + params["sound1"] as String, + params["sound2"] as String, + mapToRhythmPlayerConfig(params["config"] as Map<*, *>) + ) + ) + } + + override fun stopRhythmPlayer(callback: Callback) { + callback.code(engine?.audioEffectManager?.stopRhythmPlayer()) + } + + override fun configRhythmPlayer(params: Map, callback: Callback) { + callback.code(engine?.audioEffectManager?.configRhythmPlayer(mapToRhythmPlayerConfig(params as Map<*, *>))) } override fun enableVideo(callback: Callback) { @@ -593,7 +678,12 @@ class RtcEngineManager( } override fun muteRemoteVideoStream(params: Map, callback: Callback) { - callback.code(engine?.muteRemoteVideoStream((params["uid"] as Number).toInt(), params["muted"] as Boolean)) + callback.code( + engine?.muteRemoteVideoStream( + (params["uid"] as Number).toNativeUInt(), + params["muted"] as Boolean + ) + ) } override fun muteAllRemoteVideoStreams(params: Map, callback: Callback) { @@ -605,15 +695,44 @@ class RtcEngineManager( } override fun setBeautyEffectOptions(params: Map, callback: Callback) { - callback.code(engine?.setBeautyEffectOptions(params["enabled"] as Boolean, mapToBeautyOptions(params["options"] as Map<*, *>))) + callback.code( + engine?.setBeautyEffectOptions( + params["enabled"] as Boolean, + mapToBeautyOptions(params["options"] as Map<*, *>) + ) + ) } override fun enableRemoteSuperResolution(params: Map, callback: Callback) { - callback.code(engine?.enableRemoteSuperResolution((params["uid"] as Number).toInt(), params["enable"] as Boolean)) + callback.code( + engine?.enableRemoteSuperResolution( + (params["uid"] as Number).toNativeUInt(), + params["enable"] as Boolean + ) + ) } override fun startAudioMixing(params: Map, callback: Callback) { - callback.code(engine?.startAudioMixing(params["filePath"] as String, params["loopback"] as Boolean, params["replace"] as Boolean, (params["cycle"] as Number).toInt())) + (params["startPos"] as? Number)?.let { startPos -> + callback.code( + engine?.startAudioMixing( + params["filePath"] as String, + params["loopback"] as Boolean, + params["replace"] as Boolean, + (params["cycle"] as Number).toInt(), + startPos.toInt() + ) + ) + return@startAudioMixing + } + callback.code( + engine?.startAudioMixing( + params["filePath"] as String, + params["loopback"] as Boolean, + params["replace"] as Boolean, + (params["cycle"] as Number).toInt() + ) + ) } override fun stopAudioMixing(callback: Callback) { @@ -648,7 +767,11 @@ class RtcEngineManager( callback.code(engine?.audioMixingPublishVolume) { it } } - override fun getAudioMixingDuration(callback: Callback) { + override fun getAudioMixingDuration(params: Map, callback: Callback) { + (params["filePath"] as? String)?.let { file -> + callback.code(engine?.getAudioMixingDuration(file)) { it } + return@getAudioMixingDuration + } callback.code(engine?.audioMixingDuration) { it } } @@ -673,11 +796,60 @@ class RtcEngineManager( } override fun setVolumeOfEffect(params: Map, callback: Callback) { - callback.code(engine?.audioEffectManager?.setVolumeOfEffect((params["soundId"] as Number).toInt(), (params["volume"] as Number).toDouble())) + callback.code( + engine?.audioEffectManager?.setVolumeOfEffect( + (params["soundId"] as Number).toInt(), + (params["volume"] as Number).toDouble() + ) + ) } override fun playEffect(params: Map, callback: Callback) { - callback.code(engine?.audioEffectManager?.playEffect((params["soundId"] as Number).toInt(), params["filePath"] as String, (params["loopCount"] as Number).toInt(), (params["pitch"] as Number).toDouble(), (params["pan"] as Number).toDouble(), (params["gain"] as Number).toDouble(), params["publish"] as Boolean)) + (params["startPos"] as? Number)?.let { startPos -> + callback.code( + engine?.audioEffectManager?.playEffect( + (params["soundId"] as Number).toInt(), + params["filePath"] as String, + (params["loopCount"] as Number).toInt(), + (params["pitch"] as Number).toDouble(), + (params["pan"] as Number).toDouble(), + (params["gain"] as Number).toDouble(), + params["publish"] as Boolean, + startPos.toInt() + ) + ) + return@playEffect + } + callback.code( + engine?.audioEffectManager?.playEffect( + (params["soundId"] as Number).toInt(), + params["filePath"] as String, + (params["loopCount"] as Number).toInt(), + (params["pitch"] as Number).toDouble(), + (params["pan"] as Number).toDouble(), + (params["gain"] as Number).toDouble(), + params["publish"] as Boolean + ) + ) + } + + override fun setEffectPosition(params: Map, callback: Callback) { + callback.code( + engine?.audioEffectManager?.setEffectPosition( + (params["soundId"] as Number).toInt(), + (params["pos"] as Number).toInt() + ) + ) + } + + override fun getEffectDuration(params: Map, callback: Callback) { + callback.code(engine?.audioEffectManager?.getEffectDuration(params["filePath"] as String)) { + it + } + } + + override fun getEffectCurrentPosition(params: Map, callback: Callback) { + callback.code(engine?.audioEffectManager?.getEffectCurrentPosition((params["soundId"] as Number).toInt())) { it } } override fun stopEffect(params: Map, callback: Callback) { @@ -689,7 +861,12 @@ class RtcEngineManager( } override fun preloadEffect(params: Map, callback: Callback) { - callback.code(engine?.audioEffectManager?.preloadEffect((params["soundId"] as Number).toInt(), params["filePath"] as String)) + callback.code( + engine?.audioEffectManager?.preloadEffect( + (params["soundId"] as Number).toInt(), + params["filePath"] as String + ) + ) } override fun unloadEffect(params: Map, callback: Callback) { @@ -729,11 +906,21 @@ class RtcEngineManager( } override fun setLocalVoiceEqualization(params: Map, callback: Callback) { - callback.code(engine?.setLocalVoiceEqualization((params["bandFrequency"] as Number).toInt(), (params["bandGain"] as Number).toInt())) + callback.code( + engine?.setLocalVoiceEqualization( + (params["bandFrequency"] as Number).toInt(), + (params["bandGain"] as Number).toInt() + ) + ) } override fun setLocalVoiceReverb(params: Map, callback: Callback) { - callback.code(engine?.setLocalVoiceReverb((params["reverbKey"] as Number).toInt(), (params["value"] as Number).toInt())) + callback.code( + engine?.setLocalVoiceReverb( + (params["reverbKey"] as Number).toInt(), + (params["value"] as Number).toInt() + ) + ) } override fun setAudioEffectPreset(params: Map, callback: Callback) { @@ -749,11 +936,23 @@ class RtcEngineManager( } override fun setAudioEffectParameters(params: Map, callback: Callback) { - callback.code(engine?.setAudioEffectParameters((params["preset"] as Number).toInt(), (params["param1"] as Number).toInt(), (params["param2"] as Number).toInt())) + callback.code( + engine?.setAudioEffectParameters( + (params["preset"] as Number).toInt(), + (params["param1"] as Number).toInt(), + (params["param2"] as Number).toInt() + ) + ) } override fun setVoiceBeautifierParameters(params: Map, callback: Callback) { - callback.code(engine?.setVoiceBeautifierParameters((params["preset"] as Number).toInt(), (params["param1"] as Number).toInt(), (params["param2"] as Number).toInt())) + callback.code( + engine?.setVoiceBeautifierParameters( + (params["preset"] as Number).toInt(), + (params["param1"] as Number).toInt(), + (params["param2"] as Number).toInt() + ) + ) } override fun enableSoundPositionIndication(params: Map, callback: Callback) { @@ -761,7 +960,13 @@ class RtcEngineManager( } override fun setRemoteVoicePosition(params: Map, 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"] as Number).toNativeUInt(), + (params["pan"] as Number).toDouble(), + (params["gain"] as Number).toDouble() + ) + ) } override fun setLiveTranscoding(params: Map, callback: Callback) { @@ -769,7 +974,12 @@ class RtcEngineManager( } override fun addPublishStreamUrl(params: Map, callback: Callback) { - callback.code(engine?.addPublishStreamUrl(params["url"] as String, params["transcodingEnabled"] as Boolean)) + callback.code( + engine?.addPublishStreamUrl( + params["url"] as String, + params["transcodingEnabled"] as Boolean + ) + ) } override fun removePublishStreamUrl(params: Map, callback: Callback) { @@ -813,7 +1023,12 @@ class RtcEngineManager( } override fun setRemoteVideoStreamType(params: Map, callback: Callback) { - callback.code(engine?.setRemoteVideoStreamType((params["uid"] as Number).toInt(), (params["streamType"] as Number).toInt())) + callback.code( + engine?.setRemoteVideoStreamType( + (params["uid"] as Number).toNativeUInt(), + (params["streamType"] as Number).toInt() + ) + ) } override fun setRemoteDefaultVideoStreamType(params: Map, callback: Callback) { @@ -829,7 +1044,12 @@ class RtcEngineManager( } override fun setRemoteUserPriority(params: Map, callback: Callback) { - callback.code(engine?.setRemoteUserPriority((params["uid"] as Number).toInt(), (params["userPriority"] as Number).toInt())) + callback.code( + engine?.setRemoteUserPriority( + (params["uid"] as Number).toNativeUInt(), + (params["userPriority"] as Number).toInt() + ) + ) } override fun startEchoTest(params: Map, callback: Callback) { @@ -860,7 +1080,12 @@ class RtcEngineManager( val mediaObserver = MediaObserver { data -> emit(RtcEngineEvents.MetadataReceived, data) } - callback.code(engine?.registerMediaMetadataObserver(mediaObserver, IMetadataObserver.VIDEO_METADATA)) { + callback.code( + engine?.registerMediaMetadataObserver( + mediaObserver, + IMetadataObserver.VIDEO_METADATA + ) + ) { this.mediaObserver = mediaObserver Unit } @@ -887,7 +1112,12 @@ class RtcEngineManager( } override fun addVideoWatermark(params: Map, callback: Callback) { - callback.code(engine?.addVideoWatermark(params["watermarkUrl"] as String, mapToWatermarkOptions(params["options"] as Map<*, *>))) + callback.code( + engine?.addVideoWatermark( + params["watermarkUrl"] as String, + mapToWatermarkOptions(params["options"] as Map<*, *>) + ) + ) } override fun clearVideoWatermarks(callback: Callback) { @@ -899,20 +1129,39 @@ class RtcEngineManager( } override fun setEncryptionMode(params: Map, callback: Callback) { - callback.code(engine?.setEncryptionMode(when ((params["encryptionMode"] as Number).toInt()) { - EncryptionConfig.EncryptionMode.AES_128_XTS.value -> "aes-128-xts" - EncryptionConfig.EncryptionMode.AES_128_ECB.value -> "aes-128-ecb" - EncryptionConfig.EncryptionMode.AES_256_XTS.value -> "aes-256-xts" - else -> "" - })) + callback.code( + engine?.setEncryptionMode( + when ((params["encryptionMode"] as Number).toInt()) { + EncryptionConfig.EncryptionMode.AES_128_XTS.value -> "aes-128-xts" + EncryptionConfig.EncryptionMode.AES_128_ECB.value -> "aes-128-ecb" + EncryptionConfig.EncryptionMode.AES_256_XTS.value -> "aes-256-xts" + else -> "" + } + ) + ) } override fun enableEncryption(params: Map, callback: Callback) { - callback.code(engine?.enableEncryption(params["enabled"] as Boolean, mapToEncryptionConfig(params["config"] as Map<*, *>))) + callback.code( + engine?.enableEncryption( + params["enabled"] as Boolean, + mapToEncryptionConfig(params["config"] as Map<*, *>) + ) + ) } override fun startAudioRecording(params: Map, callback: Callback) { - callback.code(engine?.startAudioRecording(params["filePath"] as String, (params["sampleRate"] as Number).toInt(), (params["quality"] as Number).toInt())) + (params["config"] as? Map<*, *>)?.let { + callback.code(engine?.startAudioRecording(mapToAudioRecordingConfiguration(it))) + return@startAudioRecording + } + callback.code( + engine?.startAudioRecording( + params["filePath"] as String, + (params["sampleRate"] as Number).toInt(), + (params["quality"] as Number).toInt() + ) + ) } override fun stopAudioRecording(callback: Callback) { @@ -920,7 +1169,12 @@ class RtcEngineManager( } override fun addInjectStreamUrl(params: Map, callback: Callback) { - callback.code(engine?.addInjectStreamUrl(params["url"] as String, mapToLiveInjectStreamConfig(params["config"] as Map<*, *>))) + callback.code( + engine?.addInjectStreamUrl( + params["url"] as String, + mapToLiveInjectStreamConfig(params["config"] as Map<*, *>) + ) + ) } override fun removeInjectStreamUrl(params: Map, callback: Callback) { @@ -960,11 +1214,21 @@ class RtcEngineManager( } override fun setCameraFocusPositionInPreview(params: Map, callback: Callback) { - callback.code(engine?.setCameraFocusPositionInPreview((params["positionX"] as Number).toFloat(), (params["positionY"] as Number).toFloat())) + callback.code( + engine?.setCameraFocusPositionInPreview( + (params["positionX"] as Number).toFloat(), + (params["positionY"] as Number).toFloat() + ) + ) } override fun setCameraExposurePosition(params: Map, callback: Callback) { - callback.code(engine?.setCameraExposurePosition((params["positionXinView"] as Number).toFloat(), (params["positionYinView"] as Number).toFloat())) + callback.code( + engine?.setCameraExposurePosition( + (params["positionXinView"] as Number).toFloat(), + (params["positionYinView"] as Number).toFloat() + ) + ) } override fun enableFaceDetection(params: Map, callback: Callback) { @@ -988,10 +1252,20 @@ class RtcEngineManager( callback.code(engine?.createDataStream(mapToDataStreamConfig(config))) { it } return@createDataStream } - callback.code(engine?.createDataStream(params["reliable"] as Boolean, params["ordered"] as Boolean)) { it } + callback.code( + engine?.createDataStream( + params["reliable"] as Boolean, + params["ordered"] as Boolean + ) + ) { it } } override fun sendStreamMessage(params: Map, callback: Callback) { - callback.code(engine?.sendStreamMessage((params["streamId"] as Number).toInt(), (params["message"] as String).toByteArray())) + callback.code( + engine?.sendStreamMessage( + (params["streamId"] as Number).toInt(), + (params["message"] as String).toByteArray() + ) + ) } } diff --git a/RtcEngineEvent.kt b/RtcEngineEvent.kt index 8a003e383..28fb0ff5d 100644 --- a/RtcEngineEvent.kt +++ b/RtcEngineEvent.kt @@ -192,16 +192,20 @@ class RtcEngineEventHandler( callback(RtcEngineEvents.Error, err) } - override fun onApiCallExecuted(@Annotations.AgoraErrorCode error: Int, api: String?, result: String?) { + override fun onApiCallExecuted( + @Annotations.AgoraErrorCode error: Int, + api: String?, + result: String? + ) { callback(RtcEngineEvents.ApiCallExecuted, error, api, result) } override fun onJoinChannelSuccess(channel: String?, uid: Int, elapsed: Int) { - callback(RtcEngineEvents.JoinChannelSuccess, channel, uid, elapsed) + callback(RtcEngineEvents.JoinChannelSuccess, channel, uid.toUInt().toLong(), elapsed) } override fun onRejoinChannelSuccess(channel: String?, uid: Int, elapsed: Int) { - callback(RtcEngineEvents.RejoinChannelSuccess, channel, uid, elapsed) + callback(RtcEngineEvents.RejoinChannelSuccess, channel, uid.toUInt().toLong(), elapsed) } override fun onLeaveChannel(stats: RtcStats?) { @@ -209,26 +213,32 @@ class RtcEngineEventHandler( } override fun onLocalUserRegistered(uid: Int, userAccount: String?) { - callback(RtcEngineEvents.LocalUserRegistered, uid, userAccount) + callback(RtcEngineEvents.LocalUserRegistered, uid.toUInt().toLong(), userAccount) } override fun onUserInfoUpdated(uid: Int, userInfo: UserInfo?) { - callback(RtcEngineEvents.UserInfoUpdated, uid, userInfo?.toMap()) + callback(RtcEngineEvents.UserInfoUpdated, uid.toUInt().toLong(), userInfo?.toMap()) } - override fun onClientRoleChanged(@Annotations.AgoraClientRole oldRole: Int, @Annotations.AgoraClientRole newRole: Int) { + override fun onClientRoleChanged( + @Annotations.AgoraClientRole oldRole: Int, + @Annotations.AgoraClientRole newRole: Int + ) { callback(RtcEngineEvents.ClientRoleChanged, oldRole, newRole) } override fun onUserJoined(uid: Int, elapsed: Int) { - callback(RtcEngineEvents.UserJoined, uid, elapsed) + callback(RtcEngineEvents.UserJoined, uid.toUInt().toLong(), elapsed) } override fun onUserOffline(uid: Int, @Annotations.AgoraUserOfflineReason reason: Int) { - callback(RtcEngineEvents.UserOffline, uid, reason) + callback(RtcEngineEvents.UserOffline, uid.toUInt().toLong(), reason) } - override fun onConnectionStateChanged(@Annotations.AgoraConnectionStateType state: Int, @Annotations.AgoraConnectionChangedReason reason: Int) { + override fun onConnectionStateChanged( + @Annotations.AgoraConnectionStateType state: Int, + @Annotations.AgoraConnectionChangedReason reason: Int + ) { callback(RtcEngineEvents.ConnectionStateChanged, state, reason) } @@ -248,12 +258,15 @@ class RtcEngineEventHandler( callback(RtcEngineEvents.RequestToken) } - override fun onAudioVolumeIndication(speakers: Array?, @IntRange(from = 0, to = 255) totalVolume: Int) { + override fun onAudioVolumeIndication( + speakers: Array?, + @IntRange(from = 0, to = 255) totalVolume: Int + ) { callback(RtcEngineEvents.AudioVolumeIndication, speakers?.toMapList(), totalVolume) } override fun onActiveSpeaker(uid: Int) { - callback(RtcEngineEvents.ActiveSpeaker, uid) + callback(RtcEngineEvents.ActiveSpeaker, uid.toUInt().toLong()) } override fun onFirstLocalAudioFrame(elapsed: Int) { @@ -266,26 +279,47 @@ class RtcEngineEventHandler( @Deprecated("", ReplaceWith("onRemoteVideoStateChanged")) override fun onUserMuteVideo(uid: Int, muted: Boolean) { - callback(RtcEngineEvents.UserMuteVideo, uid, muted) + callback(RtcEngineEvents.UserMuteVideo, uid.toUInt().toLong(), muted) } - override fun onVideoSizeChanged(uid: Int, width: Int, height: Int, @IntRange(from = 0, to = 360) rotation: Int) { - callback(RtcEngineEvents.VideoSizeChanged, uid, width, height, rotation) + override fun onVideoSizeChanged( + uid: Int, + width: Int, + height: Int, + @IntRange(from = 0, to = 360) rotation: Int + ) { + callback(RtcEngineEvents.VideoSizeChanged, uid.toUInt().toLong(), width, height, rotation) } - override fun onRemoteVideoStateChanged(uid: Int, @Annotations.AgoraVideoRemoteState state: Int, @Annotations.AgoraVideoRemoteStateReason reason: Int, elapsed: Int) { - callback(RtcEngineEvents.RemoteVideoStateChanged, uid, state, reason, elapsed) + override fun onRemoteVideoStateChanged( + uid: Int, + @Annotations.AgoraVideoRemoteState state: Int, + @Annotations.AgoraVideoRemoteStateReason reason: Int, + elapsed: Int + ) { + callback(RtcEngineEvents.RemoteVideoStateChanged, uid.toUInt().toLong(), state, reason, elapsed) } - override fun onLocalVideoStateChanged(@Annotations.AgoraLocalVideoStreamState localVideoState: Int, @Annotations.AgoraLocalVideoStreamError error: Int) { + override fun onLocalVideoStateChanged( + @Annotations.AgoraLocalVideoStreamState localVideoState: Int, + @Annotations.AgoraLocalVideoStreamError error: Int + ) { callback(RtcEngineEvents.LocalVideoStateChanged, localVideoState, error) } - override fun onRemoteAudioStateChanged(uid: Int, @Annotations.AgoraAudioRemoteState state: Int, @Annotations.AgoraAudioRemoteStateReason reason: Int, elapsed: Int) { - callback(RtcEngineEvents.RemoteAudioStateChanged, uid, state, reason, elapsed) + override fun onRemoteAudioStateChanged( + uid: Int, + @Annotations.AgoraAudioRemoteState state: Int, + @Annotations.AgoraAudioRemoteStateReason reason: Int, + elapsed: Int + ) { + callback(RtcEngineEvents.RemoteAudioStateChanged, uid.toUInt().toLong(), state, reason, elapsed) } - override fun onLocalAudioStateChanged(@Annotations.AgoraAudioLocalState state: Int, @Annotations.AgoraAudioLocalError error: Int) { + override fun onLocalAudioStateChanged( + @Annotations.AgoraAudioLocalState state: Int, + @Annotations.AgoraAudioLocalError error: Int + ) { callback(RtcEngineEvents.LocalAudioStateChanged, state, error) } @@ -294,7 +328,11 @@ class RtcEngineEventHandler( } override fun onRemoteSubscribeFallbackToAudioOnly(uid: Int, isFallbackOrRecover: Boolean) { - callback(RtcEngineEvents.RemoteSubscribeFallbackToAudioOnly, uid, isFallbackOrRecover) + callback( + RtcEngineEvents.RemoteSubscribeFallbackToAudioOnly, + uid.toUInt().toLong(), + isFallbackOrRecover + ) } override fun onAudioRouteChanged(@Annotations.AgoraAudioOutputRouting routing: Int) { @@ -309,7 +347,11 @@ class RtcEngineEventHandler( callback(RtcEngineEvents.CameraExposureAreaChanged, rect?.toMap()) } - override fun onFacePositionChanged(imageWidth: Int, imageHeight: Int, faces: Array?) { + override fun onFacePositionChanged( + imageWidth: Int, + imageHeight: Int, + faces: Array? + ) { callback(RtcEngineEvents.FacePositionChanged, imageWidth, imageHeight, faces?.toMapList()) } @@ -321,8 +363,12 @@ class RtcEngineEventHandler( callback(RtcEngineEvents.LastmileQuality, quality) } - override fun onNetworkQuality(uid: Int, @Annotations.AgoraNetworkQuality txQuality: Int, @Annotations.AgoraNetworkQuality rxQuality: Int) { - callback(RtcEngineEvents.NetworkQuality, uid, txQuality, rxQuality) + override fun onNetworkQuality( + uid: Int, + @Annotations.AgoraNetworkQuality txQuality: Int, + @Annotations.AgoraNetworkQuality rxQuality: Int + ) { + callback(RtcEngineEvents.NetworkQuality, uid.toUInt().toLong(), txQuality, rxQuality) } override fun onLastmileProbeResult(result: LastmileProbeResult?) { @@ -343,7 +389,12 @@ class RtcEngineEventHandler( } @Deprecated("", ReplaceWith("onRemoteVideoStats")) - override fun onRemoteVideoStat(uid: Int, delay: Int, receivedBitrate: Int, receivedFrameRate: Int) { + override fun onRemoteVideoStat( + uid: Int, + delay: Int, + receivedBitrate: Int, + receivedFrameRate: Int + ) { // TODO Not in iOS } @@ -360,15 +411,22 @@ class RtcEngineEventHandler( callback(RtcEngineEvents.AudioMixingFinished) } - override fun onAudioMixingStateChanged(@Annotations.AgoraAudioMixingStateCode state: Int, @Annotations.AgoraAudioMixingErrorCode errorCode: Int) { - callback(RtcEngineEvents.AudioMixingStateChanged, state, errorCode) + override fun onAudioMixingStateChanged( + @Annotations.AgoraAudioMixingStateCode state: Int, + @Annotations.AgoraAudioMixingReason reason: Int + ) { + callback(RtcEngineEvents.AudioMixingStateChanged, state, reason) } override fun onAudioEffectFinished(soundId: Int) { callback(RtcEngineEvents.AudioEffectFinished, soundId) } - override fun onRtmpStreamingStateChanged(url: String?, @Annotations.AgoraRtmpStreamingState state: Int, @Annotations.AgoraRtmpStreamingErrorCode errCode: Int) { + override fun onRtmpStreamingStateChanged( + url: String?, + @Annotations.AgoraRtmpStreamingState state: Int, + @Annotations.AgoraRtmpStreamingErrorCode errCode: Int + ) { callback(RtcEngineEvents.RtmpStreamingStateChanged, url, state, errCode) } @@ -376,16 +434,37 @@ class RtcEngineEventHandler( callback(RtcEngineEvents.TranscodingUpdated) } - override fun onStreamInjectedStatus(url: String?, uid: Int, @Annotations.AgoraInjectStreamStatus status: Int) { - callback(RtcEngineEvents.StreamInjectedStatus, url, uid, status) + override fun onStreamInjectedStatus( + url: String?, + uid: Int, + @Annotations.AgoraInjectStreamStatus status: Int + ) { + callback(RtcEngineEvents.StreamInjectedStatus, url, uid.toUInt().toLong(), status) } override fun onStreamMessage(uid: Int, streamId: Int, data: ByteArray?) { - callback(RtcEngineEvents.StreamMessage, uid, streamId, data?.let { String(it, Charsets.UTF_8) }) - } - - override fun onStreamMessageError(uid: Int, streamId: Int, @Annotations.AgoraErrorCode error: Int, missed: Int, cached: Int) { - callback(RtcEngineEvents.StreamMessageError, uid, streamId, error, missed, cached) + callback( + RtcEngineEvents.StreamMessage, + uid.toUInt().toLong(), + streamId, + data?.let { String(it, Charsets.UTF_8) }) + } + + override fun onStreamMessageError( + uid: Int, + streamId: Int, + @Annotations.AgoraErrorCode error: Int, + missed: Int, + cached: Int + ) { + callback( + RtcEngineEvents.StreamMessageError, + uid.toUInt().toLong(), + streamId, + error, + missed, + cached + ) } override fun onMediaEngineLoadSuccess() { @@ -396,7 +475,10 @@ class RtcEngineEventHandler( callback(RtcEngineEvents.MediaEngineStartCallSuccess) } - override fun onChannelMediaRelayStateChanged(@Annotations.AgoraChannelMediaRelayState state: Int, @Annotations.AgoraChannelMediaRelayError code: Int) { + override fun onChannelMediaRelayStateChanged( + @Annotations.AgoraChannelMediaRelayState state: Int, + @Annotations.AgoraChannelMediaRelayError code: Int + ) { callback(RtcEngineEvents.ChannelMediaRelayStateChanged, state, code) } @@ -406,22 +488,22 @@ class RtcEngineEventHandler( @Deprecated("", ReplaceWith("onRemoteVideoStateChanged")) override fun onFirstRemoteVideoFrame(uid: Int, width: Int, height: Int, elapsed: Int) { - callback(RtcEngineEvents.FirstRemoteVideoFrame, uid, width, height, elapsed) + callback(RtcEngineEvents.FirstRemoteVideoFrame, uid.toUInt().toLong(), width, height, elapsed) } @Deprecated("", ReplaceWith("onRemoteAudioStateChanged")) override fun onFirstRemoteAudioFrame(uid: Int, elapsed: Int) { - callback(RtcEngineEvents.FirstRemoteAudioFrame, uid, elapsed) + callback(RtcEngineEvents.FirstRemoteAudioFrame, uid.toUInt().toLong(), elapsed) } @Deprecated("", ReplaceWith("onRemoteAudioStateChanged")) override fun onFirstRemoteAudioDecoded(uid: Int, elapsed: Int) { - callback(RtcEngineEvents.FirstRemoteAudioDecoded, uid, elapsed) + callback(RtcEngineEvents.FirstRemoteAudioDecoded, uid.toUInt().toLong(), elapsed) } @Deprecated("", ReplaceWith("onRemoteAudioStateChanged")) override fun onUserMuteAudio(uid: Int, muted: Boolean) { - callback(RtcEngineEvents.UserMuteAudio, uid, muted) + callback(RtcEngineEvents.UserMuteAudio, uid.toUInt().toLong(), muted) } @Deprecated("", ReplaceWith("onRtmpStreamingStateChanged")) @@ -436,27 +518,39 @@ class RtcEngineEventHandler( @Deprecated("", ReplaceWith("onRemoteAudioStats")) override fun onRemoteAudioTransportStats(uid: Int, delay: Int, lost: Int, rxKBitRate: Int) { - callback(RtcEngineEvents.RemoteAudioTransportStats, uid, delay, lost, rxKBitRate) + callback( + RtcEngineEvents.RemoteAudioTransportStats, + uid.toUInt().toLong(), + delay, + lost, + rxKBitRate + ) } @Deprecated("", ReplaceWith("onRemoteVideoStats")) override fun onRemoteVideoTransportStats(uid: Int, delay: Int, lost: Int, rxKBitRate: Int) { - callback(RtcEngineEvents.RemoteVideoTransportStats, uid, delay, lost, rxKBitRate) + callback( + RtcEngineEvents.RemoteVideoTransportStats, + uid.toUInt().toLong(), + delay, + lost, + rxKBitRate + ) } @Deprecated("", ReplaceWith("onRemoteVideoStateChanged")) override fun onUserEnableVideo(uid: Int, enabled: Boolean) { - callback(RtcEngineEvents.UserEnableVideo, uid, enabled) + callback(RtcEngineEvents.UserEnableVideo, uid.toUInt().toLong(), enabled) } @Deprecated("", ReplaceWith("onRemoteVideoStateChanged")) override fun onUserEnableLocalVideo(uid: Int, enabled: Boolean) { - callback(RtcEngineEvents.UserEnableLocalVideo, uid, enabled) + callback(RtcEngineEvents.UserEnableLocalVideo, uid.toUInt().toLong(), enabled) } @Deprecated("", ReplaceWith("onRemoteVideoStateChanged")) override fun onFirstRemoteVideoDecoded(uid: Int, width: Int, height: Int, elapsed: Int) { - callback(RtcEngineEvents.FirstRemoteVideoDecoded, uid, width, height, elapsed) + callback(RtcEngineEvents.FirstRemoteVideoDecoded, uid.toUInt().toLong(), width, height, elapsed) } @Deprecated("", ReplaceWith("onLocalAudioStateChanged")) @@ -475,8 +569,13 @@ class RtcEngineEventHandler( } @Deprecated("", ReplaceWith("onRemoteAudioStats")) - override fun onAudioQuality(uid: Int, @Annotations.AgoraNetworkQuality quality: Int, delay: Short, lost: Short) { - callback(RtcEngineEvents.AudioQuality, uid, quality, delay, lost) + override fun onAudioQuality( + uid: Int, + @Annotations.AgoraNetworkQuality quality: Int, + delay: Short, + lost: Short + ) { + callback(RtcEngineEvents.AudioQuality, uid.toUInt().toLong(), quality, delay, lost) } @Deprecated("", ReplaceWith("onLocalVideoStateChanged")) @@ -497,31 +596,87 @@ class RtcEngineEventHandler( callback(RtcEngineEvents.FirstLocalVideoFramePublished, elapsed) } - override fun onAudioPublishStateChanged(channel: String?, @Annotations.AgoraStreamPublishState oldState: Int, @Annotations.AgoraStreamPublishState newState: Int, elapseSinceLastState: Int) { - callback(RtcEngineEvents.AudioPublishStateChanged, channel, oldState, newState, elapseSinceLastState) - } - - override fun onVideoPublishStateChanged(channel: String?, @Annotations.AgoraStreamPublishState oldState: Int, @Annotations.AgoraStreamPublishState newState: Int, elapseSinceLastState: Int) { - callback(RtcEngineEvents.VideoPublishStateChanged, channel, oldState, newState, elapseSinceLastState) - } - - override fun onAudioSubscribeStateChanged(channel: String?, uid: Int, @Annotations.AgoraStreamSubscribeState oldState: Int, @Annotations.AgoraStreamSubscribeState newState: Int, elapseSinceLastState: Int) { - callback(RtcEngineEvents.AudioSubscribeStateChanged, channel, uid, oldState, newState, elapseSinceLastState) - } - - override fun onVideoSubscribeStateChanged(channel: String?, uid: Int, @Annotations.AgoraStreamSubscribeState oldState: Int, @Annotations.AgoraStreamSubscribeState newState: Int, elapseSinceLastState: Int) { - callback(RtcEngineEvents.VideoSubscribeStateChanged, channel, uid, oldState, newState, elapseSinceLastState) + override fun onAudioPublishStateChanged( + channel: String?, + @Annotations.AgoraStreamPublishState oldState: Int, + @Annotations.AgoraStreamPublishState newState: Int, + elapseSinceLastState: Int + ) { + callback( + RtcEngineEvents.AudioPublishStateChanged, + channel, + oldState, + newState, + elapseSinceLastState + ) + } + + override fun onVideoPublishStateChanged( + channel: String?, + @Annotations.AgoraStreamPublishState oldState: Int, + @Annotations.AgoraStreamPublishState newState: Int, + elapseSinceLastState: Int + ) { + callback( + RtcEngineEvents.VideoPublishStateChanged, + channel, + oldState, + newState, + elapseSinceLastState + ) + } + + override fun onAudioSubscribeStateChanged( + channel: String?, + uid: Int, + @Annotations.AgoraStreamSubscribeState oldState: Int, + @Annotations.AgoraStreamSubscribeState newState: Int, + elapseSinceLastState: Int + ) { + callback( + RtcEngineEvents.AudioSubscribeStateChanged, + channel, + uid.toUInt().toLong(), + oldState, + newState, + elapseSinceLastState + ) + } + + override fun onVideoSubscribeStateChanged( + channel: String?, + uid: Int, + @Annotations.AgoraStreamSubscribeState oldState: Int, + @Annotations.AgoraStreamSubscribeState newState: Int, + elapseSinceLastState: Int + ) { + callback( + RtcEngineEvents.VideoSubscribeStateChanged, + channel, + uid.toUInt().toLong(), + oldState, + newState, + elapseSinceLastState + ) } override fun onRtmpStreamingEvent(url: String?, @Annotations.AgoraRtmpStreamingEvent error: Int) { callback(RtcEngineEvents.RtmpStreamingEvent, url, error) } - override fun onUserSuperResolutionEnabled(uid: Int, enabled: Boolean, @Annotations.AgoraSuperResolutionStateReason reason: Int) { - callback(RtcEngineEvents.UserSuperResolutionEnabled, uid, enabled, reason) + override fun onUserSuperResolutionEnabled( + uid: Int, + enabled: Boolean, + @Annotations.AgoraSuperResolutionStateReason reason: Int + ) { + callback(RtcEngineEvents.UserSuperResolutionEnabled, uid.toUInt().toLong(), enabled, reason) } - override fun onUploadLogResult(requestId: String?, success: Boolean, @Annotations.AgoraUploadErrorReason reason: Int) { + override fun onUploadLogResult( + requestId: String?, + success: Boolean, + @Annotations.AgoraUploadErrorReason reason: Int + ) { callback(RtcEngineEvents.UploadLogResult, requestId, success, reason) } } diff --git a/RtcSurfaceView.kt b/RtcSurfaceView.kt index 536f7ddaf..ff31727f6 100644 --- a/RtcSurfaceView.kt +++ b/RtcSurfaceView.kt @@ -49,15 +49,16 @@ class RtcSurfaceView( } } - fun setData(engine: RtcEngine, channel: RtcChannel?, uid: Int) { + fun setData(engine: RtcEngine, channel: RtcChannel?, uid: Number) { this.channel = if (channel != null) WeakReference(channel) else null canvas.channelId = this.channel?.get()?.channelId() - canvas.uid = uid + canvas.uid = uid.toNativeUInt() setupVideoCanvas(engine) } fun resetVideoCanvas(engine: RtcEngine) { - val canvas = VideoCanvas(null, canvas.renderMode, canvas.channelId, canvas.uid, canvas.mirrorMode) + val canvas = + VideoCanvas(null, canvas.renderMode, canvas.channelId, canvas.uid, canvas.mirrorMode) if (canvas.uid == 0) { engine.setupLocalVideo(canvas) } else { diff --git a/RtcTextureView.kt b/RtcTextureView.kt index 2ebecae67..795f7af44 100644 --- a/RtcTextureView.kt +++ b/RtcTextureView.kt @@ -25,15 +25,16 @@ class RtcTextureView( addView(texture) } - fun setData(engine: RtcEngine, channel: RtcChannel?, uid: Int) { + fun setData(engine: RtcEngine, channel: RtcChannel?, uid: Number) { this.channel = if (channel != null) WeakReference(channel) else null canvas.channelId = this.channel?.get()?.channelId() - canvas.uid = uid + canvas.uid = uid.toNativeUInt() setupVideoCanvas(engine) } fun resetVideoCanvas(engine: RtcEngine) { - val canvas = VideoCanvas(null, canvas.renderMode, canvas.channelId, canvas.uid, canvas.mirrorMode) + val canvas = + VideoCanvas(null, canvas.renderMode, canvas.channelId, canvas.uid, canvas.mirrorMode) if (canvas.uid == 0) { engine.setupLocalVideo(canvas) } else {