Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rc/3.1.+ #312

Merged
merged 4 commits into from
Dec 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
## [3.1.5](https://github.com/AgoraIO-Community/react-native-agora/compare/v3.1.4...v3.1.5) (2020-12-15)


### Bug Fixes

* `RtcSurfaceView` memory leak ([c8845fe](https://github.com/AgoraIO-Community/react-native-agora/commit/c8845fe04c1596fe2e7242302bf160bc671910cb))


### Features

* example support `switchRender` ([a6a509e](https://github.com/AgoraIO-Community/react-native-agora/commit/a6a509e273f64c67dce67fc61a9451d5b0ffeb70)), closes [#309](https://github.com/AgoraIO-Community/react-native-agora/issues/309)

## [3.1.4](https://github.com/AgoraIO-Community/react-native-agora/compare/v3.1.4-rc.1...v3.1.4) (2020-12-02)


Expand Down
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
1 change: 1 addition & 0 deletions ios/RCTAgora/Base/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.idea/
12 changes: 8 additions & 4 deletions ios/RCTAgora/Base/RtcSurfaceView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,36 +18,40 @@ class RtcSurfaceView: UIView {
}()
private weak var channel: AgoraRtcChannel?

func destroy() {
canvas.view = nil
}

func setData(_ engine: AgoraRtcEngineKit, _ channel: AgoraRtcChannel?, _ uid: Int) {
self.channel = channel
canvas.channelId = channel?.getId()
canvas.uid = UInt(uid)
setupVideoCanvas(engine)
}

func resetVideoCanvas(_ engine: AgoraRtcEngineKit) {
let canvas = AgoraRtcVideoCanvas()
canvas.view = nil
canvas.renderMode = self.canvas.renderMode
canvas.channelId = self.canvas.channelId
canvas.uid = self.canvas.uid
canvas.mirrorMode = self.canvas.mirrorMode

if canvas.uid == 0 {
engine.setupLocalVideo(canvas)
} else {
engine.setupRemoteVideo(canvas)
}
}

private func setupVideoCanvas(_ engine: AgoraRtcEngineKit) {
if canvas.uid == 0 {
engine.setupLocalVideo(canvas)
} else {
engine.setupRemoteVideo(canvas)
}
}

func setRenderMode(_ engine: AgoraRtcEngineKit, _ renderMode: Int) {
canvas.renderMode = AgoraVideoRenderMode(rawValue: UInt(renderMode))!
setupRenderMode(engine)
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
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.1.4",
"version": "3.1.5",
"description": "Agora RTC SDK For React Native",
"main": "lib/commonjs/index",
"module": "lib/module/index",
Expand Down