Skip to content

Commit

Permalink
fix bug from issue: #213
Browse files Browse the repository at this point in the history
upgrade to 3.0.1
  • Loading branch information
LichKing-2234 committed Jun 12, 2020
1 parent f1ed825 commit 51f0ca3
Show file tree
Hide file tree
Showing 11 changed files with 856 additions and 742 deletions.
157 changes: 100 additions & 57 deletions Annotations.java

Large diffs are not rendered by default.

20 changes: 18 additions & 2 deletions Extensions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ fun RemoteAudioStats.toMap(): Map<String, Any?> {
"receivedSampleRate" to receivedSampleRate,
"receivedBitrate" to receivedBitrate,
"totalFrozenTime" to totalFrozenTime,
"frozenRate" to frozenRate
"frozenRate" to frozenRate,
"totalActiveTime" to totalActiveTime
)
}

Expand Down Expand Up @@ -100,7 +101,8 @@ fun RemoteVideoStats.toMap(): Map<String, Any?> {
"packetLossRate" to packetLossRate,
"rxStreamType" to rxStreamType,
"totalFrozenTime" to totalFrozenTime,
"frozenRate" to frozenRate
"frozenRate" to frozenRate,
"totalActiveTime" to totalActiveTime
)
}

Expand Down Expand Up @@ -133,3 +135,17 @@ fun LastmileProbeResult.toMap(): Map<String, Any?> {
"downlinkReport" to downlinkReport.toMap()
)
}

fun AgoraFacePositionInfo.toMap(): Map<String, Any?> {
return hashMapOf(
"x" to x,
"y" to y,
"width" to width,
"height" to height,
"distance" to distance
)
}

fun Array<out AgoraFacePositionInfo>.toMapList(): List<Map<String, Any?>> {
return List(size) { this[it].toMap() }
}
4 changes: 2 additions & 2 deletions MediaObserver.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import java.util.*
import java.util.concurrent.atomic.AtomicInteger

class MediaObserver(
private val emit: (methodName: String, data: Map<String, Any?>?) -> Unit
private val emit: (data: Map<String, Any?>?) -> Unit
) : IMetadataObserver {
private var maxMetadataSize = AtomicInteger(0)
private var metadataList = Collections.synchronizedList<String>(mutableListOf())
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions RtcChannel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ class RtcChannelManager {

fun registerMediaMetadataObserver(channelId: String, emit: (methodName: String, data: Map<String, Any?>?) -> 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
Expand Down
209 changes: 209 additions & 0 deletions RtcChannelEvent.kt
Original file line number Diff line number Diff line change
@@ -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<String, String> {
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<String, Any?>?) -> 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)
}
}
Loading

0 comments on commit 51f0ca3

Please sign in to comment.