Skip to content

Commit

Permalink
- fix multiple channel render bug
Browse files Browse the repository at this point in the history
- remove `Types` from export, you can import enum or class by `import {} from 'react-native-agora'`
  • Loading branch information
LichKing-2234 committed Jul 30, 2020
1 parent d998401 commit 10a3d01
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 20 deletions.
33 changes: 20 additions & 13 deletions RtcSurfaceView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -46,35 +46,42 @@ 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 {
engine.setupRemoteVideo(canvas)
}
}

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 {
engine.setupRemoteVideo(canvas)
}
}

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)
Expand Down
21 changes: 14 additions & 7 deletions RtcTextureView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand All @@ -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)
}
}
Expand Down

0 comments on commit 10a3d01

Please sign in to comment.