From 51f0ca3007f52fa6f55aa3cb3f7430c0ff505570 Mon Sep 17 00:00:00 2001 From: HUI <15215604969@163.com> Date: Sat, 13 Jun 2020 01:11:39 +0800 Subject: [PATCH 1/3] fix bug from issue: https://github.com/syanbo/react-native-agora/issues/213 upgrade to 3.0.1 --- Annotations.java | 157 ++++++++----- Extensions.kt | 20 +- MediaObserver.kt | 4 +- RtcChannel.kt | 4 +- RtcChannelEvent.kt | 209 +++++++++++++++++ RtcChannelEventHandler.kt | 193 ---------------- RtcEngine.kt | 28 ++- RtcEngineEvent.kt | 473 ++++++++++++++++++++++++++++++++++++++ RtcEngineEventHandler.kt | 460 ------------------------------------ RtcSurfaceView.kt | 32 ++- RtcTextureView.kt | 18 +- 11 files changed, 856 insertions(+), 742 deletions(-) create mode 100644 RtcChannelEvent.kt delete mode 100644 RtcChannelEventHandler.kt create mode 100644 RtcEngineEvent.kt delete mode 100644 RtcEngineEventHandler.kt diff --git a/Annotations.java b/Annotations.java index 6e4dba31d..778f71298 100644 --- a/Annotations.java +++ b/Annotations.java @@ -9,12 +9,36 @@ import io.agora.rtc.Constants; import io.agora.rtc.IMetadataObserver; import io.agora.rtc.video.BeautyOptions; +import io.agora.rtc.video.VideoCanvas; public class Annotations { + @IntDef({ + AgoraRtcAppType.NATIVE, + AgoraRtcAppType.COCOS, + AgoraRtcAppType.UNITY, + AgoraRtcAppType.ELECTRON, + AgoraRtcAppType.FLUTTER, + AgoraRtcAppType.UNREAL, + AgoraRtcAppType.XAMARIN, + AgoraRtcAppType.APICLOUD, + AgoraRtcAppType.REACTNATIVE, + }) + public @interface AgoraRtcAppType { + int NATIVE = 0; + int COCOS = 1; + int UNITY = 2; + int ELECTRON = 3; + int FLUTTER = 4; + int UNREAL = 5; + int XAMARIN = 6; + int APICLOUD = 7; + int REACTNATIVE = 8; + } + @IntDef({ AgoraAudioCodecProfileType.LC_AAC, - AgoraAudioCodecProfileType.HE_AAC + AgoraAudioCodecProfileType.HE_AAC, }) @Retention(RetentionPolicy.SOURCE) public @interface AgoraAudioCodecProfileType { @@ -32,7 +56,7 @@ public class Annotations { Constants.AUDIO_EQUALIZATION_BAND_2K, Constants.AUDIO_EQUALIZATION_BAND_4K, Constants.AUDIO_EQUALIZATION_BAND_8K, - Constants.AUDIO_EQUALIZATION_BAND_16K + Constants.AUDIO_EQUALIZATION_BAND_16K, }) @Retention(RetentionPolicy.SOURCE) public @interface AgoraAudioEqualizationBandFrequency { @@ -44,7 +68,7 @@ public class Annotations { Constants.LOCAL_AUDIO_STREAM_ERROR_DEVICE_NO_PERMISSION, Constants.LOCAL_AUDIO_STREAM_ERROR_DEVICE_BUSY, Constants.LOCAL_AUDIO_STREAM_ERROR_CAPTURE_FAILURE, - Constants.LOCAL_AUDIO_STREAM_ERROR_ENCODE_FAILURE + Constants.LOCAL_AUDIO_STREAM_ERROR_ENCODE_FAILURE, }) @Retention(RetentionPolicy.SOURCE) public @interface AgoraAudioLocalError { @@ -54,7 +78,7 @@ public class Annotations { Constants.LOCAL_AUDIO_STREAM_STATE_STOPPED, Constants.LOCAL_AUDIO_STREAM_STATE_CAPTURING, Constants.LOCAL_AUDIO_STREAM_STATE_ENCODING, - Constants.LOCAL_AUDIO_STREAM_STATE_FAILED + Constants.LOCAL_AUDIO_STREAM_STATE_FAILED, }) @Retention(RetentionPolicy.SOURCE) public @interface AgoraAudioLocalState { @@ -64,7 +88,7 @@ public class Annotations { 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 + AgoraAudioMixingErrorCode.MEDIA_ENGINE_AUDIO_ERROR_OK, }) @Retention(RetentionPolicy.SOURCE) public @interface AgoraAudioMixingErrorCode { @@ -75,7 +99,7 @@ public class Annotations { Constants.MEDIA_ENGINE_AUDIO_EVENT_MIXING_PLAY, Constants.MEDIA_ENGINE_AUDIO_EVENT_MIXING_PAUSED, Constants.MEDIA_ENGINE_AUDIO_EVENT_MIXING_STOPPED, - Constants.MEDIA_ENGINE_AUDIO_EVENT_MIXING_ERROR + Constants.MEDIA_ENGINE_AUDIO_EVENT_MIXING_ERROR, }) @Retention(RetentionPolicy.SOURCE) public @interface AgoraAudioMixingStateCode { @@ -88,7 +112,7 @@ public class Annotations { Constants.AUDIO_ROUTE_HEADSETNOMIC, Constants.AUDIO_ROUTE_SPEAKERPHONE, Constants.AUDIO_ROUTE_LOUDSPEAKER, - Constants.AUDIO_ROUTE_HEADSETBLUETOOTH + Constants.AUDIO_ROUTE_HEADSETBLUETOOTH, }) @Retention(RetentionPolicy.SOURCE) public @interface AgoraAudioOutputRouting { @@ -100,7 +124,7 @@ public class Annotations { Constants.AUDIO_PROFILE_MUSIC_STANDARD, Constants.AUDIO_PROFILE_MUSIC_STANDARD_STEREO, Constants.AUDIO_PROFILE_MUSIC_HIGH_QUALITY, - Constants.AUDIO_PROFILE_MUSIC_HIGH_QUALITY_STEREO + Constants.AUDIO_PROFILE_MUSIC_HIGH_QUALITY_STEREO, }) @Retention(RetentionPolicy.SOURCE) public @interface AgoraAudioProfile { @@ -109,7 +133,7 @@ public class Annotations { @IntDef({ Constants.RAW_AUDIO_FRAME_OP_MODE_READ_ONLY, Constants.RAW_AUDIO_FRAME_OP_MODE_WRITE_ONLY, - Constants.RAW_AUDIO_FRAME_OP_MODE_READ_WRITE + Constants.RAW_AUDIO_FRAME_OP_MODE_READ_WRITE, }) @Retention(RetentionPolicy.SOURCE) public @interface AgoraAudioRawFrameOperationMode { @@ -118,7 +142,7 @@ public class Annotations { @IntDef({ Constants.AUDIO_RECORDING_QUALITY_LOW, Constants.AUDIO_RECORDING_QUALITY_MEDIUM, - Constants.AUDIO_RECORDING_QUALITY_HIGH + Constants.AUDIO_RECORDING_QUALITY_HIGH, }) @Retention(RetentionPolicy.SOURCE) public @interface AgoraAudioRecordingQuality { @@ -129,7 +153,7 @@ public class Annotations { Constants.REMOTE_AUDIO_STATE_STARTING, Constants.REMOTE_AUDIO_STATE_DECODING, Constants.REMOTE_AUDIO_STATE_FROZEN, - Constants.REMOTE_AUDIO_STATE_FAILED + Constants.REMOTE_AUDIO_STATE_FAILED, }) @Retention(RetentionPolicy.SOURCE) public @interface AgoraAudioRemoteState { @@ -143,7 +167,7 @@ public class Annotations { Constants.REMOTE_AUDIO_REASON_LOCAL_UNMUTED, Constants.REMOTE_AUDIO_REASON_REMOTE_MUTED, Constants.REMOTE_AUDIO_REASON_REMOTE_UNMUTED, - Constants.REMOTE_AUDIO_REASON_REMOTE_OFFLINE + Constants.REMOTE_AUDIO_REASON_REMOTE_OFFLINE, }) @Retention(RetentionPolicy.SOURCE) public @interface AgoraAudioRemoteStateReason { @@ -157,7 +181,16 @@ public class Annotations { Constants.AUDIO_REVERB_HIPHOP, Constants.AUDIO_REVERB_VOCAL_CONCERT, Constants.AUDIO_REVERB_KTV, - Constants.AUDIO_REVERB_STUDIO + Constants.AUDIO_REVERB_STUDIO, + Constants.AUDIO_REVERB_FX_KTV, + Constants.AUDIO_REVERB_FX_VOCAL_CONCERT, + Constants.AUDIO_REVERB_FX_UNCLE, + Constants.AUDIO_REVERB_FX_SISTER, + Constants.AUDIO_REVERB_FX_STUDIO, + Constants.AUDIO_REVERB_FX_POPULAR, + Constants.AUDIO_REVERB_FX_RNB, + Constants.AUDIO_REVERB_FX_PHONOGRAPH, + Constants.AUDIO_VIRTUAL_STEREO, }) @Retention(RetentionPolicy.SOURCE) public @interface AgoraAudioReverbPreset { @@ -177,7 +210,7 @@ public class Annotations { @IntDef({ AgoraAudioSampleRateType.TYPE_32000, AgoraAudioSampleRateType.TYPE_44100, - AgoraAudioSampleRateType.TYPE_48000 + AgoraAudioSampleRateType.TYPE_48000, }) @Retention(RetentionPolicy.SOURCE) public @interface AgoraAudioSampleRateType { @@ -192,7 +225,7 @@ public class Annotations { Constants.AUDIO_SCENARIO_EDUCATION, Constants.AUDIO_SCENARIO_GAME_STREAMING, Constants.AUDIO_SCENARIO_SHOWROOM, - Constants.AUDIO_SCENARIO_CHATROOM_GAMING + Constants.AUDIO_SCENARIO_CHATROOM_GAMING, }) @Retention(RetentionPolicy.SOURCE) public @interface AgoraAudioScenario { @@ -205,7 +238,19 @@ public class Annotations { Constants.VOICE_CHANGER_BABYGIRL, Constants.VOICE_CHANGER_ZHUBAJIE, Constants.VOICE_CHANGER_ETHEREAL, - Constants.VOICE_CHANGER_HULK + Constants.VOICE_CHANGER_HULK, + Constants.VOICE_BEAUTY_VIGOROUS, + Constants.VOICE_BEAUTY_DEEP, + Constants.VOICE_BEAUTY_MELLOW, + Constants.VOICE_BEAUTY_FALSETTO, + Constants.VOICE_BEAUTY_FULL, + Constants.VOICE_BEAUTY_CLEAR, + Constants.VOICE_BEAUTY_RESOUNDING, + Constants.VOICE_BEAUTY_RINGING, + Constants.VOICE_BEAUTY_SPACIAL, + Constants.GENERAL_BEAUTY_VOICE_MALE_MAGNETIC, + Constants.GENERAL_BEAUTY_VOICE_FEMALE_FRESH, + Constants.GENERAL_BEAUTY_VOICE_FEMALE_VITALITY, }) @Retention(RetentionPolicy.SOURCE) public @interface AgoraAudioVoiceChanger { @@ -214,7 +259,7 @@ public class Annotations { @IntDef({ AgoraCameraCaptureOutputPreference.CAPTURER_OUTPUT_PREFERENCE_AUTO, AgoraCameraCaptureOutputPreference.CAPTURER_OUTPUT_PREFERENCE_PERFORMANCE, - AgoraCameraCaptureOutputPreference.CAPTURER_OUTPUT_PREFERENCE_PREVIEW + AgoraCameraCaptureOutputPreference.CAPTURER_OUTPUT_PREFERENCE_PREVIEW, }) @Retention(RetentionPolicy.SOURCE) public @interface AgoraCameraCaptureOutputPreference { @@ -225,7 +270,7 @@ public class Annotations { @IntDef({ AgoraCameraDirection.CAMERA_REAR, - AgoraCameraDirection.CAMERA_FRONT + AgoraCameraDirection.CAMERA_FRONT, }) @Retention(RetentionPolicy.SOURCE) public @interface AgoraCameraDirection { @@ -245,7 +290,7 @@ public class Annotations { Constants.RELAY_ERROR_SERVER_CONNECTION_LOST, Constants.RELAY_ERROR_INTERNAL_ERROR, Constants.RELAY_ERROR_SRC_TOKEN_EXPIRED, - Constants.RELAY_ERROR_DEST_TOKEN_EXPIRED + Constants.RELAY_ERROR_DEST_TOKEN_EXPIRED, }) @Retention(RetentionPolicy.SOURCE) public @interface AgoraChannelMediaRelayError { @@ -263,7 +308,7 @@ public class Annotations { Constants.RELAY_EVENT_PACKET_UPDATE_DEST_CHANNEL_REFUSED, Constants.RELAY_EVENT_PACKET_UPDATE_DEST_CHANNEL_NOT_CHANGE, Constants.RELAY_EVENT_PACKET_UPDATE_DEST_CHANNEL_IS_NULL, - Constants.RELAY_EVENT_VIDEO_PROFILE_UPDATE + Constants.RELAY_EVENT_VIDEO_PROFILE_UPDATE, }) @Retention(RetentionPolicy.SOURCE) public @interface AgoraChannelMediaRelayEvent { @@ -282,7 +327,7 @@ public class Annotations { @IntDef({ Constants.CHANNEL_PROFILE_COMMUNICATION, Constants.CHANNEL_PROFILE_LIVE_BROADCASTING, - Constants.CHANNEL_PROFILE_GAME + Constants.CHANNEL_PROFILE_GAME, }) @Retention(RetentionPolicy.SOURCE) public @interface AgoraChannelProfile { @@ -290,7 +335,7 @@ public class Annotations { @IntDef({ Constants.CLIENT_ROLE_BROADCASTER, - Constants.CLIENT_ROLE_AUDIENCE + Constants.CLIENT_ROLE_AUDIENCE, }) @Retention(RetentionPolicy.SOURCE) public @interface AgoraClientRole { @@ -311,7 +356,7 @@ public class Annotations { Constants.CONNECTION_CHANGED_SETTING_PROXY_SERVER, Constants.CONNECTION_CHANGED_RENEW_TOKEN, Constants.CONNECTION_CHANGED_CLIENT_IP_ADDRESS_CHANGED, - Constants.CONNECTION_CHANGED_KEEP_ALIVE_TIMEOUT + Constants.CONNECTION_CHANGED_KEEP_ALIVE_TIMEOUT, }) @Retention(RetentionPolicy.SOURCE) public @interface AgoraConnectionChangedReason { @@ -322,7 +367,7 @@ public class Annotations { Constants.CONNECTION_STATE_CONNECTING, Constants.CONNECTION_STATE_CONNECTED, Constants.CONNECTION_STATE_RECONNECTING, - Constants.CONNECTION_STATE_FAILED + Constants.CONNECTION_STATE_FAILED, }) @Retention(RetentionPolicy.SOURCE) public @interface AgoraConnectionStateType { @@ -331,7 +376,7 @@ public class Annotations { @IntDef({ AgoraDegradationPreference.MAINTAIN_QUALITY, AgoraDegradationPreference.MAINTAIN_FRAMERATE, - AgoraDegradationPreference.MAINTAIN_BALANCED + AgoraDegradationPreference.MAINTAIN_BALANCED, }) @Retention(RetentionPolicy.SOURCE) public @interface AgoraDegradationPreference { @@ -343,7 +388,7 @@ public class Annotations { @StringDef({ AgoraEncryptionMode.AES128XTS, AgoraEncryptionMode.AES256XTS, - AgoraEncryptionMode.AES128ECB + AgoraEncryptionMode.AES128ECB, }) @Retention(RetentionPolicy.SOURCE) public @interface AgoraEncryptionMode { @@ -422,7 +467,7 @@ public class Annotations { Constants.ERR_VCM_UNKNOWN_ERROR, Constants.ERR_VCM_ENCODER_INIT_ERROR, Constants.ERR_VCM_ENCODER_ENCODE_ERROR, - Constants.ERR_VCM_ENCODER_SET_ERROR + Constants.ERR_VCM_ENCODER_SET_ERROR, }) @Retention(RetentionPolicy.SOURCE) public @interface AgoraErrorCode { @@ -439,7 +484,7 @@ public class Annotations { Constants.INJECT_STREAM_STATUS_STOP_UNAUTHORIZED, Constants.INJECT_STREAM_STATUS_STOP_TIMEDOUT, Constants.INJECT_STREAM_STATUS_STOP_FAILED, - Constants.INJECT_STREAM_STATUS_BROKEN + Constants.INJECT_STREAM_STATUS_BROKEN, }) @Retention(RetentionPolicy.SOURCE) public @interface AgoraInjectStreamStatus { @@ -448,7 +493,7 @@ public class Annotations { @IntDef({ Constants.LASTMILE_PROBE_RESULT_COMPLETE, Constants.LASTMILE_PROBE_RESULT_INCOMPLETE_NO_BWE, - Constants.LASTMILE_PROBE_RESULT_UNAVAILABLE + Constants.LASTMILE_PROBE_RESULT_UNAVAILABLE, }) @Retention(RetentionPolicy.SOURCE) public @interface AgoraLastmileProbeResultState { @@ -457,7 +502,7 @@ public class Annotations { @IntDef({ BeautyOptions.LIGHTENING_CONTRAST_LOW, BeautyOptions.LIGHTENING_CONTRAST_NORMAL, - BeautyOptions.LIGHTENING_CONTRAST_HIGH + BeautyOptions.LIGHTENING_CONTRAST_HIGH, }) @Retention(RetentionPolicy.SOURCE) public @interface AgoraLighteningContrastLevel { @@ -469,7 +514,7 @@ public class Annotations { Constants.LOCAL_VIDEO_STREAM_ERROR_DEVICE_NO_PERMISSION, 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_ENCODE_FAILURE, }) @Retention(RetentionPolicy.SOURCE) public @interface AgoraLocalVideoStreamError { @@ -479,7 +524,7 @@ public class Annotations { Constants.LOCAL_VIDEO_STREAM_STATE_STOPPED, Constants.LOCAL_VIDEO_STREAM_STATE_CAPTURING, Constants.LOCAL_VIDEO_STREAM_STATE_ENCODING, - Constants.LOCAL_VIDEO_STREAM_STATE_FAILED + Constants.LOCAL_VIDEO_STREAM_STATE_FAILED, }) @Retention(RetentionPolicy.SOURCE) public @interface AgoraLocalVideoStreamState { @@ -491,7 +536,7 @@ public class Annotations { Constants.LOG_FILTER_INFO, Constants.LOG_FILTER_WARNING, Constants.LOG_FILTER_ERROR, - Constants.LOG_FILTER_CRITICAL + Constants.LOG_FILTER_CRITICAL, }) @Retention(RetentionPolicy.SOURCE) public @interface AgoraLogFilter { @@ -501,7 +546,7 @@ public class Annotations { Constants.MEDIA_TYPE_NONE, Constants.MEDIA_TYPE_AUDIO_ONLY, Constants.MEDIA_TYPE_VIDEO_ONLY, - Constants.MEDIA_TYPE_AUDIO_AND_VIDEO + Constants.MEDIA_TYPE_AUDIO_AND_VIDEO, }) @Retention(RetentionPolicy.SOURCE) public @interface AgoraMediaType { @@ -509,7 +554,7 @@ public class Annotations { @IntDef({ IMetadataObserver.UNKNOWN_METADATA, - IMetadataObserver.VIDEO_METADATA + IMetadataObserver.VIDEO_METADATA, }) @Retention(RetentionPolicy.SOURCE) public @interface AgoraMetadataType { @@ -524,7 +569,7 @@ public class Annotations { Constants.QUALITY_VBAD, Constants.QUALITY_DOWN, Constants.QUALITY_UNSUPPORTED, - Constants.QUALITY_DETECTING + Constants.QUALITY_DETECTING, }) @Retention(RetentionPolicy.SOURCE) public @interface AgoraNetworkQuality { @@ -537,7 +582,7 @@ public class Annotations { Constants.NETWORK_TYPE_WIFI, Constants.NETWORK_TYPE_MOBILE_2G, Constants.NETWORK_TYPE_MOBILE_3G, - Constants.NETWORK_TYPE_MOBILE_4G + Constants.NETWORK_TYPE_MOBILE_4G, }) @Retention(RetentionPolicy.SOURCE) public @interface AgoraNetworkType { @@ -554,7 +599,7 @@ public class Annotations { Constants.RTMP_STREAM_PUBLISH_ERROR_REACH_LIMIT, Constants.RTMP_STREAM_PUBLISH_ERROR_NOT_AUTHORIZED, Constants.RTMP_STREAM_PUBLISH_ERROR_STREAM_NOT_FOUND, - Constants.RTMP_STREAM_PUBLISH_ERROR_FORMAT_NOT_SUPPORTED + Constants.RTMP_STREAM_PUBLISH_ERROR_FORMAT_NOT_SUPPORTED, }) @Retention(RetentionPolicy.SOURCE) public @interface AgoraRtmpStreamingErrorCode { @@ -565,7 +610,7 @@ public class Annotations { Constants.RTMP_STREAM_PUBLISH_STATE_CONNECTING, Constants.RTMP_STREAM_PUBLISH_STATE_RUNNING, Constants.RTMP_STREAM_PUBLISH_STATE_RECOVERING, - Constants.RTMP_STREAM_PUBLISH_STATE_FAILURE + Constants.RTMP_STREAM_PUBLISH_STATE_FAILURE, }) @Retention(RetentionPolicy.SOURCE) public @interface AgoraRtmpStreamingState { @@ -574,7 +619,7 @@ public class Annotations { @IntDef({ Constants.STREAM_FALLBACK_OPTION_DISABLED, Constants.STREAM_FALLBACK_OPTION_VIDEO_STREAM_LOW, - Constants.STREAM_FALLBACK_OPTION_AUDIO_ONLY + Constants.STREAM_FALLBACK_OPTION_AUDIO_ONLY, }) @Retention(RetentionPolicy.SOURCE) public @interface AgoraStreamFallbackOptions { @@ -583,7 +628,7 @@ public class Annotations { @IntDef({ Constants.USER_OFFLINE_QUIT, Constants.USER_OFFLINE_DROPPED, - Constants.USER_OFFLINE_BECOME_AUDIENCE + Constants.USER_OFFLINE_BECOME_AUDIENCE, }) @Retention(RetentionPolicy.SOURCE) public @interface AgoraUserOfflineReason { @@ -591,7 +636,7 @@ public class Annotations { @IntDef({ Constants.USER_PRIORITY_HIGH, - Constants.USER_PRIORITY_NORANL + Constants.USER_PRIORITY_NORANL, }) @Retention(RetentionPolicy.SOURCE) public @interface AgoraUserPriority { @@ -600,7 +645,7 @@ public class Annotations { @IntDef({ AgoraVideoCodecProfileType.BASELINE, AgoraVideoCodecProfileType.MAIN, - AgoraVideoCodecProfileType.HIGH + AgoraVideoCodecProfileType.HIGH, }) @Retention(RetentionPolicy.SOURCE) public @interface AgoraVideoCodecProfileType { @@ -615,7 +660,7 @@ public class Annotations { AgoraVideoFrameRate.FRAME_RATE_FPS_10, AgoraVideoFrameRate.FRAME_RATE_FPS_15, AgoraVideoFrameRate.FRAME_RATE_FPS_24, - AgoraVideoFrameRate.FRAME_RATE_FPS_30 + AgoraVideoFrameRate.FRAME_RATE_FPS_30, }) @Retention(RetentionPolicy.SOURCE) public @interface AgoraVideoFrameRate { @@ -630,7 +675,7 @@ public class Annotations { @IntDef({ Constants.VIDEO_MIRROR_MODE_AUTO, Constants.VIDEO_MIRROR_MODE_ENABLED, - Constants.VIDEO_MIRROR_MODE_DISABLED + Constants.VIDEO_MIRROR_MODE_DISABLED, }) @Retention(RetentionPolicy.SOURCE) public @interface AgoraVideoMirrorMode { @@ -639,7 +684,7 @@ public class Annotations { @IntDef({ AgoraVideoOutputOrientationMode.ORIENTATION_MODE_ADAPTIVE, AgoraVideoOutputOrientationMode.ORIENTATION_MODE_FIXED_LANDSCAPE, - AgoraVideoOutputOrientationMode.ORIENTATION_MODE_FIXED_PORTRAIT + AgoraVideoOutputOrientationMode.ORIENTATION_MODE_FIXED_PORTRAIT, }) @Retention(RetentionPolicy.SOURCE) public @interface AgoraVideoOutputOrientationMode { @@ -651,13 +696,10 @@ public class Annotations { @IntDef({ Constants.ADAPT_NONE, Constants.ADAPT_UP_BANDWIDTH, - Constants.ADAPT_DOWN_BANDWIDTH + Constants.ADAPT_DOWN_BANDWIDTH, }) @Retention(RetentionPolicy.SOURCE) public @interface AgoraVideoQualityAdaptIndication { - int ORIENTATION_MODE_ADAPTIVE = 0; - int ORIENTATION_MODE_FIXED_LANDSCAPE = 1; - int ORIENTATION_MODE_FIXED_PORTRAIT = 2; } @IntDef({ @@ -665,7 +707,7 @@ public class Annotations { Constants.REMOTE_VIDEO_STATE_STARTING, Constants.REMOTE_VIDEO_STATE_DECODING, Constants.REMOTE_VIDEO_STATE_FROZEN, - Constants.REMOTE_VIDEO_STATE_FAILED + Constants.REMOTE_VIDEO_STATE_FAILED, }) @Retention(RetentionPolicy.SOURCE) public @interface AgoraVideoRemoteState { @@ -681,16 +723,17 @@ public class Annotations { Constants.REMOTE_VIDEO_STATE_REASON_REMOTE_UNMUTED, Constants.REMOTE_VIDEO_STATE_REASON_REMOTE_OFFLINE, Constants.REMOTE_VIDEO_STATE_REASON_AUDIO_FALLBACK, - Constants.REMOTE_VIDEO_STATE_REASON_AUDIO_FALLBACK_RECOVERY + Constants.REMOTE_VIDEO_STATE_REASON_AUDIO_FALLBACK_RECOVERY, }) @Retention(RetentionPolicy.SOURCE) public @interface AgoraVideoRemoteStateReason { } @IntDef({ - Constants.RENDER_MODE_HIDDEN, - Constants.RENDER_MODE_FIT, - Constants.RENDER_MODE_ADAPTIVE + VideoCanvas.RENDER_MODE_HIDDEN, + VideoCanvas.RENDER_MODE_FIT, + VideoCanvas.RENDER_MODE_ADAPTIVE, + VideoCanvas.RENDER_MODE_FILL, }) @Retention(RetentionPolicy.SOURCE) public @interface AgoraVideoRenderMode { @@ -698,7 +741,7 @@ public class Annotations { @IntDef({ Constants.VIDEO_STREAM_HIGH, - Constants.VIDEO_STREAM_LOW + Constants.VIDEO_STREAM_LOW, }) @Retention(RetentionPolicy.SOURCE) public @interface AgoraVideoStreamType { @@ -728,7 +771,7 @@ public class Annotations { Constants.WARN_ADM_RECORD_IS_OCCUPIED, Constants.WARN_APM_HOWLING, Constants.WARN_ADM_GLITCH_STATE, - Constants.WARN_ADM_IMPROPER_SETTINGS + Constants.WARN_ADM_IMPROPER_SETTINGS, }) @Retention(RetentionPolicy.SOURCE) public @interface AgoraWarningCode { diff --git a/Extensions.kt b/Extensions.kt index 6066ceac6..472f5ca71 100644 --- a/Extensions.kt +++ b/Extensions.kt @@ -67,7 +67,8 @@ fun RemoteAudioStats.toMap(): Map { "receivedSampleRate" to receivedSampleRate, "receivedBitrate" to receivedBitrate, "totalFrozenTime" to totalFrozenTime, - "frozenRate" to frozenRate + "frozenRate" to frozenRate, + "totalActiveTime" to totalActiveTime ) } @@ -100,7 +101,8 @@ fun RemoteVideoStats.toMap(): Map { "packetLossRate" to packetLossRate, "rxStreamType" to rxStreamType, "totalFrozenTime" to totalFrozenTime, - "frozenRate" to frozenRate + "frozenRate" to frozenRate, + "totalActiveTime" to totalActiveTime ) } @@ -133,3 +135,17 @@ fun LastmileProbeResult.toMap(): Map { "downlinkReport" to downlinkReport.toMap() ) } + +fun AgoraFacePositionInfo.toMap(): Map { + return hashMapOf( + "x" to x, + "y" to y, + "width" to width, + "height" to height, + "distance" to distance + ) +} + +fun Array.toMapList(): List> { + return List(size) { this[it].toMap() } +} diff --git a/MediaObserver.kt b/MediaObserver.kt index f7b61bd18..729d7e57f 100644 --- a/MediaObserver.kt +++ b/MediaObserver.kt @@ -6,7 +6,7 @@ import java.util.* import java.util.concurrent.atomic.AtomicInteger class MediaObserver( - private val emit: (methodName: String, data: Map?) -> Unit + private val emit: (data: Map?) -> Unit ) : IMetadataObserver { private var maxMetadataSize = AtomicInteger(0) private var metadataList = Collections.synchronizedList(mutableListOf()) @@ -31,7 +31,7 @@ class MediaObserver( } override fun onMetadataReceived(buffer: ByteArray, uid: Int, timeStampMs: Long) { - emit("MetadataReceived", hashMapOf( + emit(hashMapOf( "buffer" to String(buffer), "uid" to uid, "timeStampMs" to timeStampMs diff --git a/RtcChannel.kt b/RtcChannel.kt index b73477be4..7860fa65a 100644 --- a/RtcChannel.kt +++ b/RtcChannel.kt @@ -75,8 +75,8 @@ class RtcChannelManager { fun registerMediaMetadataObserver(channelId: String, emit: (methodName: String, data: Map?) -> Unit): Int { this[channelId]?.let { - val mediaObserver = MediaObserver { methodName, data -> - emit(methodName, data?.toMutableMap()?.apply { put("channelId", channelId) }) + val mediaObserver = MediaObserver { data -> + emit(RtcChannelEvents.MetadataReceived, data?.toMutableMap()?.apply { put("channelId", channelId) }) } val res = it.registerMediaMetadataObserver(mediaObserver, IMetadataObserver.VIDEO_METADATA) if (res == 0) mediaObserverMap[channelId] = mediaObserver diff --git a/RtcChannelEvent.kt b/RtcChannelEvent.kt new file mode 100644 index 000000000..2b471ac45 --- /dev/null +++ b/RtcChannelEvent.kt @@ -0,0 +1,209 @@ +package io.agora.rtc.base + +import androidx.annotation.IntRange +import io.agora.rtc.IRtcChannelEventHandler +import io.agora.rtc.IRtcEngineEventHandler +import io.agora.rtc.RtcChannel + +class RtcChannelEvents { + companion object { + const val Warning = "Warning" + const val Error = "Error" + const val JoinChannelSuccess = "JoinChannelSuccess" + const val RejoinChannelSuccess = "RejoinChannelSuccess" + const val LeaveChannel = "LeaveChannel" + const val ClientRoleChanged = "ClientRoleChanged" + const val UserJoined = "UserJoined" + const val UserOffline = "UserOffline" + const val ConnectionStateChanged = "ConnectionStateChanged" + const val ConnectionLost = "ConnectionLost" + const val TokenPrivilegeWillExpire = "TokenPrivilegeWillExpire" + const val RequestToken = "RequestToken" + const val ActiveSpeaker = "ActiveSpeaker" + const val VideoSizeChanged = "VideoSizeChanged" + const val RemoteVideoStateChanged = "RemoteVideoStateChanged" + const val RemoteAudioStateChanged = "RemoteAudioStateChanged" + const val LocalPublishFallbackToAudioOnly = "LocalPublishFallbackToAudioOnly" + const val RemoteSubscribeFallbackToAudioOnly = "RemoteSubscribeFallbackToAudioOnly" + const val RtcStats = "RtcStats" + const val NetworkQuality = "NetworkQuality" + const val RemoteVideoStats = "RemoteVideoStats" + const val RemoteAudioStats = "RemoteAudioStats" + const val RtmpStreamingStateChanged = "RtmpStreamingStateChanged" + const val TranscodingUpdated = "TranscodingUpdated" + const val StreamInjectedStatus = "StreamInjectedStatus" + const val StreamMessage = "StreamMessage" + const val StreamMessageError = "StreamMessageError" + const val ChannelMediaRelayStateChanged = "ChannelMediaRelayStateChanged" + const val ChannelMediaRelayEvent = "ChannelMediaRelayEvent" + const val MetadataReceived = "MetadataReceived" + + fun toMap(): Map { + return hashMapOf( + "Warning" to Warning, + "Error" to Error, + "JoinChannelSuccess" to JoinChannelSuccess, + "RejoinChannelSuccess" to RejoinChannelSuccess, + "LeaveChannel" to LeaveChannel, + "ClientRoleChanged" to ClientRoleChanged, + "UserJoined" to UserJoined, + "UserOffline" to UserOffline, + "ConnectionStateChanged" to ConnectionStateChanged, + "ConnectionLost" to ConnectionLost, + "TokenPrivilegeWillExpire" to TokenPrivilegeWillExpire, + "RequestToken" to RequestToken, + "ActiveSpeaker" to ActiveSpeaker, + "VideoSizeChanged" to VideoSizeChanged, + "RemoteVideoStateChanged" to RemoteVideoStateChanged, + "RemoteAudioStateChanged" to RemoteAudioStateChanged, + "LocalPublishFallbackToAudioOnly" to LocalPublishFallbackToAudioOnly, + "RemoteSubscribeFallbackToAudioOnly" to RemoteSubscribeFallbackToAudioOnly, + "RtcStats" to RtcStats, + "NetworkQuality" to NetworkQuality, + "RemoteVideoStats" to RemoteVideoStats, + "RemoteAudioStats" to RemoteAudioStats, + "RtmpStreamingStateChanged" to RtmpStreamingStateChanged, + "TranscodingUpdated" to TranscodingUpdated, + "StreamInjectedStatus" to StreamInjectedStatus, + "StreamMessage" to StreamMessage, + "StreamMessageError" to StreamMessageError, + "ChannelMediaRelayStateChanged" to ChannelMediaRelayStateChanged, + "ChannelMediaRelayEvent" to ChannelMediaRelayEvent, + "MetadataReceived" to MetadataReceived + ) + } + } +} + +class RtcChannelEventHandler( + private val emitter: (methodName: String, data: Map?) -> Unit +) : IRtcChannelEventHandler() { + companion object { + const val PREFIX = "io.agora.rtc." + } + + private fun callback(methodName: String, channel: RtcChannel?, vararg data: Any?) { + channel?.let { + emitter(methodName, hashMapOf( + "channelId" to it.channelId(), + "data" to data.toList() + )) + } + } + + override fun onChannelWarning(rtcChannel: RtcChannel?, @Annotations.AgoraWarningCode warn: Int) { + callback(RtcChannelEvents.Warning, rtcChannel, warn) + } + + override fun onChannelError(rtcChannel: RtcChannel?, @Annotations.AgoraErrorCode err: Int) { + callback(RtcChannelEvents.Error, rtcChannel, err) + } + + override fun onJoinChannelSuccess(rtcChannel: RtcChannel?, uid: Int, elapsed: Int) { + callback(RtcChannelEvents.JoinChannelSuccess, rtcChannel, uid, elapsed) + } + + override fun onRejoinChannelSuccess(rtcChannel: RtcChannel?, uid: Int, elapsed: Int) { + callback(RtcChannelEvents.RejoinChannelSuccess, rtcChannel, uid, 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) { + callback(RtcChannelEvents.ClientRoleChanged, rtcChannel, oldRole, newRole) + } + + override fun onUserJoined(rtcChannel: RtcChannel?, uid: Int, elapsed: Int) { + callback(RtcChannelEvents.UserJoined, rtcChannel, uid, elapsed) + } + + override fun onUserOffline(rtcChannel: RtcChannel?, uid: Int, @Annotations.AgoraUserOfflineReason reason: Int) { + callback(RtcChannelEvents.UserOffline, rtcChannel, uid, reason) + } + + override fun onConnectionStateChanged(rtcChannel: RtcChannel?, @Annotations.AgoraConnectionStateType state: Int, @Annotations.AgoraConnectionChangedReason reason: Int) { + callback(RtcChannelEvents.ConnectionStateChanged, rtcChannel, state, reason) + } + + override fun onConnectionLost(rtcChannel: RtcChannel?) { + callback(RtcChannelEvents.ConnectionLost, rtcChannel) + } + + override fun onTokenPrivilegeWillExpire(rtcChannel: RtcChannel?, token: String?) { + callback(RtcChannelEvents.TokenPrivilegeWillExpire, rtcChannel, token) + } + + override fun onRequestToken(rtcChannel: RtcChannel?) { + callback(RtcChannelEvents.RequestToken, rtcChannel) + } + + 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.LocalPublishFallbackToAudioOnly, rtcChannel, isFallbackOrRecover) + } + + override fun onRemoteSubscribeFallbackToAudioOnly(rtcChannel: RtcChannel?, uid: Int, isFallbackOrRecover: Boolean) { + callback(RtcChannelEvents.RemoteSubscribeFallbackToAudioOnly, rtcChannel, uid, 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?) { + callback(RtcChannelEvents.RemoteVideoStats, rtcChannel, stats?.toMap()) + } + + 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) { + callback(RtcChannelEvents.RtmpStreamingStateChanged, rtcChannel, url, state, errCode) + } + + override fun onTranscodingUpdated(rtcChannel: RtcChannel?) { + 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 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.ChannelMediaRelayStateChanged, rtcChannel, state, code) + } + + override fun onChannelMediaRelayEvent(rtcChannel: RtcChannel?, @Annotations.AgoraChannelMediaRelayEvent code: Int) { + callback(RtcChannelEvents.ChannelMediaRelayEvent, rtcChannel, code) + } +} diff --git a/RtcChannelEventHandler.kt b/RtcChannelEventHandler.kt deleted file mode 100644 index 5bdf2cee6..000000000 --- a/RtcChannelEventHandler.kt +++ /dev/null @@ -1,193 +0,0 @@ -package io.agora.rtc.base - -import androidx.annotation.IntRange -import io.agora.rtc.IRtcChannelEventHandler -import io.agora.rtc.IRtcEngineEventHandler -import io.agora.rtc.RtcChannel - -class RtcChannelEventHandler( - private val emitter: (methodName: String, data: Map?) -> Unit -) : IRtcChannelEventHandler() { - companion object { - const val PREFIX = "io.agora.rtc." - val EVENTS = hashMapOf( - "Warning" to "Warning", - "Error" to "Error", - "JoinChannelSuccess" to "JoinChannelSuccess", - "RejoinChannelSuccess" to "RejoinChannelSuccess", - "LeaveChannel" to "LeaveChannel", - "ClientRoleChanged" to "ClientRoleChanged", - "UserJoined" to "UserJoined", - "UserOffline" to "UserOffline", - "ConnectionStateChanged" to "ConnectionStateChanged", - "ConnectionLost" to "ConnectionLost", - "TokenPrivilegeWillExpire" to "TokenPrivilegeWillExpire", - "RequestToken" to "RequestToken", - "ActiveSpeaker" to "ActiveSpeaker", - "VideoSizeChanged" to "VideoSizeChanged", - "RemoteVideoStateChanged" to "RemoteVideoStateChanged", - "RemoteAudioStateChanged" to "RemoteAudioStateChanged", - "LocalPublishFallbackToAudioOnly" to "LocalPublishFallbackToAudioOnly", - "RemoteSubscribeFallbackToAudioOnly" to "RemoteSubscribeFallbackToAudioOnly", - "RtcStats" to "RtcStats", - "NetworkQuality" to "NetworkQuality", - "RemoteVideoStats" to "RemoteVideoStats", - "RemoteAudioStats" to "RemoteAudioStats", - "RtmpStreamingStateChanged" to "RtmpStreamingStateChanged", - "TranscodingUpdated" to "TranscodingUpdated", - "StreamInjectedStatus" to "StreamInjectedStatus", - "StreamMessage" to "StreamMessage", - "StreamMessageError" to "StreamMessageError", - "ChannelMediaRelayStateChanged" to "ChannelMediaRelayStateChanged", - "ChannelMediaRelayEvent" to "ChannelMediaRelayEvent", - "MetadataReceived" to "MetadataReceived" - ) - } - - private fun callback(methodName: String, channel: RtcChannel, vararg data: Any?) { - emitter(methodName, hashMapOf( - "channelId" to channel.channelId(), - "data" to data.toList() - )) - } - - override fun onChannelWarning(rtcChannel: RtcChannel, @Annotations.AgoraWarningCode warn: Int) { - super.onChannelWarning(rtcChannel, warn) - callback("Warning", rtcChannel, warn) - } - - override fun onChannelError(rtcChannel: RtcChannel, @Annotations.AgoraErrorCode err: Int) { - super.onChannelError(rtcChannel, err) - callback("Error", rtcChannel, err) - } - - override fun onJoinChannelSuccess(rtcChannel: RtcChannel, uid: Int, elapsed: Int) { - super.onJoinChannelSuccess(rtcChannel, uid, elapsed) - callback("JoinChannelSuccess", rtcChannel, uid, elapsed) - } - - override fun onRejoinChannelSuccess(rtcChannel: RtcChannel, uid: Int, elapsed: Int) { - super.onRejoinChannelSuccess(rtcChannel, uid, elapsed) - callback("RejoinChannelSuccess", rtcChannel, uid, elapsed) - } - - override fun onLeaveChannel(rtcChannel: RtcChannel, stats: IRtcEngineEventHandler.RtcStats?) { - super.onLeaveChannel(rtcChannel, stats) - callback("LeaveChannel", rtcChannel, stats?.toMap()) - } - - override fun onClientRoleChanged(rtcChannel: RtcChannel, @Annotations.AgoraClientRole oldRole: Int, @Annotations.AgoraClientRole newRole: Int) { - super.onClientRoleChanged(rtcChannel, oldRole, newRole) - callback("ClientRoleChanged", rtcChannel, oldRole, newRole) - } - - override fun onUserJoined(rtcChannel: RtcChannel, uid: Int, elapsed: Int) { - super.onUserJoined(rtcChannel, uid, elapsed) - callback("UserJoined", rtcChannel, uid, elapsed) - } - - override fun onUserOffline(rtcChannel: RtcChannel, uid: Int, @Annotations.AgoraUserOfflineReason reason: Int) { - super.onUserOffline(rtcChannel, uid, reason) - callback("UserOffline", rtcChannel, uid, reason) - } - - override fun onConnectionStateChanged(rtcChannel: RtcChannel, @Annotations.AgoraConnectionStateType state: Int, @Annotations.AgoraConnectionChangedReason reason: Int) { - super.onConnectionStateChanged(rtcChannel, state, reason) - callback("ConnectionStateChanged", rtcChannel, state, reason) - } - - override fun onConnectionLost(rtcChannel: RtcChannel) { - super.onConnectionLost(rtcChannel) - callback("ConnectionLost", rtcChannel) - } - - override fun onTokenPrivilegeWillExpire(rtcChannel: RtcChannel, token: String?) { - super.onTokenPrivilegeWillExpire(rtcChannel, token) - callback("TokenPrivilegeWillExpire", rtcChannel, token) - } - - override fun onRequestToken(rtcChannel: RtcChannel) { - super.onRequestToken(rtcChannel) - callback("RequestToken", rtcChannel) - } - - override fun onActiveSpeaker(rtcChannel: RtcChannel, uid: Int) { - super.onActiveSpeaker(rtcChannel, uid) - callback("ActiveSpeaker", rtcChannel, uid) - } - - override fun onVideoSizeChanged(rtcChannel: RtcChannel, uid: Int, width: Int, height: Int, @IntRange(from = 0, to = 360) rotation: Int) { - super.onVideoSizeChanged(rtcChannel, uid, width, height, rotation) - callback("VideoSizeChanged", rtcChannel, uid, width, height, rotation) - } - - override fun onRemoteVideoStateChanged(rtcChannel: RtcChannel, uid: Int, @Annotations.AgoraVideoRemoteState state: Int, @Annotations.AgoraVideoRemoteStateReason reason: Int, elapsed: Int) { - super.onRemoteVideoStateChanged(rtcChannel, uid, state, reason, elapsed) - callback("RemoteVideoStateChanged", rtcChannel, uid, state, reason, elapsed) - } - - override fun onRemoteAudioStateChanged(rtcChannel: RtcChannel, uid: Int, @Annotations.AgoraAudioRemoteState state: Int, @Annotations.AgoraAudioRemoteStateReason reason: Int, elapsed: Int) { - super.onRemoteAudioStateChanged(rtcChannel, uid, state, reason, elapsed) - callback("RemoteAudioStateChanged", rtcChannel, uid, state, reason, elapsed) - } - - override fun onRemoteSubscribeFallbackToAudioOnly(rtcChannel: RtcChannel, uid: Int, isFallbackOrRecover: Boolean) { - super.onRemoteSubscribeFallbackToAudioOnly(rtcChannel, uid, isFallbackOrRecover) - callback("RemoteSubscribeFallbackToAudioOnly", rtcChannel, uid, isFallbackOrRecover) - } - - override fun onRtcStats(rtcChannel: RtcChannel, stats: IRtcEngineEventHandler.RtcStats?) { - super.onRtcStats(rtcChannel, stats) - callback("RtcStats", rtcChannel, stats?.toMap()) - } - - override fun onNetworkQuality(rtcChannel: RtcChannel, uid: Int, @Annotations.AgoraNetworkQuality txQuality: Int, @Annotations.AgoraNetworkQuality rxQuality: Int) { - super.onNetworkQuality(rtcChannel, uid, txQuality, rxQuality) - callback("NetworkQuality", rtcChannel, uid, txQuality, rxQuality) - } - - override fun onRemoteVideoStats(rtcChannel: RtcChannel, stats: IRtcEngineEventHandler.RemoteVideoStats?) { - super.onRemoteVideoStats(rtcChannel, stats) - callback("RemoteVideoStats", rtcChannel, stats?.toMap()) - } - - override fun onRemoteAudioStats(rtcChannel: RtcChannel, stats: IRtcEngineEventHandler.RemoteAudioStats?) { - super.onRemoteAudioStats(rtcChannel, stats) - callback("RemoteAudioStats", rtcChannel, stats?.toMap()) - } - - override fun onRtmpStreamingStateChanged(rtcChannel: RtcChannel, url: String?, @Annotations.AgoraRtmpStreamingState state: Int, @Annotations.AgoraRtmpStreamingErrorCode errCode: Int) { - super.onRtmpStreamingStateChanged(rtcChannel, url, state, errCode) - callback("RtmpStreamingStateChanged", rtcChannel, url, state, errCode) - } - - override fun onTranscodingUpdated(rtcChannel: RtcChannel) { - super.onTranscodingUpdated(rtcChannel) - callback("TranscodingUpdated", rtcChannel) - } - - override fun onStreamInjectedStatus(rtcChannel: RtcChannel, url: String?, uid: Int, @Annotations.AgoraInjectStreamStatus status: Int) { - super.onStreamInjectedStatus(rtcChannel, url, uid, status) - callback("StreamInjectedStatus", rtcChannel, url, uid, status) - } - - override fun onStreamMessage(rtcChannel: RtcChannel, uid: Int, streamId: Int, data: ByteArray?) { - super.onStreamMessage(rtcChannel, uid, streamId, data) - callback("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) { - super.onStreamMessageError(rtcChannel, uid, streamId, error, missed, cached) - callback("StreamMessageError", rtcChannel, uid, streamId, error, missed, cached) - } - - override fun onChannelMediaRelayStateChanged(rtcChannel: RtcChannel, @Annotations.AgoraChannelMediaRelayState state: Int, @Annotations.AgoraChannelMediaRelayError code: Int) { - super.onChannelMediaRelayStateChanged(rtcChannel, state, code) - callback("ChannelMediaRelayStateChanged", rtcChannel, state, code) - } - - override fun onChannelMediaRelayEvent(rtcChannel: RtcChannel, @Annotations.AgoraChannelMediaRelayEvent code: Int) { - super.onChannelMediaRelayEvent(rtcChannel, code) - callback("ChannelMediaRelayEvent", rtcChannel, code) - } -} diff --git a/RtcEngine.kt b/RtcEngine.kt index bd1150b33..c0a668a7a 100644 --- a/RtcEngine.kt +++ b/RtcEngine.kt @@ -3,10 +3,7 @@ package io.agora.rtc.base import android.content.Context import androidx.annotation.FloatRange import androidx.annotation.IntRange -import io.agora.rtc.Constants -import io.agora.rtc.IMetadataObserver -import io.agora.rtc.RtcEngine -import io.agora.rtc.RtcEngineEx +import io.agora.rtc.* import io.agora.rtc.models.UserInfo interface RtcEngineInterface : @@ -31,7 +28,7 @@ interface RtcEngineInterface : RtcEngineManager.RtcInjectStreamInterface, RtcEngineManager.RtcCameraInterface, RtcEngineManager.RtcStreamMessageInterface { - fun create(appId: String, callback: Callback?) + fun create(appId: String, areaCode: Int, callback: Callback?) fun destroy(callback: Callback?) @@ -71,11 +68,16 @@ class RtcEngineManager { private var engine: RtcEngine? = null private var mediaObserver: MediaObserver? = null - fun create(context: Context, appId: String, emit: (methodName: String, data: Map?) -> Unit) { - engine = RtcEngineEx.create(context, appId, RtcEngineEventHandler { methodName, data -> - emit(methodName, data) + fun create(context: Context, appId: String, areaCode: Int, @Annotations.AgoraRtcAppType appType: Int, emit: (methodName: String, data: Map?) -> Unit) { + RtcEngineEx.create(RtcEngineConfig().apply { + mContext = context + mAppId = appId + mAreaCode = areaCode + mEventHandler = RtcEngineEventHandler { methodName, data -> + emit(methodName, data) + } }) - (engine as? RtcEngineEx)?.setAppType(8) + (engine as? RtcEngineEx)?.setAppType(appType) } fun destroy() { @@ -112,8 +114,8 @@ class RtcEngineManager { fun registerMediaMetadataObserver(emit: (methodName: String, data: Map?) -> Unit): Int { engine?.let { - val mediaObserver = MediaObserver { methodName, data -> - emit(methodName, data) + val mediaObserver = MediaObserver { data -> + emit(RtcEngineEvents.MetadataReceived, data) } val res = it.registerMediaMetadataObserver(mediaObserver, IMetadataObserver.VIDEO_METADATA) if (res == 0) this.mediaObserver = mediaObserver @@ -241,6 +243,8 @@ class RtcEngineManager { fun getAudioMixingCurrentPosition(callback: Callback?) fun setAudioMixingPosition(pos: Int, callback: Callback?) + + fun setAudioMixingPitch(@IntRange(from = -12, to = 12) pitch: Int, callback: Callback?) } interface RtcAudioEffectInterface { @@ -402,6 +406,8 @@ class RtcEngineManager { fun setCameraExposurePosition(positionXinView: Float, positionYinView: Float, callback: Callback?) + fun enableFaceDetection(enable: Boolean, callback: Callback?) + fun setCameraTorchOn(isOn: Boolean, callback: Callback?) fun setCameraAutoFocusFaceModeEnabled(enabled: Boolean, callback: Callback?) diff --git a/RtcEngineEvent.kt b/RtcEngineEvent.kt new file mode 100644 index 000000000..00aaaf42e --- /dev/null +++ b/RtcEngineEvent.kt @@ -0,0 +1,473 @@ +package io.agora.rtc.base + +import android.graphics.Rect +import androidx.annotation.IntRange +import io.agora.rtc.IRtcEngineEventHandler +import io.agora.rtc.models.UserInfo + +class RtcEngineEvents { + companion object { + const val Warning = "Warning" + const val Error = "Error" + const val ApiCallExecuted = "ApiCallExecuted" + const val JoinChannelSuccess = "JoinChannelSuccess" + const val RejoinChannelSuccess = "RejoinChannelSuccess" + const val LeaveChannel = "LeaveChannel" + const val LocalUserRegistered = "LocalUserRegistered" + const val UserInfoUpdated = "UserInfoUpdated" + const val ClientRoleChanged = "ClientRoleChanged" + const val UserJoined = "UserJoined" + const val UserOffline = "UserOffline" + const val ConnectionStateChanged = "ConnectionStateChanged" + const val NetworkTypeChanged = "NetworkTypeChanged" + const val ConnectionLost = "ConnectionLost" + const val TokenPrivilegeWillExpire = "TokenPrivilegeWillExpire" + const val RequestToken = "RequestToken" + const val AudioVolumeIndication = "AudioVolumeIndication" + const val ActiveSpeaker = "ActiveSpeaker" + const val FirstLocalAudioFrame = "FirstLocalAudioFrame" + const val FirstLocalVideoFrame = "FirstLocalVideoFrame" + const val UserMuteVideo = "UserMuteVideo" + const val VideoSizeChanged = "VideoSizeChanged" + const val RemoteVideoStateChanged = "RemoteVideoStateChanged" + const val LocalVideoStateChanged = "LocalVideoStateChanged" + const val RemoteAudioStateChanged = "RemoteAudioStateChanged" + const val LocalAudioStateChanged = "LocalAudioStateChanged" + const val LocalPublishFallbackToAudioOnly = "LocalPublishFallbackToAudioOnly" + const val RemoteSubscribeFallbackToAudioOnly = "RemoteSubscribeFallbackToAudioOnly" + const val AudioRouteChanged = "AudioRouteChanged" + const val CameraFocusAreaChanged = "CameraFocusAreaChanged" + const val CameraExposureAreaChanged = "CameraExposureAreaChanged" + const val FacePositionChanged = "FacePositionChanged" + const val RtcStats = "RtcStats" + const val LastmileQuality = "LastmileQuality" + const val NetworkQuality = "NetworkQuality" + const val LastmileProbeResult = "LastmileProbeResult" + const val LocalVideoStats = "LocalVideoStats" + const val LocalAudioStats = "LocalAudioStats" + const val RemoteVideoStats = "RemoteVideoStats" + const val RemoteAudioStats = "RemoteAudioStats" + const val AudioMixingFinished = "AudioMixingFinished" + const val AudioMixingStateChanged = "AudioMixingStateChanged" + const val AudioEffectFinished = "AudioEffectFinished" + const val RtmpStreamingStateChanged = "RtmpStreamingStateChanged" + const val TranscodingUpdated = "TranscodingUpdated" + const val StreamInjectedStatus = "StreamInjectedStatus" + const val StreamMessage = "StreamMessage" + const val StreamMessageError = "StreamMessageError" + const val MediaEngineLoadSuccess = "MediaEngineLoadSuccess" + const val MediaEngineStartCallSuccess = "MediaEngineStartCallSuccess" + const val ChannelMediaRelayStateChanged = "ChannelMediaRelayStateChanged" + const val ChannelMediaRelayEvent = "ChannelMediaRelayEvent" + const val FirstRemoteVideoFrame = "FirstRemoteVideoFrame" + const val FirstRemoteAudioFrame = "FirstRemoteAudioFrame" + const val FirstRemoteAudioDecoded = "FirstRemoteAudioDecoded" + const val UserMuteAudio = "UserMuteAudio" + const val StreamPublished = "StreamPublished" + const val StreamUnpublished = "StreamUnpublished" + const val RemoteAudioTransportStats = "RemoteAudioTransportStats" + const val RemoteVideoTransportStats = "RemoteVideoTransportStats" + const val UserEnableVideo = "UserEnableVideo" + const val UserEnableLocalVideo = "UserEnableLocalVideo" + const val FirstRemoteVideoDecoded = "FirstRemoteVideoDecoded" + const val MicrophoneEnabled = "MicrophoneEnabled" + const val ConnectionInterrupted = "ConnectionInterrupted" + const val ConnectionBanned = "ConnectionBanned" + const val AudioQuality = "AudioQuality" + const val CameraReady = "CameraReady" + const val VideoStopped = "VideoStopped" + const val MetadataReceived = "MetadataReceived" + + fun toMap(): Map { + return hashMapOf( + "Warning" to Warning, + "Error" to Error, + "ApiCallExecuted" to ApiCallExecuted, + "JoinChannelSuccess" to JoinChannelSuccess, + "RejoinChannelSuccess" to RejoinChannelSuccess, + "LeaveChannel" to LeaveChannel, + "LocalUserRegistered" to LocalUserRegistered, + "UserInfoUpdated" to UserInfoUpdated, + "ClientRoleChanged" to ClientRoleChanged, + "UserJoined" to UserJoined, + "UserOffline" to UserOffline, + "ConnectionStateChanged" to ConnectionStateChanged, + "NetworkTypeChanged" to NetworkTypeChanged, + "ConnectionLost" to ConnectionLost, + "TokenPrivilegeWillExpire" to TokenPrivilegeWillExpire, + "RequestToken" to RequestToken, + "AudioVolumeIndication" to AudioVolumeIndication, + "ActiveSpeaker" to ActiveSpeaker, + "FirstLocalAudioFrame" to FirstLocalAudioFrame, + "FirstLocalVideoFrame" to FirstLocalVideoFrame, + "UserMuteVideo" to UserMuteVideo, + "VideoSizeChanged" to VideoSizeChanged, + "RemoteVideoStateChanged" to RemoteVideoStateChanged, + "LocalVideoStateChanged" to LocalVideoStateChanged, + "RemoteAudioStateChanged" to RemoteAudioStateChanged, + "LocalAudioStateChanged" to LocalAudioStateChanged, + "LocalPublishFallbackToAudioOnly" to LocalPublishFallbackToAudioOnly, + "RemoteSubscribeFallbackToAudioOnly" to RemoteSubscribeFallbackToAudioOnly, + "AudioRouteChanged" to AudioRouteChanged, + "CameraFocusAreaChanged" to CameraFocusAreaChanged, + "CameraExposureAreaChanged" to CameraExposureAreaChanged, + "FacePositionChanged" to FacePositionChanged, + "RtcStats" to RtcStats, + "LastmileQuality" to LastmileQuality, + "NetworkQuality" to NetworkQuality, + "LastmileProbeResult" to LastmileProbeResult, + "LocalVideoStats" to LocalVideoStats, + "LocalAudioStats" to LocalAudioStats, + "RemoteVideoStats" to RemoteVideoStats, + "RemoteAudioStats" to RemoteAudioStats, + "AudioMixingFinished" to AudioMixingFinished, + "AudioMixingStateChanged" to AudioMixingStateChanged, + "AudioEffectFinished" to AudioEffectFinished, + "RtmpStreamingStateChanged" to RtmpStreamingStateChanged, + "TranscodingUpdated" to TranscodingUpdated, + "StreamInjectedStatus" to StreamInjectedStatus, + "StreamMessage" to StreamMessage, + "StreamMessageError" to StreamMessageError, + "MediaEngineLoadSuccess" to MediaEngineLoadSuccess, + "MediaEngineStartCallSuccess" to MediaEngineStartCallSuccess, + "ChannelMediaRelayStateChanged" to ChannelMediaRelayStateChanged, + "ChannelMediaRelayEvent" to ChannelMediaRelayEvent, + "FirstRemoteVideoFrame" to FirstRemoteVideoFrame, + "FirstRemoteAudioFrame" to FirstRemoteAudioFrame, + "FirstRemoteAudioDecoded" to FirstRemoteAudioDecoded, + "UserMuteAudio" to UserMuteAudio, + "StreamPublished" to StreamPublished, + "StreamUnpublished" to StreamUnpublished, + "RemoteAudioTransportStats" to RemoteAudioTransportStats, + "RemoteVideoTransportStats" to RemoteVideoTransportStats, + "UserEnableVideo" to UserEnableVideo, + "UserEnableLocalVideo" to UserEnableLocalVideo, + "FirstRemoteVideoDecoded" to FirstRemoteVideoDecoded, + "MicrophoneEnabled" to MicrophoneEnabled, + "ConnectionInterrupted" to ConnectionInterrupted, + "ConnectionBanned" to ConnectionBanned, + "AudioQuality" to AudioQuality, + "CameraReady" to CameraReady, + "VideoStopped" to VideoStopped, + "MetadataReceived" to MetadataReceived + ) + } + } +} + +class RtcEngineEventHandler( + private val emitter: (methodName: String, data: Map?) -> Unit +) : IRtcEngineEventHandler() { + companion object { + const val PREFIX = "io.agora.rtc." + } + + private fun callback(methodName: String, vararg data: Any?) { + emitter(methodName, hashMapOf("data" to data.toList())) + } + + override fun onWarning(@Annotations.AgoraWarningCode warn: Int) { + callback(RtcEngineEvents.Warning, warn) + } + + override fun onError(@Annotations.AgoraErrorCode err: Int) { + callback(RtcEngineEvents.Error, err) + } + + 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) + } + + override fun onRejoinChannelSuccess(channel: String?, uid: Int, elapsed: Int) { + callback(RtcEngineEvents.RejoinChannelSuccess, uid, elapsed) + } + + override fun onLeaveChannel(stats: RtcStats?) { + callback(RtcEngineEvents.LeaveChannel, stats?.toMap()) + } + + override fun onLocalUserRegistered(uid: Int, userAccount: String?) { + callback(RtcEngineEvents.LocalUserRegistered, uid, userAccount) + } + + override fun onUserInfoUpdated(uid: Int, userInfo: UserInfo?) { + callback(RtcEngineEvents.UserInfoUpdated, uid, userInfo?.toMap()) + } + + 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) + } + + override fun onUserOffline(uid: Int, @Annotations.AgoraUserOfflineReason reason: Int) { + callback(RtcEngineEvents.UserOffline, uid, reason) + } + + override fun onConnectionStateChanged(@Annotations.AgoraConnectionStateType state: Int, @Annotations.AgoraConnectionChangedReason reason: Int) { + callback(RtcEngineEvents.ConnectionStateChanged, state, reason) + } + + override fun onNetworkTypeChanged(@Annotations.AgoraNetworkType type: Int) { + callback(RtcEngineEvents.NetworkTypeChanged, type) + } + + override fun onConnectionLost() { + callback(RtcEngineEvents.ConnectionLost) + } + + override fun onTokenPrivilegeWillExpire(token: String?) { + callback(RtcEngineEvents.TokenPrivilegeWillExpire, token) + } + + override fun onRequestToken() { + callback(RtcEngineEvents.RequestToken) + } + + 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) + } + + override fun onFirstLocalAudioFrame(elapsed: Int) { + callback(RtcEngineEvents.FirstLocalAudioFrame, elapsed) + } + + override fun onFirstLocalVideoFrame(width: Int, height: Int, elapsed: Int) { + callback(RtcEngineEvents.FirstLocalVideoFrame, width, height, elapsed) + } + + @Deprecated("", ReplaceWith("onRemoteVideoStateChanged")) + override fun onUserMuteVideo(uid: Int, muted: Boolean) { + callback(RtcEngineEvents.UserMuteVideo, uid, 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 onRemoteVideoStateChanged(uid: Int, @Annotations.AgoraVideoRemoteState state: Int, @Annotations.AgoraVideoRemoteStateReason reason: Int, elapsed: Int) { + callback(RtcEngineEvents.RemoteVideoStateChanged, uid, state, reason, elapsed) + } + + 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 onLocalAudioStateChanged(@Annotations.AgoraAudioLocalState state: Int, @Annotations.AgoraAudioLocalError error: Int) { + callback(RtcEngineEvents.LocalAudioStateChanged, state, error) + } + + override fun onLocalPublishFallbackToAudioOnly(isFallbackOrRecover: Boolean) { + callback(RtcEngineEvents.LocalPublishFallbackToAudioOnly, isFallbackOrRecover) + } + + override fun onRemoteSubscribeFallbackToAudioOnly(uid: Int, isFallbackOrRecover: Boolean) { + callback(RtcEngineEvents.RemoteSubscribeFallbackToAudioOnly, uid, isFallbackOrRecover) + } + + override fun onAudioRouteChanged(@Annotations.AgoraAudioOutputRouting routing: Int) { + callback(RtcEngineEvents.AudioRouteChanged, routing) + } + + override fun onCameraFocusAreaChanged(rect: Rect?) { + callback(RtcEngineEvents.CameraFocusAreaChanged, rect?.toMap()) + } + + override fun onCameraExposureAreaChanged(rect: Rect?) { + callback(RtcEngineEvents.CameraExposureAreaChanged, rect?.toMap()) + } + + override fun onFacePositionChanged(imageWidth: Int, imageHeight: Int, faces: Array?) { + callback(RtcEngineEvents.FacePositionChanged, imageWidth, imageHeight, faces?.toMapList()) + } + + override fun onRtcStats(stats: RtcStats?) { + callback(RtcEngineEvents.RtcStats, stats?.toMap()) + } + + override fun onLastmileQuality(@Annotations.AgoraNetworkQuality quality: Int) { + 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 onLastmileProbeResult(result: LastmileProbeResult?) { + callback(RtcEngineEvents.LastmileProbeResult, result?.toMap()) + } + + @Deprecated("", ReplaceWith("onLocalVideoStats")) + override fun onLocalVideoStat(sentBitrate: Int, sentFrameRate: Int) { + // TODO Not in iOS + } + + override fun onLocalVideoStats(stats: LocalVideoStats?) { + callback(RtcEngineEvents.LocalVideoStats, stats?.toMap()) + } + + override fun onLocalAudioStats(stats: LocalAudioStats?) { + callback(RtcEngineEvents.LocalAudioStats, stats?.toMap()) + } + + @Deprecated("", ReplaceWith("onRemoteVideoStats")) + override fun onRemoteVideoStat(uid: Int, delay: Int, receivedBitrate: Int, receivedFrameRate: Int) { + // TODO Not in iOS + } + + override fun onRemoteVideoStats(stats: RemoteVideoStats?) { + callback(RtcEngineEvents.RemoteVideoStats, stats?.toMap()) + } + + override fun onRemoteAudioStats(stats: RemoteAudioStats?) { + callback(RtcEngineEvents.RemoteAudioStats, stats?.toMap()) + } + + @Deprecated("", ReplaceWith("onAudioMixingStateChanged")) + override fun onAudioMixingFinished() { + callback(RtcEngineEvents.AudioMixingFinished) + } + + override fun onAudioMixingStateChanged(@Annotations.AgoraAudioMixingStateCode state: Int, @Annotations.AgoraAudioMixingErrorCode errorCode: Int) { + callback(RtcEngineEvents.AudioMixingStateChanged, state, errorCode) + } + + override fun onAudioEffectFinished(soundId: Int) { + callback(RtcEngineEvents.AudioEffectFinished, soundId) + } + + override fun onRtmpStreamingStateChanged(url: String?, @Annotations.AgoraRtmpStreamingState state: Int, @Annotations.AgoraRtmpStreamingErrorCode errCode: Int) { + callback(RtcEngineEvents.RtmpStreamingStateChanged, url, state, errCode) + } + + override fun onTranscodingUpdated() { + callback(RtcEngineEvents.TranscodingUpdated) + } + + override fun onStreamInjectedStatus(url: String?, uid: Int, @Annotations.AgoraInjectStreamStatus status: Int) { + callback(RtcEngineEvents.StreamInjectedStatus, url, uid, 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) + } + + override fun onMediaEngineLoadSuccess() { + callback(RtcEngineEvents.MediaEngineLoadSuccess) + } + + override fun onMediaEngineStartCallSuccess() { + callback(RtcEngineEvents.MediaEngineStartCallSuccess) + } + + override fun onChannelMediaRelayStateChanged(@Annotations.AgoraChannelMediaRelayState state: Int, @Annotations.AgoraChannelMediaRelayError code: Int) { + callback(RtcEngineEvents.ChannelMediaRelayStateChanged, state, code) + } + + override fun onChannelMediaRelayEvent(@Annotations.AgoraChannelMediaRelayEvent code: Int) { + callback(RtcEngineEvents.ChannelMediaRelayEvent, code) + } + + @Deprecated("", ReplaceWith("onRemoteVideoStateChanged")) + override fun onFirstRemoteVideoFrame(uid: Int, width: Int, height: Int, elapsed: Int) { + callback(RtcEngineEvents.FirstRemoteVideoFrame, uid, width, height, elapsed) + } + + @Deprecated("", ReplaceWith("onRemoteAudioStateChanged")) + override fun onFirstRemoteAudioFrame(uid: Int, elapsed: Int) { + callback(RtcEngineEvents.FirstRemoteAudioFrame, uid, elapsed) + } + + @Deprecated("", ReplaceWith("onRemoteAudioStateChanged")) + override fun onFirstRemoteAudioDecoded(uid: Int, elapsed: Int) { + callback(RtcEngineEvents.FirstRemoteAudioDecoded, uid, elapsed) + } + + @Deprecated("", ReplaceWith("onRemoteAudioStateChanged")) + override fun onUserMuteAudio(uid: Int, muted: Boolean) { + callback(RtcEngineEvents.UserMuteAudio, uid, muted) + } + + @Deprecated("", ReplaceWith("onRtmpStreamingStateChanged")) + override fun onStreamPublished(url: String?, @Annotations.AgoraErrorCode error: Int) { + callback(RtcEngineEvents.StreamPublished, url, error) + } + + @Deprecated("", ReplaceWith("onRtmpStreamingStateChanged")) + override fun onStreamUnpublished(url: String?) { + callback(RtcEngineEvents.StreamUnpublished, url) + } + + @Deprecated("", ReplaceWith("onRemoteAudioStats")) + override fun onRemoteAudioTransportStats(uid: Int, delay: Int, lost: Int, rxKBitRate: Int) { + callback(RtcEngineEvents.RemoteAudioTransportStats, uid, delay, lost, rxKBitRate) + } + + @Deprecated("", ReplaceWith("onRemoteVideoStats")) + override fun onRemoteVideoTransportStats(uid: Int, delay: Int, lost: Int, rxKBitRate: Int) { + callback(RtcEngineEvents.RemoteVideoTransportStats, uid, delay, lost, rxKBitRate) + } + + @Deprecated("", ReplaceWith("onRemoteVideoStateChanged")) + override fun onUserEnableVideo(uid: Int, enabled: Boolean) { + callback(RtcEngineEvents.UserEnableVideo, uid, enabled) + } + + @Deprecated("", ReplaceWith("onRemoteVideoStateChanged")) + override fun onUserEnableLocalVideo(uid: Int, enabled: Boolean) { + callback(RtcEngineEvents.UserEnableLocalVideo, uid, enabled) + } + + @Deprecated("", ReplaceWith("onRemoteVideoStateChanged")) + override fun onFirstRemoteVideoDecoded(uid: Int, width: Int, height: Int, elapsed: Int) { + callback(RtcEngineEvents.FirstRemoteVideoDecoded, uid, width, height, elapsed) + } + + @Deprecated("", ReplaceWith("onLocalAudioStateChanged")) + override fun onMicrophoneEnabled(enabled: Boolean) { + callback(RtcEngineEvents.MicrophoneEnabled, enabled) + } + + @Deprecated("", ReplaceWith("onConnectionStateChanged")) + override fun onConnectionInterrupted() { + callback(RtcEngineEvents.ConnectionInterrupted) + } + + @Deprecated("", ReplaceWith("onConnectionStateChanged")) + override fun onConnectionBanned() { + callback(RtcEngineEvents.ConnectionBanned) + } + + @Deprecated("", ReplaceWith("onRemoteAudioStats")) + override fun onAudioQuality(uid: Int, @Annotations.AgoraNetworkQuality quality: Int, delay: Short, lost: Short) { + callback(RtcEngineEvents.AudioQuality, uid, quality, delay, lost) + } + + @Deprecated("", ReplaceWith("onLocalVideoStateChanged")) + override fun onCameraReady() { + callback(RtcEngineEvents.CameraReady) + } + + @Deprecated("", ReplaceWith("onLocalVideoStateChanged")) + override fun onVideoStopped() { + callback(RtcEngineEvents.VideoStopped) + } +} diff --git a/RtcEngineEventHandler.kt b/RtcEngineEventHandler.kt deleted file mode 100644 index abb7897eb..000000000 --- a/RtcEngineEventHandler.kt +++ /dev/null @@ -1,460 +0,0 @@ -package io.agora.rtc.base - -import android.graphics.Rect -import androidx.annotation.IntRange -import io.agora.rtc.IRtcEngineEventHandler -import io.agora.rtc.models.UserInfo - -class RtcEngineEventHandler( - private val emitter: (methodName: String, data: Map?) -> Unit -) : IRtcEngineEventHandler() { - companion object { - const val PREFIX = "io.agora.rtc." - val EVENTS = hashMapOf( - "Warning" to "Warning", - "Error" to "Error", - "ApiCallExecuted" to "ApiCallExecuted", - "JoinChannelSuccess" to "JoinChannelSuccess", - "RejoinChannelSuccess" to "RejoinChannelSuccess", - "LeaveChannel" to "LeaveChannel", - "LocalUserRegistered" to "LocalUserRegistered", - "UserInfoUpdated" to "UserInfoUpdated", - "ClientRoleChanged" to "ClientRoleChanged", - "UserJoined" to "UserJoined", - "UserOffline" to "UserOffline", - "ConnectionStateChanged" to "ConnectionStateChanged", - "NetworkTypeChanged" to "NetworkTypeChanged", - "ConnectionLost" to "ConnectionLost", - "TokenPrivilegeWillExpire" to "TokenPrivilegeWillExpire", - "RequestToken" to "RequestToken", - "AudioVolumeIndication" to "AudioVolumeIndication", - "ActiveSpeaker" to "ActiveSpeaker", - "FirstLocalAudioFrame" to "FirstLocalAudioFrame", - "FirstLocalVideoFrame" to "FirstLocalVideoFrame", - "UserMuteVideo" to "UserMuteVideo", - "VideoSizeChanged" to "VideoSizeChanged", - "RemoteVideoStateChanged" to "RemoteVideoStateChanged", - "LocalVideoStateChanged" to "LocalVideoStateChanged", - "RemoteAudioStateChanged" to "RemoteAudioStateChanged", - "LocalAudioStateChanged" to "LocalAudioStateChanged", - "LocalPublishFallbackToAudioOnly" to "LocalPublishFallbackToAudioOnly", - "RemoteSubscribeFallbackToAudioOnly" to "RemoteSubscribeFallbackToAudioOnly", - "AudioRouteChanged" to "AudioRouteChanged", - "CameraFocusAreaChanged" to "CameraFocusAreaChanged", - "CameraExposureAreaChanged" to "CameraExposureAreaChanged", - "RtcStats" to "RtcStats", - "LastmileQuality" to "LastmileQuality", - "NetworkQuality" to "NetworkQuality", - "LastmileProbeResult" to "LastmileProbeResult", - "LocalVideoStats" to "LocalVideoStats", - "LocalAudioStats" to "LocalAudioStats", - "RemoteVideoStats" to "RemoteVideoStats", - "RemoteAudioStats" to "RemoteAudioStats", - "AudioMixingFinished" to "AudioMixingFinished", - "AudioMixingStateChanged" to "AudioMixingStateChanged", - "AudioEffectFinished" to "AudioEffectFinished", - "RtmpStreamingStateChanged" to "RtmpStreamingStateChanged", - "TranscodingUpdated" to "TranscodingUpdated", - "StreamInjectedStatus" to "StreamInjectedStatus", - "StreamMessage" to "StreamMessage", - "StreamMessageError" to "StreamMessageError", - "MediaEngineLoadSuccess" to "MediaEngineLoadSuccess", - "MediaEngineStartCallSuccess" to "MediaEngineStartCallSuccess", - "ChannelMediaRelayStateChanged" to "ChannelMediaRelayStateChanged", - "ChannelMediaRelayEvent" to "ChannelMediaRelayEvent", - "FirstRemoteVideoFrame" to "FirstRemoteVideoFrame", - "FirstRemoteAudioFrame" to "FirstRemoteAudioFrame", - "FirstRemoteAudioDecoded" to "FirstRemoteAudioDecoded", - "UserMuteAudio" to "UserMuteAudio", - "StreamPublished" to "StreamPublished", - "StreamUnpublished" to "StreamUnpublished", - "RemoteAudioTransportStats" to "RemoteAudioTransportStats", - "RemoteVideoTransportStats" to "RemoteVideoTransportStats", - "UserEnableVideo" to "UserEnableVideo", - "UserEnableLocalVideo" to "UserEnableLocalVideo", - "FirstRemoteVideoDecoded" to "FirstRemoteVideoDecoded", - "MicrophoneEnabled" to "MicrophoneEnabled", - "ConnectionInterrupted" to "ConnectionInterrupted", - "ConnectionBanned" to "ConnectionBanned", - "AudioQuality" to "AudioQuality", - "CameraReady" to "CameraReady", - "VideoStopped" to "VideoStopped", - "MetadataReceived" to "MetadataReceived" - ) - } - - private fun callback(methodName: String, vararg data: Any?) { - emitter(methodName, hashMapOf("data" to data.toList())) - } - - override fun onWarning(@Annotations.AgoraWarningCode warn: Int) { - super.onWarning(warn) - callback("Warning", warn) - } - - override fun onError(@Annotations.AgoraErrorCode err: Int) { - super.onError(err) - callback("Error", err) - } - - override fun onApiCallExecuted(@Annotations.AgoraErrorCode error: Int, api: String?, result: String?) { - super.onApiCallExecuted(error, api, result) - callback("ApiCallExecuted", error, api, result) - } - - override fun onJoinChannelSuccess(channel: String?, uid: Int, elapsed: Int) { - super.onJoinChannelSuccess(channel, uid, elapsed) - callback("JoinChannelSuccess", channel, uid, elapsed) - } - - override fun onRejoinChannelSuccess(channel: String?, uid: Int, elapsed: Int) { - super.onRejoinChannelSuccess(channel, uid, elapsed) - callback("RejoinChannelSuccess", uid, elapsed) - } - - override fun onLeaveChannel(stats: RtcStats?) { - super.onLeaveChannel(stats) - callback("LeaveChannel", stats?.toMap()) - } - - override fun onLocalUserRegistered(uid: Int, userAccount: String?) { - super.onLocalUserRegistered(uid, userAccount) - callback("LocalUserRegistered", uid, userAccount) - } - - override fun onUserInfoUpdated(uid: Int, userInfo: UserInfo?) { - super.onUserInfoUpdated(uid, userInfo) - callback("UserInfoUpdated", uid, userInfo?.toMap()) - } - - override fun onClientRoleChanged(@Annotations.AgoraClientRole oldRole: Int, @Annotations.AgoraClientRole newRole: Int) { - super.onClientRoleChanged(oldRole, newRole) - callback("ClientRoleChanged", oldRole, newRole) - } - - override fun onUserJoined(uid: Int, elapsed: Int) { - super.onUserJoined(uid, elapsed) - callback("UserJoined", uid, elapsed) - } - - override fun onUserOffline(uid: Int, @Annotations.AgoraUserOfflineReason reason: Int) { - super.onUserOffline(uid, reason) - callback("UserOffline", uid, reason) - } - - override fun onConnectionStateChanged(@Annotations.AgoraConnectionStateType state: Int, @Annotations.AgoraConnectionChangedReason reason: Int) { - super.onConnectionStateChanged(state, reason) - callback("ConnectionStateChanged", state, reason) - } - - override fun onNetworkTypeChanged(@Annotations.AgoraNetworkType type: Int) { - super.onNetworkTypeChanged(type) - callback("NetworkTypeChanged", type) - } - - override fun onConnectionLost() { - super.onConnectionLost() - callback("ConnectionLost") - } - - override fun onTokenPrivilegeWillExpire(token: String?) { - super.onTokenPrivilegeWillExpire(token) - callback("TokenPrivilegeWillExpire", token) - } - - override fun onRequestToken() { - super.onRequestToken() - callback("RequestToken") - } - - override fun onAudioVolumeIndication(speakers: Array?, @IntRange(from = 0, to = 255) totalVolume: Int) { - super.onAudioVolumeIndication(speakers, totalVolume) - callback("AudioVolumeIndication", speakers?.toMapList(), totalVolume) - } - - override fun onActiveSpeaker(uid: Int) { - super.onActiveSpeaker(uid) - callback("ActiveSpeaker", uid) - } - - override fun onFirstLocalAudioFrame(elapsed: Int) { - super.onFirstLocalAudioFrame(elapsed) - callback("FirstLocalAudioFrame", elapsed) - } - - override fun onFirstLocalVideoFrame(width: Int, height: Int, elapsed: Int) { - super.onFirstLocalVideoFrame(width, height, elapsed) - callback("FirstLocalVideoFrame", width, height, elapsed) - } - - @Deprecated("", ReplaceWith("onRemoteVideoStateChanged")) - override fun onUserMuteVideo(uid: Int, muted: Boolean) { - super.onUserMuteVideo(uid, muted) - callback("UserMuteVideo", uid, muted) - } - - override fun onVideoSizeChanged(uid: Int, width: Int, height: Int, @IntRange(from = 0, to = 360) rotation: Int) { - super.onVideoSizeChanged(uid, width, height, rotation) - callback("VideoSizeChanged", uid, width, height, rotation) - } - - override fun onRemoteVideoStateChanged(uid: Int, @Annotations.AgoraVideoRemoteState state: Int, @Annotations.AgoraVideoRemoteStateReason reason: Int, elapsed: Int) { - super.onRemoteVideoStateChanged(uid, state, reason, elapsed) - callback("RemoteVideoStateChanged", uid, state, reason, elapsed) - } - - override fun onLocalVideoStateChanged(@Annotations.AgoraLocalVideoStreamState localVideoState: Int, @Annotations.AgoraLocalVideoStreamError error: Int) { - super.onLocalVideoStateChanged(localVideoState, error) - callback("LocalVideoStateChanged", localVideoState, error) - } - - override fun onRemoteAudioStateChanged(uid: Int, @Annotations.AgoraAudioRemoteState state: Int, @Annotations.AgoraAudioRemoteStateReason reason: Int, elapsed: Int) { - super.onRemoteAudioStateChanged(uid, state, reason, elapsed) - callback("RemoteAudioStateChanged", uid, state, reason, elapsed) - } - - override fun onLocalAudioStateChanged(@Annotations.AgoraAudioLocalState state: Int, @Annotations.AgoraAudioLocalError error: Int) { - super.onLocalAudioStateChanged(state, error) - callback("LocalAudioStateChanged", state, error) - } - - override fun onLocalPublishFallbackToAudioOnly(isFallbackOrRecover: Boolean) { - super.onLocalPublishFallbackToAudioOnly(isFallbackOrRecover) - callback("LocalPublishFallbackToAudioOnly", isFallbackOrRecover) - } - - override fun onRemoteSubscribeFallbackToAudioOnly(uid: Int, isFallbackOrRecover: Boolean) { - super.onRemoteSubscribeFallbackToAudioOnly(uid, isFallbackOrRecover) - callback("RemoteSubscribeFallbackToAudioOnly", uid, isFallbackOrRecover) - } - - override fun onAudioRouteChanged(@Annotations.AgoraAudioOutputRouting routing: Int) { - super.onAudioRouteChanged(routing) - callback("AudioRouteChanged", routing) - } - - override fun onCameraFocusAreaChanged(rect: Rect?) { - super.onCameraFocusAreaChanged(rect) - callback("CameraFocusAreaChanged", rect?.toMap()) - } - - override fun onCameraExposureAreaChanged(rect: Rect?) { - super.onCameraExposureAreaChanged(rect) - callback("CameraExposureAreaChanged", rect?.toMap()) - } - - override fun onRtcStats(stats: RtcStats?) { - super.onRtcStats(stats) - callback("RtcStats", stats?.toMap()) - } - - override fun onLastmileQuality(@Annotations.AgoraNetworkQuality quality: Int) { - super.onLastmileQuality(quality) - callback("LastmileQuality", quality) - } - - override fun onNetworkQuality(uid: Int, @Annotations.AgoraNetworkQuality txQuality: Int, @Annotations.AgoraNetworkQuality rxQuality: Int) { - super.onNetworkQuality(uid, txQuality, rxQuality) - callback("NetworkQuality", uid, txQuality, rxQuality) - } - - override fun onLastmileProbeResult(result: LastmileProbeResult?) { - super.onLastmileProbeResult(result) - callback("LastmileProbeResult", result?.toMap()) - } - - @Deprecated("", ReplaceWith("onLocalVideoStats")) - override fun onLocalVideoStat(sentBitrate: Int, sentFrameRate: Int) { - super.onLocalVideoStat(sentBitrate, sentFrameRate) - // TODO Not in iOS - } - - override fun onLocalVideoStats(stats: LocalVideoStats?) { - super.onLocalVideoStats(stats) - callback("LocalVideoStats", stats?.toMap()) - } - - override fun onLocalAudioStats(stats: LocalAudioStats?) { - super.onLocalAudioStats(stats) - callback("LocalAudioStats", stats?.toMap()) - } - - @Deprecated("", ReplaceWith("onRemoteVideoStats")) - override fun onRemoteVideoStat(uid: Int, delay: Int, receivedBitrate: Int, receivedFrameRate: Int) { - super.onRemoteVideoStat(uid, delay, receivedBitrate, receivedFrameRate) - // TODO Not in iOS - } - - override fun onRemoteVideoStats(stats: RemoteVideoStats?) { - super.onRemoteVideoStats(stats) - callback("RemoteVideoStats", stats?.toMap()) - } - - override fun onRemoteAudioStats(stats: RemoteAudioStats?) { - super.onRemoteAudioStats(stats) - callback("RemoteAudioStats", stats?.toMap()) - } - - @Deprecated("", ReplaceWith("onAudioMixingStateChanged")) - override fun onAudioMixingFinished() { - super.onAudioMixingFinished() - callback("AudioMixingFinished") - } - - override fun onAudioMixingStateChanged(@Annotations.AgoraAudioMixingStateCode state: Int, @Annotations.AgoraAudioMixingErrorCode errorCode: Int) { - super.onAudioMixingStateChanged(state, errorCode) - callback("AudioMixingStateChanged", state, errorCode) - } - - override fun onAudioEffectFinished(soundId: Int) { - super.onAudioEffectFinished(soundId) - callback("AudioEffectFinished", soundId) - } - - override fun onRtmpStreamingStateChanged(url: String?, @Annotations.AgoraRtmpStreamingState state: Int, @Annotations.AgoraRtmpStreamingErrorCode errCode: Int) { - super.onRtmpStreamingStateChanged(url, state, errCode) - callback("RtmpStreamingStateChanged", url, state, errCode) - } - - override fun onTranscodingUpdated() { - super.onTranscodingUpdated() - callback("TranscodingUpdated") - } - - override fun onStreamInjectedStatus(url: String?, uid: Int, @Annotations.AgoraInjectStreamStatus status: Int) { - super.onStreamInjectedStatus(url, uid, status) - callback("StreamInjectedStatus", url, uid, status) - } - - override fun onStreamMessage(uid: Int, streamId: Int, data: ByteArray?) { - super.onStreamMessage(uid, streamId, data) - callback("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) { - super.onStreamMessageError(uid, streamId, error, missed, cached) - callback("StreamMessageError", uid, streamId, error, missed, cached) - } - - override fun onMediaEngineLoadSuccess() { - super.onMediaEngineLoadSuccess() - callback("MediaEngineLoadSuccess") - } - - override fun onMediaEngineStartCallSuccess() { - super.onMediaEngineStartCallSuccess() - callback("MediaEngineStartCallSuccess") - } - - override fun onChannelMediaRelayStateChanged(@Annotations.AgoraChannelMediaRelayState state: Int, @Annotations.AgoraChannelMediaRelayError code: Int) { - super.onChannelMediaRelayStateChanged(state, code) - callback("ChannelMediaRelayStateChanged", state, code) - } - - override fun onChannelMediaRelayEvent(@Annotations.AgoraChannelMediaRelayEvent code: Int) { - super.onChannelMediaRelayEvent(code) - callback("ChannelMediaRelayEvent", code) - } - - @Deprecated("", ReplaceWith("onRemoteVideoStateChanged")) - override fun onFirstRemoteVideoFrame(uid: Int, width: Int, height: Int, elapsed: Int) { - super.onFirstRemoteVideoFrame(uid, width, height, elapsed) - callback("FirstRemoteVideoFrame", uid, width, height, elapsed) - } - - @Deprecated("", ReplaceWith("onRemoteAudioStateChanged")) - override fun onFirstRemoteAudioFrame(uid: Int, elapsed: Int) { - super.onFirstRemoteAudioFrame(uid, elapsed) - callback("FirstRemoteAudioFrame", uid, elapsed) - } - - @Deprecated("", ReplaceWith("onRemoteAudioStateChanged")) - override fun onFirstRemoteAudioDecoded(uid: Int, elapsed: Int) { - super.onFirstRemoteAudioDecoded(uid, elapsed) - callback("FirstRemoteAudioDecoded", uid, elapsed) - } - - @Deprecated("", ReplaceWith("onRemoteAudioStateChanged")) - override fun onUserMuteAudio(uid: Int, muted: Boolean) { - super.onUserMuteAudio(uid, muted) - callback("UserMuteAudio", uid, muted) - } - - @Deprecated("", ReplaceWith("onRtmpStreamingStateChanged")) - override fun onStreamPublished(url: String?, @Annotations.AgoraErrorCode error: Int) { - super.onStreamPublished(url, error) - callback("StreamPublished", url, error) - } - - @Deprecated("", ReplaceWith("onRtmpStreamingStateChanged")) - override fun onStreamUnpublished(url: String?) { - super.onStreamUnpublished(url) - callback("StreamUnpublished", url) - } - - @Deprecated("", ReplaceWith("onRemoteAudioStats")) - override fun onRemoteAudioTransportStats(uid: Int, delay: Int, lost: Int, rxKBitRate: Int) { - super.onRemoteAudioTransportStats(uid, delay, lost, rxKBitRate) - callback("RemoteAudioTransportStats", uid, delay, lost, rxKBitRate) - } - - @Deprecated("", ReplaceWith("onRemoteVideoStats")) - override fun onRemoteVideoTransportStats(uid: Int, delay: Int, lost: Int, rxKBitRate: Int) { - super.onRemoteVideoTransportStats(uid, delay, lost, rxKBitRate) - callback("RemoteVideoTransportStats", uid, delay, lost, rxKBitRate) - } - - @Deprecated("", ReplaceWith("onRemoteVideoStateChanged")) - override fun onUserEnableVideo(uid: Int, enabled: Boolean) { - super.onUserEnableVideo(uid, enabled) - callback("UserEnableVideo", uid, enabled) - } - - @Deprecated("", ReplaceWith("onRemoteVideoStateChanged")) - override fun onUserEnableLocalVideo(uid: Int, enabled: Boolean) { - super.onUserEnableLocalVideo(uid, enabled) - callback("UserEnableLocalVideo", uid, enabled) - } - - @Deprecated("", ReplaceWith("onRemoteVideoStateChanged")) - override fun onFirstRemoteVideoDecoded(uid: Int, width: Int, height: Int, elapsed: Int) { - super.onFirstRemoteVideoDecoded(uid, width, height, elapsed) - callback("FirstRemoteVideoDecoded", uid, width, height, elapsed) - } - - @Deprecated("", ReplaceWith("onLocalAudioStateChanged")) - override fun onMicrophoneEnabled(enabled: Boolean) { - super.onMicrophoneEnabled(enabled) - callback("MicrophoneEnabled", enabled) - } - - @Deprecated("", ReplaceWith("onConnectionStateChanged")) - override fun onConnectionInterrupted() { - super.onConnectionInterrupted() - callback("ConnectionInterrupted") - } - - @Deprecated("", ReplaceWith("onConnectionStateChanged")) - override fun onConnectionBanned() { - super.onConnectionBanned() - callback("ConnectionBanned") - } - - @Deprecated("", ReplaceWith("onRemoteAudioStats")) - override fun onAudioQuality(uid: Int, @Annotations.AgoraNetworkQuality quality: Int, delay: Short, lost: Short) { - super.onAudioQuality(uid, quality, delay, lost) - callback("AudioQuality", uid, quality, delay, lost) - } - - @Deprecated("", ReplaceWith("onLocalVideoStateChanged")) - override fun onCameraReady() { - super.onCameraReady() - callback("CameraReady") - } - - @Deprecated("", ReplaceWith("onLocalVideoStateChanged")) - override fun onVideoStopped() { - super.onVideoStopped() - callback("VideoStopped") - } -} diff --git a/RtcSurfaceView.kt b/RtcSurfaceView.kt index f7495ea5d..ad7e9036b 100644 --- a/RtcSurfaceView.kt +++ b/RtcSurfaceView.kt @@ -3,14 +3,17 @@ package io.agora.rtc.base import android.content.Context import android.view.SurfaceView import android.widget.FrameLayout +import io.agora.rtc.RtcChannel import io.agora.rtc.RtcEngine import io.agora.rtc.video.VideoCanvas +import java.lang.ref.WeakReference class RtcSurfaceView( context: Context ) : FrameLayout(context) { private var surface: SurfaceView = RtcEngine.CreateRendererView(context) private var canvas: VideoCanvas + private var channel: WeakReference? = null init { canvas = VideoCanvas(surface) @@ -39,15 +42,12 @@ class RtcSurfaceView( fun setRenderMode(engine: RtcEngine, @Annotations.AgoraVideoRenderMode renderMode: Int) { canvas.renderMode = renderMode - if (canvas.uid == 0) { - engine.setLocalRenderMode(canvas.renderMode, canvas.mirrorMode) - } else { - engine.setRemoteRenderMode(canvas.uid, canvas.renderMode, canvas.mirrorMode) - } + setupRenderMode(engine) } - fun setChannelId(engine: RtcEngine, channelId: String) { - canvas.channelId = channelId + fun setChannel(engine: RtcEngine, channel: RtcChannel?) { + this.channel = if (channel != null) WeakReference(channel) else null + canvas.channelId = channel?.channelId() if (canvas.uid == 0) { engine.setupLocalVideo(canvas) } else { @@ -57,11 +57,7 @@ class RtcSurfaceView( fun setMirrorMode(engine: RtcEngine, @Annotations.AgoraVideoMirrorMode mirrorMode: Int) { canvas.mirrorMode = mirrorMode - if (canvas.uid == 0) { - engine.setLocalRenderMode(canvas.renderMode, canvas.mirrorMode) - } else { - engine.setRemoteRenderMode(canvas.uid, canvas.renderMode, canvas.mirrorMode) - } + setupRenderMode(engine) } fun setUid(engine: RtcEngine, uid: Int) { @@ -73,6 +69,18 @@ class RtcSurfaceView( } } + private fun setupRenderMode(engine: RtcEngine) { + if (canvas.uid == 0) { + engine.setLocalRenderMode(canvas.renderMode, canvas.mirrorMode) + } else { + channel?.get()?.let { + it.setRemoteRenderMode(canvas.uid, canvas.renderMode, canvas.mirrorMode) + return@setupRenderMode + } + engine.setRemoteRenderMode(canvas.uid, canvas.renderMode, canvas.mirrorMode) + } + } + override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) { val width: Int = MeasureSpec.getSize(widthMeasureSpec) val height: Int = MeasureSpec.getSize(heightMeasureSpec) diff --git a/RtcTextureView.kt b/RtcTextureView.kt index e787d2dd8..1461defe4 100644 --- a/RtcTextureView.kt +++ b/RtcTextureView.kt @@ -2,15 +2,18 @@ package io.agora.rtc.base import android.content.Context import android.widget.FrameLayout +import io.agora.rtc.RtcChannel import io.agora.rtc.RtcEngine import io.agora.rtc.mediaio.AgoraTextureView import io.agora.rtc.mediaio.MediaIO +import java.lang.ref.WeakReference class RtcTextureView( context: Context ) : FrameLayout(context) { private var texture: AgoraTextureView = AgoraTextureView(context) private var uid: Int = 0 + private var channel: WeakReference? = null init { texture.init(null) @@ -19,20 +22,29 @@ class RtcTextureView( addView(texture) } + fun setChannel(engine: RtcEngine, channel: RtcChannel?) { + this.channel = if (channel != null) WeakReference(channel) else null + setupVideoRenderer(engine) + } + fun setMirror(engine: RtcEngine, mirror: Boolean) { texture.setMirror(mirror) - setupVideo(engine) + setupVideoRenderer(engine) } fun setUid(engine: RtcEngine, uid: Int) { this.uid = uid - setupVideo(engine) + setupVideoRenderer(engine) } - private fun setupVideo(engine: RtcEngine) { + private fun setupVideoRenderer(engine: RtcEngine) { if (uid == 0) { engine.setLocalVideoRenderer(texture) } else { + channel?.get()?.let { + it.setRemoteVideoRenderer(uid, texture) + return@setupVideoRenderer + } engine.setRemoteVideoRenderer(uid, texture) } } From cf24c0ba69c62506ed3e5209567e6192ce3662be Mon Sep 17 00:00:00 2001 From: HUI <15215604969@163.com> Date: Sat, 13 Jun 2020 03:07:38 +0800 Subject: [PATCH 2/3] fix bugs --- RtcEngine.kt | 2 +- RtcTextureView.kt | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/RtcEngine.kt b/RtcEngine.kt index c0a668a7a..e24f74724 100644 --- a/RtcEngine.kt +++ b/RtcEngine.kt @@ -69,7 +69,7 @@ class RtcEngineManager { private var mediaObserver: MediaObserver? = null fun create(context: Context, appId: String, areaCode: Int, @Annotations.AgoraRtcAppType appType: Int, emit: (methodName: String, data: Map?) -> Unit) { - RtcEngineEx.create(RtcEngineConfig().apply { + engine = RtcEngineEx.create(RtcEngineConfig().apply { mContext = context mAppId = appId mAreaCode = areaCode diff --git a/RtcTextureView.kt b/RtcTextureView.kt index 1461defe4..e028b55c4 100644 --- a/RtcTextureView.kt +++ b/RtcTextureView.kt @@ -39,12 +39,15 @@ class RtcTextureView( private fun setupVideoRenderer(engine: RtcEngine) { if (uid == 0) { + engine.setLocalVideoRenderer(null) engine.setLocalVideoRenderer(texture) } else { channel?.get()?.let { + it.setRemoteVideoRenderer(uid, null) it.setRemoteVideoRenderer(uid, texture) return@setupVideoRenderer } + engine.setRemoteVideoRenderer(uid, null) engine.setRemoteVideoRenderer(uid, texture) } } From b67450678710cbc3ad4fcf72d8b53dd695d0a8e8 Mon Sep 17 00:00:00 2001 From: HUI <15215604969@163.com> Date: Mon, 22 Jun 2020 22:42:05 +0800 Subject: [PATCH 3/3] Android finish --- Annotations.java | 1 + 1 file changed, 1 insertion(+) diff --git a/Annotations.java b/Annotations.java index 778f71298..d1e6fd652 100644 --- a/Annotations.java +++ b/Annotations.java @@ -24,6 +24,7 @@ public class Annotations { AgoraRtcAppType.APICLOUD, AgoraRtcAppType.REACTNATIVE, }) + @Retention(RetentionPolicy.SOURCE) public @interface AgoraRtcAppType { int NATIVE = 0; int COCOS = 1;