From 10a3d013c231c7e38e68b801b8734b64fc122c69 Mon Sep 17 00:00:00 2001 From: HUI <15215604969@163.com> Date: Thu, 30 Jul 2020 15:55:15 +0800 Subject: [PATCH] - fix multiple channel render bug - remove `Types` from export, you can import enum or class by `import {} from 'react-native-agora'` --- RtcSurfaceView.kt | 33 ++++++++++++++++++++------------- RtcTextureView.kt | 21 ++++++++++++++------- 2 files changed, 34 insertions(+), 20 deletions(-) diff --git a/RtcSurfaceView.kt b/RtcSurfaceView.kt index 891a0c7b2..d665d8143 100644 --- a/RtcSurfaceView.kt +++ b/RtcSurfaceView.kt @@ -46,14 +46,17 @@ class RtcSurfaceView( } } - fun setRenderMode(engine: RtcEngine, @Annotations.AgoraVideoRenderMode renderMode: Int) { - canvas.renderMode = renderMode - setupRenderMode(engine) - } + fun setData(engine: RtcEngine, channel: RtcChannel?, uid: Int) { + resetVideoCanvas(engine) - fun setChannel(engine: RtcEngine, channel: RtcChannel?) { this.channel = if (channel != null) WeakReference(channel) else null - canvas.channelId = channel?.channelId() + canvas.channelId = this.channel?.get()?.channelId() + canvas.uid = uid + setupVideoCanvas(engine) + } + + private fun resetVideoCanvas(engine: RtcEngine) { + val canvas = VideoCanvas(null, canvas.renderMode, canvas.channelId, canvas.uid, canvas.mirrorMode) if (canvas.uid == 0) { engine.setupLocalVideo(canvas) } else { @@ -61,13 +64,7 @@ class RtcSurfaceView( } } - fun setMirrorMode(engine: RtcEngine, @Annotations.AgoraVideoMirrorMode mirrorMode: Int) { - canvas.mirrorMode = mirrorMode - setupRenderMode(engine) - } - - fun setUid(engine: RtcEngine, uid: Int) { - canvas.uid = uid + private fun setupVideoCanvas(engine: RtcEngine) { if (canvas.uid == 0) { engine.setupLocalVideo(canvas) } else { @@ -75,6 +72,16 @@ class RtcSurfaceView( } } + fun setRenderMode(engine: RtcEngine, @Annotations.AgoraVideoRenderMode renderMode: Int) { + canvas.renderMode = renderMode + setupRenderMode(engine) + } + + fun setMirrorMode(engine: RtcEngine, @Annotations.AgoraVideoMirrorMode mirrorMode: Int) { + canvas.mirrorMode = mirrorMode + setupRenderMode(engine) + } + private fun setupRenderMode(engine: RtcEngine) { if (canvas.uid == 0) { engine.setLocalRenderMode(canvas.renderMode, canvas.mirrorMode) diff --git a/RtcTextureView.kt b/RtcTextureView.kt index e028b55c4..be98e356a 100644 --- a/RtcTextureView.kt +++ b/RtcTextureView.kt @@ -22,8 +22,11 @@ class RtcTextureView( addView(texture) } - fun setChannel(engine: RtcEngine, channel: RtcChannel?) { + fun setData(engine: RtcEngine, channel: RtcChannel?, uid: Int) { + resetVideoRender(engine) + this.channel = if (channel != null) WeakReference(channel) else null + this.uid = uid setupVideoRenderer(engine) } @@ -32,22 +35,26 @@ class RtcTextureView( setupVideoRenderer(engine) } - fun setUid(engine: RtcEngine, uid: Int) { - this.uid = uid - setupVideoRenderer(engine) + private fun resetVideoRender(engine: RtcEngine) { + if (uid == 0) { + engine.setLocalVideoRenderer(null) + } else { + channel?.get()?.let { + it.setRemoteVideoRenderer(uid, null) + return@resetVideoRender + } + engine.setRemoteVideoRenderer(uid, null) + } } 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) } }