Skip to content

Commit

Permalink
- fix crash when rendering view without channelId property
Browse files Browse the repository at this point in the history
- fix `RtcLocalView` freezes after rendering remote view
  • Loading branch information
LichKing-2234 committed Aug 4, 2020
1 parent e22238c commit c7feadc
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 15 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
## THE CHANGELOG

#### 3.0.1-rc.4
- fix crash when rendering view without `channelId` property
- fix `RtcLocalView` freezes after rendering remote view

#### 3.0.1-rc.3
- fix multiple channel render bug
- remove `Types` from export, you can import enum or class by `import {} from 'react-native-agora'`
Expand Down
4 changes: 1 addition & 3 deletions android/src/main/java/io/agora/rtc/base/RtcSurfaceView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,13 @@ class RtcSurfaceView(
}

fun setData(engine: RtcEngine, channel: RtcChannel?, uid: Int) {
resetVideoCanvas(engine)

this.channel = if (channel != null) WeakReference(channel) else null
canvas.channelId = this.channel?.get()?.channelId()
canvas.uid = uid
setupVideoCanvas(engine)
}

private fun resetVideoCanvas(engine: RtcEngine) {
fun resetVideoCanvas(engine: RtcEngine) {
val canvas = VideoCanvas(null, canvas.renderMode, canvas.channelId, canvas.uid, canvas.mirrorMode)
if (canvas.uid == 0) {
engine.setupLocalVideo(canvas)
Expand Down
4 changes: 1 addition & 3 deletions android/src/main/java/io/agora/rtc/base/RtcTextureView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ class RtcTextureView(
}

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 @@ -35,7 +33,7 @@ class RtcTextureView(
setupVideoRenderer(engine)
}

private fun resetVideoRender(engine: RtcEngine) {
fun resetVideoRender(engine: RtcEngine) {
if (uid == 0) {
engine.setLocalVideoRenderer(null)
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ class RCTAgoraRtcSurfaceViewManager : SimpleViewManager<RtcSurfaceView>() {
return RtcSurfaceView(reactContext)
}

override fun onDropViewInstance(view: RtcSurfaceView) {
// getEngine()?.let { view.resetVideoCanvas(it) }
super.onDropViewInstance(view)
}

override fun getName(): String {
return REACT_CLASS
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,19 @@ class RCTAgoraRtcTextureViewManager : SimpleViewManager<RtcTextureView>() {
return RtcTextureView(reactContext)
}

override fun onDropViewInstance(view: RtcTextureView) {
// getEngine()?.let { view.resetVideoRender(it) }
super.onDropViewInstance(view)
}

override fun getName(): String {
return REACT_CLASS
}

@ReactProp(name = "data")
fun setData(view: RtcTextureView, data: ReadableMap) {
val channel = data.getString("channelId")?.let { getChannel(it) }
getEngine()?.let {
view.setData(it, channel, data.getInt("uid"))
}
getEngine()?.let { view.setData(it, channel, data.getInt("uid")) }
}

@ReactProp(name = "mirror")
Expand Down
4 changes: 1 addition & 3 deletions ios/RCTAgora/Base/RtcSurfaceView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,13 @@ class RtcSurfaceView: UIView {
private weak var channel: AgoraRtcChannel?

func setData(_ engine: AgoraRtcEngineKit, _ channel: AgoraRtcChannel?, _ uid: Int) {
resetVideoCanvas(engine)

self.channel = channel
canvas.channelId = channel?.getId()
canvas.uid = UInt(uid)
setupVideoCanvas(engine)
}

private func resetVideoCanvas(_ engine: AgoraRtcEngineKit) {
func resetVideoCanvas(_ engine: AgoraRtcEngineKit) {
let canvas = AgoraRtcVideoCanvas()
canvas.view = nil
canvas.renderMode = self.canvas.renderMode
Expand Down
6 changes: 6 additions & 0 deletions ios/RCTAgora/React/RCTAgoraRtcSurfaceViewManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ class RtcView: RtcSurfaceView {
private var getEngine: (() -> AgoraRtcEngineKit?)?
private var getChannel: ((_ channelId: String) -> AgoraRtcChannel?)?

deinit {
// if let engine = getEngine?() {
// resetVideoCanvas(engine)
// }
}

func setEngine(_ getEngine: @escaping () -> AgoraRtcEngineKit?) {
self.getEngine = getEngine
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-native-agora",
"version": "3.0.1-rc.3",
"version": "3.0.1-rc.4",
"description": "React Native around the Agora RTC SDKs for Android and iOS agora",
"summary": "agora native sdk for react-native",
"main": "lib/index.js",
Expand Down
6 changes: 4 additions & 2 deletions src/src/RtcRenderView.native.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,10 @@ const RCTRtcSurfaceView = requireNativeComponent('RCTAgoraRtcSurfaceView');
*/
export class RtcSurfaceView extends Component<RtcSurfaceViewProps & RtcUidProps, {}> {
render() {
const {channelId, uid, ...others} = this.props
const {channelId = null, uid, ...others} = this.props
return (
<RCTRtcSurfaceView
key={`surface-${channelId}-${uid}`}
data={{channelId, uid}}
{...others}/>
)
Expand All @@ -88,9 +89,10 @@ const RCTRtcTextureView = requireNativeComponent('RCTAgoraRtcTextureView');
*/
export class RtcTextureView extends Component<RtcTextureViewProps & RtcUidProps, {}> {
render() {
const {channelId, uid, ...others} = this.props
const {channelId = null, uid, ...others} = this.props
return (
<RCTRtcTextureView
key={`texture-${channelId}-${uid}`}
data={{channelId, uid}}
{...others}/>
)
Expand Down

0 comments on commit c7feadc

Please sign in to comment.