Skip to content

Commit

Permalink
feat: example support switchRender
Browse files Browse the repository at this point in the history
fix: `RtcSurfaceView` memory leak #309
  • Loading branch information
LichKing-2234 committed Dec 15, 2020
1 parent 458c051 commit 155c1cb
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 13 deletions.
4 changes: 4 additions & 0 deletions example/ios/AgoraExample/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,12 @@
</dict>
</dict>
</dict>
<key>NSCameraUsageDescription</key>
<string>Camera</string>
<key>NSLocationWhenInUseUsageDescription</key>
<string></string>
<key>NSMicrophoneUsageDescription</key>
<string>Microphone</string>
<key>UILaunchStoryboardName</key>
<string>LaunchScreen</string>
<key>UIRequiredDeviceCapabilities</key>
Expand Down
46 changes: 34 additions & 12 deletions example/src/examples/basic/JoinChannelVideo.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
import React, { Component } from 'react';
import {
View,
TextInput,
PermissionsAndroid,
StyleSheet,
Button,
PermissionsAndroid,
Platform,
StyleSheet,
TextInput,
TouchableOpacity,
View,
} from 'react-native';

import RtcEngine, {
RtcLocalView,
RtcRemoteView,
ChannelProfile,
ClientRole,
RtcLocalView,
RtcRemoteView,
} from 'react-native-agora';

const config = require('../../../agora.config.json');
Expand All @@ -22,6 +23,7 @@ interface State {
isJoined: boolean;
remoteUid: number | undefined;
switchCamera: boolean;
switchRender: boolean;
}

export default class JoinChannelAudio extends Component<{}, State, any> {
Expand All @@ -33,7 +35,8 @@ export default class JoinChannelAudio extends Component<{}, State, any> {
channelId: config.channelId,
isJoined: false,
remoteUid: undefined,
switchCamera: false,
switchCamera: true,
switchRender: true,
};
}

Expand Down Expand Up @@ -107,6 +110,11 @@ export default class JoinChannelAudio extends Component<{}, State, any> {
});
};

_switchRender = () => {
const { switchRender } = this.state;
this.setState({ switchRender: !switchRender });
};

render() {
const { channelId, isJoined, switchCamera } = this.state;
return (
Expand Down Expand Up @@ -135,17 +143,31 @@ export default class JoinChannelAudio extends Component<{}, State, any> {
}

_renderVideo = () => {
const { remoteUid } = this.state;
const { remoteUid, switchRender } = this.state;
return (
<View style={styles.container}>
<RtcLocalView.SurfaceView style={styles.local} />
{remoteUid !== undefined && (
{switchRender ? (
<RtcLocalView.SurfaceView style={styles.local} />
) : (
<RtcRemoteView.SurfaceView
style={styles.remote}
uid={remoteUid}
style={styles.local}
uid={remoteUid!}
zOrderMediaOverlay={true}
/>
)}
{remoteUid !== undefined && (
<TouchableOpacity style={styles.remote} onPress={this._switchRender}>
{switchRender ? (
<RtcRemoteView.SurfaceView
style={styles.container}
uid={remoteUid}
zOrderMediaOverlay={true}
/>
) : (
<RtcLocalView.SurfaceView style={styles.container} />
)}
</TouchableOpacity>
)}
</View>
);
};
Expand Down
19 changes: 18 additions & 1 deletion ios/RCTAgora/React/RCTAgoraRtcSurfaceViewManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,22 @@
import Foundation
import AgoraRtcKit

fileprivate struct AssociatedKeys {
static var view: UInt8 = 0
}

@objc(AgoraRtcVideoCanvas)
public extension AgoraRtcVideoCanvas {
@objc weak var view: UIView? {
get {
return objc_getAssociatedObject(self, &AssociatedKeys.view) as? UIView
}
set {
objc_setAssociatedObject(self, &AssociatedKeys.view, newValue, .OBJC_ASSOCIATION_ASSIGN)
}
}
}

@objc(RCTAgoraRtcSurfaceViewManager)
class RCTAgoraRtcSurfaceViewManager: RCTViewManager {
override func view() -> UIView! {
Expand Down Expand Up @@ -39,8 +55,9 @@ class RCTAgoraRtcSurfaceViewManager: RCTViewManager {
class RtcView: RtcSurfaceView {
private var getEngine: (() -> AgoraRtcEngineKit?)?
private var getChannel: ((_ channelId: String) -> AgoraRtcChannel?)?

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

0 comments on commit 155c1cb

Please sign in to comment.