Skip to content

Commit

Permalink
fix: merge some bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
LichKing-2234 committed Mar 24, 2021
1 parent de52ca6 commit df303ee
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 58 deletions.
8 changes: 8 additions & 0 deletions BeanCovertor.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.agora.rtc.base

import android.graphics.Color
import io.agora.rtc.RtcEngineConfig
import io.agora.rtc.internal.EncryptionConfig
import io.agora.rtc.internal.LastmileProbeConfig
import io.agora.rtc.live.LiveInjectStreamConfig
Expand Down Expand Up @@ -172,6 +173,13 @@ fun mapToChannelMediaOptions(map: Map<*, *>): ChannelMediaOptions {
}
}

fun mapToRtcEngineConfig(map: Map<*, *>): RtcEngineConfig {
return RtcEngineConfig().apply {
mAppId = map["appId"] as String
(map["areaCode"] as? Number)?.toInt()?.let { mAreaCode = it }
}
}

fun mapToEncryptionConfig(map: Map<*, *>): EncryptionConfig {
return EncryptionConfig().apply {
(map["encryptionMode"] as? Number)?.let { encryptionMode = intToEncryptionMode(it.toInt()) }
Expand Down
2 changes: 1 addition & 1 deletion MediaObserver.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import java.util.concurrent.atomic.AtomicInteger
class MediaObserver(
private val emit: (data: Map<String, Any?>?) -> Unit
) : IMetadataObserver {
private var maxMetadataSize = AtomicInteger(0)
private var maxMetadataSize = AtomicInteger(1024)
private var metadataList = Collections.synchronizedList<String>(mutableListOf())

fun addMetadata(metadata: String) {
Expand Down
43 changes: 15 additions & 28 deletions RtcChannel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,7 @@ class RtcChannelManager(
}

override fun destroy(params: Map<String, *>, callback: Callback) {
var code: Int? = -Constants.ERR_NOT_INITIALIZED
this[params["channelId"] as String]?.let {
code = rtcChannelMap.remove(it.channelId())?.destroy()
}
callback.code(code)
callback.code(rtcChannelMap.remove(params["channelId"] as String)?.destroy())
}

override fun setClientRole(params: Map<String, *>, callback: Callback) {
Expand Down Expand Up @@ -258,24 +254,22 @@ class RtcChannelManager(
}

override fun registerMediaMetadataObserver(params: Map<String, *>, callback: Callback) {
var code = -Constants.ERR_NOT_INITIALIZED
this[params["channelId"] as String]?.let {
val mediaObserver = MediaObserver { data ->
emit(RtcChannelEvents.MetadataReceived, data?.toMutableMap()?.apply { put("channelId", it.channelId()) })
}
code = it.registerMediaMetadataObserver(mediaObserver, IMetadataObserver.VIDEO_METADATA)
if (code == 0) mediaObserverMap[it.channelId()] = mediaObserver
val channelId = params["channelId"] as String
val mediaObserver = MediaObserver { data ->
emit(RtcChannelEvents.MetadataReceived, data?.toMutableMap()?.apply { put("channelId", channelId) })
}
callback.code(this[channelId]?.registerMediaMetadataObserver(mediaObserver, IMetadataObserver.VIDEO_METADATA)) {
mediaObserverMap[channelId] = mediaObserver
Unit
}
callback.code(code)
}

override fun unregisterMediaMetadataObserver(params: Map<String, *>, callback: Callback) {
var code = -Constants.ERR_NOT_INITIALIZED
this[params["channelId"] as String]?.let {
code = it.registerMediaMetadataObserver(null, IMetadataObserver.VIDEO_METADATA)
if (code == 0) mediaObserverMap.remove(it.channelId())
val channelId = params["channelId"] as String
callback.code(this[channelId]?.registerMediaMetadataObserver(null, IMetadataObserver.VIDEO_METADATA)) {
mediaObserverMap.remove(channelId)
Unit
}
callback.code(code)
}

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

override fun createDataStream(params: Map<String, *>, callback: Callback) {
var code = -Constants.ERR_NOT_INITIALIZED
this[params["channelId"] as String]?.let {
code = it.createDataStream(params["reliable"] as Boolean, params["ordered"] as Boolean)
}
callback.code(code) { it }
val channel = this[params["channelId"] as String]
callback.code(channel?.createDataStream(params["reliable"] as Boolean, params["ordered"] as Boolean)) { it }
}

override fun sendStreamMessage(params: Map<String, *>, callback: Callback) {
var code = -Constants.ERR_NOT_INITIALIZED
this[params["channelId"] as String]?.let {
code = it.sendStreamMessage((params["streamId"] as Number).toInt(), (params["message"] as String).toByteArray())
}
callback.code(code)
callback.code(this[params["channelId"] as String]?.sendStreamMessage((params["streamId"] as Number).toInt(), (params["message"] as String).toByteArray()))
}
}
53 changes: 24 additions & 29 deletions RtcEngine.kt
Original file line number Diff line number Diff line change
Expand Up @@ -344,10 +344,8 @@ class RtcEngineManager(
}

override fun create(params: Map<String, *>, callback: Callback) {
engine = RtcEngineEx.create(RtcEngineConfig().apply {
engine = RtcEngineEx.create(mapToRtcEngineConfig(params["config"] as Map<*, *>).apply {
mContext = params["context"] as Context
mAppId = params["appId"] as String
mAreaCode = (params["areaCode"] as Number).toInt()
mEventHandler = RtcEngineEventHandler { methodName, data ->
emit(methodName, data)
}
Expand All @@ -373,11 +371,17 @@ class RtcEngineManager(
}

override fun joinChannel(params: Map<String, *>, callback: Callback) {
callback.code(engine?.joinChannel(params["token"] as? String, params["channelName"] as String, params["optionalInfo"] as? String, (params["optionalUid"] as Number).toInt()))
val token = params["token"] as? String
val channelName = params["channelName"] as String
val optionalInfo = params["optionalInfo"] as? String
val optionalUid = (params["optionalUid"] as Number).toInt()
callback.code(engine?.joinChannel(token, channelName, optionalInfo, optionalUid))
}

override fun switchChannel(params: Map<String, *>, callback: Callback) {
callback.code(engine?.switchChannel(params["token"] as? String, params["channelName"] as String))
val token = params["token"] as? String
val channelName = params["channelName"] as String
callback.code(engine?.switchChannel(token, channelName))
}

override fun leaveChannel(callback: Callback) {
Expand Down Expand Up @@ -437,7 +441,10 @@ class RtcEngineManager(
}

override fun joinChannelWithUserAccount(params: Map<String, *>, callback: Callback) {
callback.code(engine?.joinChannelWithUserAccount(params["token"] as? String, params["channelName"] as String, params["userAccount"] as String))
val token = params["token"] as? String
val channelName = params["channelName"] as String
val userAccount = params["userAccount"] as String
callback.code(engine?.joinChannelWithUserAccount(token, channelName, userAccount))
}

override fun getUserInfoByUserAccount(params: Map<String, *>, callback: Callback) {
Expand Down Expand Up @@ -785,24 +792,20 @@ class RtcEngineManager(
}

override fun registerMediaMetadataObserver(callback: Callback) {
var code = -Constants.ERR_NOT_INITIALIZED
engine?.let {
val mediaObserver = MediaObserver { data ->
emit(RtcEngineEvents.MetadataReceived, data)
}
code = it.registerMediaMetadataObserver(mediaObserver, IMetadataObserver.VIDEO_METADATA)
if (code == 0) this.mediaObserver = mediaObserver
val mediaObserver = MediaObserver { data ->
emit(RtcEngineEvents.MetadataReceived, data)
}
callback.code(engine?.registerMediaMetadataObserver(mediaObserver, IMetadataObserver.VIDEO_METADATA)) {
this.mediaObserver = mediaObserver
Unit
}
callback.code(code)
}

override fun unregisterMediaMetadataObserver(callback: Callback) {
var code = -Constants.ERR_NOT_INITIALIZED
engine?.let {
code = it.registerMediaMetadataObserver(null, IMetadataObserver.VIDEO_METADATA)
if (code == 0) mediaObserver = null
callback.code(engine?.registerMediaMetadataObserver(null, IMetadataObserver.VIDEO_METADATA)) {
mediaObserver = null
Unit
}
callback.code(code)
}

override fun setMaxMetadataSize(params: Map<String, *>, callback: Callback) {
Expand Down Expand Up @@ -916,18 +919,10 @@ class RtcEngineManager(
}

override fun createDataStream(params: Map<String, *>, callback: Callback) {
var code = -Constants.ERR_NOT_INITIALIZED
engine?.let {
code = it.createDataStream(params["reliable"] as Boolean, params["ordered"] as Boolean)
}
callback.code(code) { it }
callback.code(engine?.createDataStream(params["reliable"] as Boolean, params["ordered"] as Boolean)) { it }
}

override fun sendStreamMessage(params: Map<String, *>, callback: Callback) {
var code = -Constants.ERR_NOT_INITIALIZED
engine?.let {
code = it.sendStreamMessage((params["streamId"] as Number).toInt(), (params["message"] as String).toByteArray())
}
callback.code(code)
callback.code(engine?.sendStreamMessage((params["streamId"] as Number).toInt(), (params["message"] as String).toByteArray()))
}
}

0 comments on commit df303ee

Please sign in to comment.