@byteplus/react-native-rtc 1.1.1 → 1.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +88 -57
- package/android/build.gradle +23 -14
- package/android/proguard-rules.pro +1 -1
- package/android/src/live/java/com/volcengine/reactnative/vertc/live/VertcLive.java +76 -8
- package/android/src/main/java/com/volcengine/reactnative/vertc/NativeVariableManager.java +0 -5
- package/android/src/main/java/com/volcengine/reactnative/vertc/ScreenCaptureHelper.java +13 -18
- package/android/src/main/java/com/volcengine/reactnative/vertc/VertcApiEngineManager.java +5 -5
- package/android/src/main/java/com/volcengine/reactnative/vertc/VertcHelper.java +30 -0
- package/android/src/main/java/com/volcengine/reactnative/vertc/VertcImpl.java +68 -0
- package/android/src/main/java/com/volcengine/reactnative/vertc/events/ClassHelper.java +24 -3
- package/android/src/main/java/com/volcengine/reactnative/vertc/events/IRTCRoomEventHandlerImpl.java +90 -11
- package/android/src/main/java/com/volcengine/reactnative/vertc/events/IRTCVideoEventHandlerImpl.java +65 -4
- package/android/src/newarch/com/volcengine/reactnative/vertc/VertcModule.java +86 -0
- package/android/src/{main/java → oldarch}/com/volcengine/reactnative/vertc/VertcModule.java +11 -17
- package/ios/core/RTCHeader.h +1 -0
- package/ios/core/VertcHelper.h +9 -3
- package/ios/core/VertcHelper.m +72 -1
- package/ios/live/VertcLive.m +164 -12
- package/ios/new_arch_core/RCTVertc.h +23 -0
- package/ios/new_arch_core/RCTVertc.mm +89 -0
- package/ios/new_arch_core/VertcImpl.h +33 -0
- package/ios/new_arch_core/VertcImpl.m +53 -0
- package/ios/new_arch_core/VertcViewManager.m +51 -0
- package/lib/commonjs/index.js +1609 -806
- package/lib/module/index.js +1608 -808
- package/lib/typescript/codegen/android/api.d.ts +152 -8
- package/lib/typescript/codegen/android/callback.d.ts +13 -5
- package/lib/typescript/codegen/android/keytype.d.ts +105 -7
- package/lib/typescript/codegen/ios/api.d.ts +152 -16
- package/lib/typescript/codegen/ios/callback.d.ts +65 -5
- package/lib/typescript/codegen/ios/keytype.d.ts +171 -5
- package/lib/typescript/codegen/pack/api.d.ts +94 -83
- package/lib/typescript/codegen/pack/callback.d.ts +158 -40
- package/lib/typescript/codegen/pack/keytype.d.ts +121 -21
- package/lib/typescript/interface.d.ts +43 -10
- package/lib/typescript/module.d.ts +7 -0
- package/lib/typescript/platforms/android/vertc.d.ts +4 -1
- package/lib/typescript/platforms/ios/vertc.d.ts +2 -1
- package/lib/typescript/platforms/turboModule/NativeVertc.d.ts +26 -0
- package/lib/typescript/platforms/turboModule/index.d.ts +4 -0
- package/lib/typescript/proxy.d.ts +1 -1
- package/lib/typescript/util.d.ts +1 -0
- package/package.json +11 -2
- package/react-native-rtc.podspec +35 -31
- package/src/platforms/turboModule/NativeVertc.ts +33 -0
- package/src/platforms/turboModule/index.ts +1 -0
- /package/android/src/{main/java → oldarch}/com/volcengine/reactnative/vertc/VertcModuleSpec.java +0 -0
- /package/ios/{core → original_arch_core}/VertcModule.h +0 -0
- /package/ios/{core → original_arch_core}/VertcModule.m +0 -0
- /package/ios/{core → original_arch_core}/VertcViewManager.m +0 -0
package/README.md
CHANGED
|
@@ -1,92 +1,117 @@
|
|
|
1
1
|
# BytePlus React Native SDK
|
|
2
2
|
|
|
3
3
|
## Introduction
|
|
4
|
+
|
|
4
5
|
BytePlus React Native SDK is the audio and video call SDK provided by BytePlus for React Native.
|
|
5
6
|
|
|
6
7
|
## Minimum Requirements
|
|
8
|
+
|
|
7
9
|
Require Node >= 18.
|
|
8
10
|
|
|
9
|
-
| Platform | Version
|
|
10
|
-
|
|
|
11
|
-
| Android
|
|
12
|
-
| iOS
|
|
11
|
+
| Platform | Version |
|
|
12
|
+
| -------- | ------------ |
|
|
13
|
+
| Android | 6.0 (API 23) |
|
|
14
|
+
| iOS | 13.4 |
|
|
13
15
|
|
|
14
16
|
## Install
|
|
17
|
+
|
|
15
18
|
```shell
|
|
16
19
|
npm install @byteplus/react-native-rtc
|
|
17
20
|
```
|
|
21
|
+
|
|
18
22
|
```shell
|
|
19
23
|
yarn add @byteplus/react-native-rtc
|
|
20
24
|
```
|
|
21
25
|
|
|
26
|
+
## Attention
|
|
27
|
+
|
|
28
|
+
- In Android/iOS scenarios, the screen sharing method is slightly different. For details, please refer to [Android screen sharing](https://docs.byteplus.com/en/docs/byteplus-rtc/docs-124176) and [iOS screen sharing](https://docs.byteplus.com/en/docs/byteplus-rtc/docs-124177).
|
|
29
|
+
- Not support debug in iOS simulator, using real device instead.
|
|
30
|
+
- **If you need 16KB page size supported in Android or React Native New arch supported, please contact us for help, we will provide an offline sdk package.**
|
|
31
|
+
|
|
22
32
|
## Basic Example
|
|
23
33
|
|
|
24
34
|
### RTC Core Definition
|
|
35
|
+
|
|
25
36
|
`@/core/index.ts`
|
|
26
37
|
|
|
27
38
|
```typescript
|
|
28
39
|
import {
|
|
29
|
-
|
|
40
|
+
RTCManager,
|
|
41
|
+
IEngine,
|
|
42
|
+
IRoom,
|
|
43
|
+
RTCVideoEventHandler,
|
|
44
|
+
RTCRoomEventHandler,
|
|
45
|
+
IJoinRoomProps,
|
|
46
|
+
ICreateRTCEngineOptions,
|
|
30
47
|
} from '@byteplus/react-native-rtc';
|
|
31
48
|
|
|
32
49
|
class RTCClient {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
this.room?.setRTCRoomEventHandler(handlers);
|
|
50
|
-
}
|
|
51
|
-
startAudioCapture() {
|
|
52
|
-
return this.engine?.startAudioCapture();
|
|
53
|
-
}
|
|
54
|
-
startVideoCapture() {
|
|
55
|
-
return this.engine?.startVideoCapture();
|
|
56
|
-
}
|
|
57
|
-
destroyEngine() {
|
|
58
|
-
this.leaveRoom();
|
|
59
|
-
this.room?.destroy();
|
|
60
|
-
this.room = null;
|
|
61
|
-
this.manager!.destroyRTCEngine();
|
|
62
|
-
this.engine = null;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
/** Room related */
|
|
66
|
-
joinRoom(params: IJoinRoomProps) {
|
|
67
|
-
return this.room?.joinRoom({
|
|
68
|
-
token: 'Your token',
|
|
69
|
-
...params,
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
|
-
leaveRoom() {
|
|
73
|
-
this.effectPlayerUnloadAll();
|
|
74
|
-
this.stopScreenCapture();
|
|
75
|
-
this.room?.leaveRoom();
|
|
76
|
-
}
|
|
77
|
-
createRoom(roomId: string) {
|
|
78
|
-
this.room = this.engine?.createRTCRoom(roomId);
|
|
79
|
-
return this.room;
|
|
50
|
+
manager?: RTCManager;
|
|
51
|
+
engine?: IEngine | null;
|
|
52
|
+
room?: IRoom | null;
|
|
53
|
+
|
|
54
|
+
constructor() {
|
|
55
|
+
this.manager = new RTCManager();
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** Engine related */
|
|
59
|
+
async createEngine({appID}: ICreateRTCEngineOptions) {
|
|
60
|
+
this.engine = await this.manager!.createRTCEngine({appID});
|
|
61
|
+
}
|
|
62
|
+
setExtensionConfig() {
|
|
63
|
+
if (Platform.OS === 'ios') {
|
|
64
|
+
// https://docs.byteplus.com/en/docs/byteplus-rtc/docs-125721
|
|
65
|
+
return this.engine?.ios_setExtensionConfig("Your iOS App's Group ID");
|
|
80
66
|
}
|
|
67
|
+
}
|
|
68
|
+
setRTCVideoEventHandler(handlers: RTCVideoEventHandler) {
|
|
69
|
+
this.engine?.setRtcVideoEventHandler(handlers);
|
|
70
|
+
}
|
|
71
|
+
setRTCRoomEventHandler(handlers: RTCRoomEventHandler) {
|
|
72
|
+
this.room?.setRTCRoomEventHandler(handlers);
|
|
73
|
+
}
|
|
74
|
+
startAudioCapture() {
|
|
75
|
+
return this.engine?.startAudioCapture();
|
|
76
|
+
}
|
|
77
|
+
startVideoCapture() {
|
|
78
|
+
return this.engine?.startVideoCapture();
|
|
79
|
+
}
|
|
80
|
+
destroyEngine() {
|
|
81
|
+
this.leaveRoom();
|
|
82
|
+
this.room?.destroy();
|
|
83
|
+
this.room = null;
|
|
84
|
+
this.manager!.destroyRTCEngine();
|
|
85
|
+
this.engine = null;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/** Room related */
|
|
89
|
+
joinRoom(params: IJoinRoomProps) {
|
|
90
|
+
return this.room?.joinRoom({
|
|
91
|
+
token: 'Your token',
|
|
92
|
+
...params,
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
leaveRoom() {
|
|
96
|
+
this.effectPlayerUnloadAll();
|
|
97
|
+
this.stopScreenCapture();
|
|
98
|
+
this.room?.leaveRoom();
|
|
99
|
+
}
|
|
100
|
+
createRoom(roomId: string) {
|
|
101
|
+
this.room = this.engine?.createRTCRoom(roomId);
|
|
102
|
+
return this.room;
|
|
103
|
+
}
|
|
81
104
|
}
|
|
82
105
|
|
|
83
106
|
export default new RTCClient();
|
|
84
107
|
```
|
|
85
108
|
|
|
86
109
|
### JoinRoom Page
|
|
110
|
+
|
|
87
111
|
`@/page/login.tsx`
|
|
88
112
|
|
|
89
113
|
Mainly focus on the usage of `NativeViewComponent`. Note that after the component is registered, call `setLocalVideoCanvas` in `onLoad` to set the local rendering view. The same applies to remote users.
|
|
114
|
+
|
|
90
115
|
```typescript
|
|
91
116
|
import { Platform } from 'react-native';
|
|
92
117
|
import { request, PERMISSIONS } from 'react-native-permissions';
|
|
@@ -116,6 +141,11 @@ const Login = () => {
|
|
|
116
141
|
appID: 'Your appId',
|
|
117
142
|
});
|
|
118
143
|
|
|
144
|
+
if (Platform.OS === 'ios') {
|
|
145
|
+
/** Invoke `setExtensionConfig`, if you need to use screen sharing */
|
|
146
|
+
RTCClient.setExtensionConfig();
|
|
147
|
+
}
|
|
148
|
+
|
|
119
149
|
/** Set relative callbacks */
|
|
120
150
|
RTCClient.setRTCVideoEventHandler(...Your custom events);
|
|
121
151
|
|
|
@@ -134,9 +164,13 @@ const Login = () => {
|
|
|
134
164
|
|
|
135
165
|
/** Join room */
|
|
136
166
|
RTCClient.joinRoom({
|
|
167
|
+
token: 'Your RTC Token',
|
|
137
168
|
userId: localUser.userId,
|
|
138
|
-
|
|
139
|
-
|
|
169
|
+
roomConfigs: {
|
|
170
|
+
isAutoPublishVideo: true,
|
|
171
|
+
isAutoPublishAudio: true,
|
|
172
|
+
isAutoSubscribeAudio: true,
|
|
173
|
+
isAutoSubscribeVideo: true,
|
|
140
174
|
},
|
|
141
175
|
});
|
|
142
176
|
|
|
@@ -165,6 +199,3 @@ const Login = () => {
|
|
|
165
199
|
|
|
166
200
|
export default Login;
|
|
167
201
|
```
|
|
168
|
-
## Attention
|
|
169
|
-
- In Android/iOS scenarios, the screen sharing method is slightly different. For details, please refer to [Android screen sharing](https://docs.byteplus.com/en/docs/byteplus-rtc/docs-124176) and [iOS screen sharing](https://docs.byteplus.com/en/docs/byteplus-rtc/docs-124177).
|
|
170
|
-
- Not support debug in iOS simulator, using real device instead.
|
package/android/build.gradle
CHANGED
|
@@ -28,16 +28,20 @@ def isBp = parsedJson.name.startsWith("@byteplus")
|
|
|
28
28
|
|
|
29
29
|
def license_type = getLicenseType()
|
|
30
30
|
|
|
31
|
+
def liveVersionToUse
|
|
31
32
|
def rtcVersionToUse
|
|
32
33
|
if (isBp) {
|
|
33
|
-
rtcVersionToUse = enableUnionForRTCWithLive ? "3.58.1.
|
|
34
|
+
rtcVersionToUse = enableUnionForRTCWithLive ? "3.58.1.53300" : "3.58.1.52100"
|
|
35
|
+
liveVersionToUse = "1.47.300.2"
|
|
34
36
|
println "Using BytePlusRTC SDK version : $rtcVersionToUse (union live enabled: $enableUnionForRTCWithLive / union vod enabled: $enableUnionForRTCWithVod)"
|
|
35
37
|
} else {
|
|
36
|
-
rtcVersionToUse = enableUnionForRTCWithLive ? "3.58.1.
|
|
38
|
+
rtcVersionToUse = enableUnionForRTCWithLive ? "3.58.1.53200" : "3.58.1.55100"
|
|
39
|
+
liveVersionToUse = "1.47.3.6"
|
|
37
40
|
println "Using VolcEngineRTC SDK version : $rtcVersionToUse (union build enabled: $enableUnionForRTCWithLive / union vod enabled: $enableUnionForRTCWithVod)"
|
|
38
41
|
}
|
|
39
42
|
|
|
40
43
|
|
|
44
|
+
|
|
41
45
|
def isNewArchitectureEnabled() {
|
|
42
46
|
return rootProject.hasProperty("newArchEnabled") && rootProject.getProperty("newArchEnabled") == "true"
|
|
43
47
|
}
|
|
@@ -83,7 +87,9 @@ android {
|
|
|
83
87
|
minSdkVersion getExtOrIntegerDefault("minSdkVersion")
|
|
84
88
|
targetSdkVersion getExtOrIntegerDefault("targetSdkVersion")
|
|
85
89
|
|
|
86
|
-
consumerProguardFiles 'proguard-rules.pro'
|
|
90
|
+
consumerProguardFiles 'proguard-rules.pro'
|
|
91
|
+
|
|
92
|
+
buildConfigField("boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString())
|
|
87
93
|
}
|
|
88
94
|
|
|
89
95
|
buildTypes {
|
|
@@ -102,21 +108,29 @@ android {
|
|
|
102
108
|
}
|
|
103
109
|
}
|
|
104
110
|
|
|
105
|
-
def apiVolcEngineVersion = "1.6.
|
|
111
|
+
def apiVolcEngineVersion = "1.6.6";
|
|
112
|
+
|
|
113
|
+
if (isNewArchitectureEnabled()) {
|
|
114
|
+
println "Using new architecture"
|
|
115
|
+
android.sourceSets.main.java.srcDirs += 'src/newarch'
|
|
116
|
+
} else {
|
|
117
|
+
println "Using original architecture"
|
|
118
|
+
android.sourceSets.main.java.srcDirs += 'src/oldarch'
|
|
119
|
+
}
|
|
106
120
|
|
|
107
121
|
if (enableUnionForRTCWithLive) {
|
|
108
122
|
android.sourceSets.main.java.srcDirs += 'src/live/java'
|
|
109
123
|
dependencies {
|
|
110
124
|
implementation project(':byteplus_react-native-live-push')
|
|
111
|
-
implementation "com.bytedanceapi:ttsdk-player_$license_type
|
|
125
|
+
implementation "com.bytedanceapi:ttsdk-player_$license_type:$liveVersionToUse"
|
|
112
126
|
}
|
|
113
127
|
}
|
|
114
128
|
|
|
115
129
|
if (enableUnionForRTCWithVod) {
|
|
116
130
|
android.sourceSets.main.java.srcDirs += 'src/vod/java'
|
|
117
|
-
//
|
|
131
|
+
//
|
|
118
132
|
// Might cause rtc api some error, just alpha version.
|
|
119
|
-
//
|
|
133
|
+
//
|
|
120
134
|
apiVolcEngineVersion = '1.5.0'
|
|
121
135
|
dependencies {
|
|
122
136
|
implementation "com.bytedanceapi:ttsdk-player_$license_type:1.46.300.2"
|
|
@@ -124,13 +138,8 @@ if (enableUnionForRTCWithVod) {
|
|
|
124
138
|
}
|
|
125
139
|
|
|
126
140
|
dependencies {
|
|
127
|
-
// For < 0.71, this will be from the local maven repo
|
|
128
|
-
// For > 0.71, this will be replaced by `com.facebook.react:react-android:$version` by react gradle plugin
|
|
129
|
-
// noinspection GradleDynamicVersion
|
|
130
141
|
implementation "com.facebook.react:react-native:+"
|
|
131
|
-
|
|
132
142
|
implementation "com.volcengine:VolcApiEngine:$apiVolcEngineVersion"
|
|
143
|
+
implementation isBp ? "com.byteplus:BytePlusRTC:$rtcVersionToUse" : "com.volcengine:VolcEngineRTC:$rtcVersionToUse";
|
|
144
|
+
}
|
|
133
145
|
|
|
134
|
-
// Use the RTC SDK dependency determined by getNativeDep() which can be overridden by customer's app build.gradle.
|
|
135
|
-
implementation isBp ? "com.byteplus:BytePlusRTC:$rtcVersionToUse" : "com.volcengine:VolcEngineRTC:$rtcVersionToUse"
|
|
136
|
-
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# Add project specific ProGuard rules here.
|
|
1
|
+
# Add project specific ProGuard rules here.
|
|
2
2
|
# By default, the flags in this file are appended to flags specified
|
|
3
3
|
# in /usr/local/Cellar/android-sdk/24.3.3/tools/proguard/proguard-android.txt
|
|
4
4
|
# You can edit the include path and order by changing the proguardFiles
|
|
@@ -5,6 +5,7 @@ package com.volcengine.reactnative.vertc.live;
|
|
|
5
5
|
|
|
6
6
|
import android.util.Log;
|
|
7
7
|
|
|
8
|
+
import com.pandora.common.applog.AppLogWrapper;
|
|
8
9
|
import com.ss.avframework.live.VeLivePusherDef;
|
|
9
10
|
import com.ss.avframework.live.VeLiveVideoFrame;
|
|
10
11
|
import com.ss.avframework.opengl.RendererCommon;
|
|
@@ -18,6 +19,10 @@ import com.ss.bytertc.engine.data.VideoSourceType;
|
|
|
18
19
|
import java.util.concurrent.TimeUnit;
|
|
19
20
|
import com.ss.bytertc.engine.video.builder.GLTextureVideoFrameBuilder;
|
|
20
21
|
import com.volcengine.velive.rn.push.VeLivePushHelper;
|
|
22
|
+
import com.ss.avframework.live.filter.video.effect.CVEffectManager;
|
|
23
|
+
|
|
24
|
+
import org.json.JSONException;
|
|
25
|
+
import org.json.JSONObject;
|
|
21
26
|
|
|
22
27
|
import javax.annotation.Nonnull;
|
|
23
28
|
|
|
@@ -29,6 +34,30 @@ public class VertcLive {
|
|
|
29
34
|
private org.json.JSONObject mOptions;
|
|
30
35
|
private RTCVideo mEngine;
|
|
31
36
|
|
|
37
|
+
// 新增:VeLivePusherStatistics转字符串辅助方法
|
|
38
|
+
private String statisticsToString(VeLivePusherDef.VeLivePusherStatistics stats) {
|
|
39
|
+
if (stats == null) return "null";
|
|
40
|
+
return new StringBuilder()
|
|
41
|
+
.append("VeLivePusherStatistics{")
|
|
42
|
+
.append("url='").append(stats.url).append('\'')
|
|
43
|
+
.append(", encodeWidth=").append(stats.encodeWidth)
|
|
44
|
+
.append(", encodeHeight=").append(stats.encodeHeight)
|
|
45
|
+
.append(", captureWidth=").append(stats.captureWidth)
|
|
46
|
+
.append(", captureHeight=").append(stats.captureHeight)
|
|
47
|
+
.append(", captureFps=").append(stats.captureFps)
|
|
48
|
+
.append(", encodeFps=").append(stats.encodeFps)
|
|
49
|
+
.append(", transportFps=").append(stats.transportFps)
|
|
50
|
+
.append(", fps=").append(stats.fps)
|
|
51
|
+
.append(", videoBitrate=").append(stats.videoBitrate)
|
|
52
|
+
.append(", minVideoBitrate=").append(stats.minVideoBitrate)
|
|
53
|
+
.append(", maxVideoBitrate=").append(stats.maxVideoBitrate)
|
|
54
|
+
.append(", encodeVideoBitrate=").append(stats.encodeVideoBitrate)
|
|
55
|
+
.append(", transportVideoBitrate=").append(stats.transportVideoBitrate)
|
|
56
|
+
.append(", encodeAudioBitrate=").append(stats.encodeAudioBitrate)
|
|
57
|
+
.append(", codec=").append(stats.codec)
|
|
58
|
+
.append('}').toString();
|
|
59
|
+
}
|
|
60
|
+
|
|
32
61
|
/**
|
|
33
62
|
* @brief Start to capture live stream.
|
|
34
63
|
*/
|
|
@@ -43,7 +72,29 @@ public class VertcLive {
|
|
|
43
72
|
if (mLivePusher == null) {
|
|
44
73
|
throw new RuntimeException("[Unknown LivePusher] can't find pusher instance by view id.");
|
|
45
74
|
}
|
|
46
|
-
|
|
75
|
+
|
|
76
|
+
// mLivePusher.setStatisticsObserver(new VeLivePusherDef.VeLivePusherStatisticsObserver() {
|
|
77
|
+
// @Override
|
|
78
|
+
// public void onStatistics(VeLivePusherDef.VeLivePusherStatistics statistics) {
|
|
79
|
+
// String staticLog = statisticsToString(statistics);
|
|
80
|
+
// JSONObject json = new JSONObject();
|
|
81
|
+
// try {
|
|
82
|
+
// JSONObject jsonObject = new JSONObject();
|
|
83
|
+
// jsonObject.put("staticLog",staticLog);
|
|
84
|
+
// json.put("event_key", "livcore_statistics").put("message", jsonObject.toString()).put("effectcost", CVEffectManager.cvCostdurationMs+"ms");
|
|
85
|
+
// Log.d("flexttv>>>>> ", json.toString());
|
|
86
|
+
// } catch (JSONException e) {
|
|
87
|
+
// throw new RuntimeException(e);
|
|
88
|
+
// }
|
|
89
|
+
// AppLogWrapper.onEventV3("live_client_monitor_log",json);
|
|
90
|
+
// }
|
|
91
|
+
//
|
|
92
|
+
// @Override
|
|
93
|
+
// public void onLogMonitor(JSONObject logInfo) {
|
|
94
|
+
// VeLivePusherDef.VeLivePusherStatisticsObserver.super.onLogMonitor(logInfo);
|
|
95
|
+
// }
|
|
96
|
+
// }, 2);
|
|
97
|
+
|
|
47
98
|
// set video source as external
|
|
48
99
|
engine.setVideoSourceType(getStreamIndex(), VideoSourceType.VIDEO_SOURCE_TYPE_EXTERNAL);
|
|
49
100
|
// set video frame listener
|
|
@@ -53,12 +104,29 @@ public class VertcLive {
|
|
|
53
104
|
public VeLivePusherDef.VeLiveVideoFrameSource getObservedVideoFrameSource() {
|
|
54
105
|
return new VeLivePusherDef.VeLiveVideoFrameSource(VeLivePusherDef.VeLiveVideoFrameSource.VeLiveVideoFrameSourcePreEncode);
|
|
55
106
|
}
|
|
56
|
-
|
|
107
|
+
// private static final long INTERVAL_MS = 1000; // 计算间隔为1秒
|
|
108
|
+
// private long lastTime = 0;
|
|
109
|
+
// private int frameCount = 0;
|
|
57
110
|
@Override
|
|
58
111
|
public void onPreEncodeVideoFrame(VeLiveVideoFrame frame) {
|
|
59
112
|
int ret_status = -1;
|
|
60
113
|
StreamIndex streamIndex = getStreamIndex();
|
|
61
114
|
|
|
115
|
+
// long currentTime = System.currentTimeMillis();
|
|
116
|
+
// frameCount++;
|
|
117
|
+
//
|
|
118
|
+
// if (lastTime == 0) {
|
|
119
|
+
// lastTime = currentTime;
|
|
120
|
+
// }
|
|
121
|
+
//
|
|
122
|
+
// if (currentTime - lastTime >= INTERVAL_MS) {
|
|
123
|
+
// int fps = frameCount;
|
|
124
|
+
// Log.d("flexttv>>>>> FrameRateCalculator", "当前帧率: " + fps + " FPS");
|
|
125
|
+
// frameCount = 0;
|
|
126
|
+
// lastTime = currentTime;
|
|
127
|
+
// }
|
|
128
|
+
|
|
129
|
+
|
|
62
130
|
float[] mMVPMatrix = RendererCommon.convertMatrixFromAndroidGraphicsMatrix(frame.getTextureMatrix());
|
|
63
131
|
GLTextureVideoFrameBuilder builder = new GLTextureVideoFrameBuilder(
|
|
64
132
|
frame.isOesTextureFrame() ? VideoPixelFormat.TEXTURE_OES : VideoPixelFormat.TEXTURE_2D
|
|
@@ -70,7 +138,7 @@ public class VertcLive {
|
|
|
70
138
|
.setTextureMatrix(mMVPMatrix)
|
|
71
139
|
.setEGLContext(VeLivePusher.getEGLContext())
|
|
72
140
|
.setTimeStampUs(System.currentTimeMillis() * TimeUnit.MILLISECONDS.toNanos(1));
|
|
73
|
-
|
|
141
|
+
|
|
74
142
|
if (streamIndex == StreamIndex.STREAM_INDEX_MAIN) {
|
|
75
143
|
ret_status = engine.pushExternalVideoFrame(builder.build());
|
|
76
144
|
}
|
|
@@ -85,7 +153,7 @@ public class VertcLive {
|
|
|
85
153
|
}
|
|
86
154
|
};
|
|
87
155
|
mLivePusher.addVideoFrameListener(mListener);
|
|
88
|
-
|
|
156
|
+
|
|
89
157
|
return 0;
|
|
90
158
|
} catch (Exception err) {
|
|
91
159
|
Log.d(TAG, "startLiveVideoCapture failed:" + err.getMessage());
|
|
@@ -122,17 +190,17 @@ public class VertcLive {
|
|
|
122
190
|
}
|
|
123
191
|
}
|
|
124
192
|
|
|
125
|
-
|
|
193
|
+
|
|
126
194
|
// Get VeLivePusher from Object
|
|
127
195
|
private VeLivePusher getVeLivePusher(String pusherViewId) {
|
|
128
|
-
|
|
196
|
+
|
|
129
197
|
if (VeLivePushHelper.getPusher(pusherViewId) != null) {
|
|
130
198
|
return VeLivePushHelper.getPusher(pusherViewId);
|
|
131
199
|
}
|
|
132
|
-
|
|
200
|
+
|
|
133
201
|
return null;
|
|
134
202
|
}
|
|
135
|
-
|
|
203
|
+
|
|
136
204
|
// Get StreamIndex from options
|
|
137
205
|
private StreamIndex getStreamIndex() {
|
|
138
206
|
Number index = mOptions.optInt("streamIndex", StreamIndex.STREAM_INDEX_MAIN.value());
|
|
@@ -11,13 +11,8 @@ import com.volcengine.VolcApiEngine.runtime.*;
|
|
|
11
11
|
|
|
12
12
|
public class NativeVariableManager {
|
|
13
13
|
static void init(@NonNull MessageClient msgClient, ReactApplicationContext reactContext) {
|
|
14
|
-
var helper = new ScreenCaptureHelper(reactContext);
|
|
15
14
|
var m = msgClient.proto.variableManager;
|
|
16
|
-
|
|
17
15
|
m.registerVar("ApplicationContext", (Object[] args) -> reactContext.getApplicationContext());
|
|
18
16
|
m.registerVar("ReactApplicationContext", (Object[] args) -> reactContext);
|
|
19
|
-
m.registerVar("screenIntent", helper::getScreenIntent);
|
|
20
|
-
|
|
21
|
-
helper.setup();
|
|
22
17
|
}
|
|
23
18
|
}
|
|
@@ -20,23 +20,20 @@ import com.facebook.react.bridge.ActivityEventListener;
|
|
|
20
20
|
import com.facebook.react.bridge.ReactApplicationContext;
|
|
21
21
|
import com.ss.bytertc.base.media.screen.RXScreenCaptureService;
|
|
22
22
|
|
|
23
|
+
import java.util.function.Function;
|
|
24
|
+
|
|
23
25
|
public class ScreenCaptureHelper {
|
|
24
26
|
static final int SCREEN_RECORD_REQUEST_CODE = 1010;
|
|
27
|
+
static ReactApplicationContext reactApplicationContext;
|
|
25
28
|
|
|
26
|
-
private
|
|
29
|
+
private Function<Intent, Integer> mCallback;
|
|
27
30
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
ScreenCaptureHelper(ReactApplicationContext reactApplicationContext) {
|
|
31
|
-
this.reactApplicationContext = reactApplicationContext;
|
|
31
|
+
static public void registerReactApplicationContext(ReactApplicationContext context) {
|
|
32
|
+
reactApplicationContext = context;
|
|
32
33
|
}
|
|
33
34
|
|
|
34
|
-
ReactApplicationContext getReactApplicationContext() {
|
|
35
|
-
return this.reactApplicationContext;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
35
|
public void setup() {
|
|
39
|
-
|
|
36
|
+
ScreenCaptureHelper.reactApplicationContext.addActivityEventListener(new ActivityEventListener() {
|
|
40
37
|
@Override
|
|
41
38
|
public void onActivityResult(Activity activity, int requestCode, int resultCode, @Nullable Intent intent) {
|
|
42
39
|
if (requestCode != SCREEN_RECORD_REQUEST_CODE) {
|
|
@@ -46,7 +43,7 @@ public class ScreenCaptureHelper {
|
|
|
46
43
|
// success
|
|
47
44
|
if (resultCode == AppCompatActivity.RESULT_OK) {
|
|
48
45
|
if (mCallback != null) {
|
|
49
|
-
Context context =
|
|
46
|
+
Context context = ScreenCaptureHelper.reactApplicationContext;
|
|
50
47
|
Intent _intent = new Intent();
|
|
51
48
|
_intent.putExtra(RXScreenCaptureService.KEY_LARGE_ICON, R.drawable.launcher_quick_start);
|
|
52
49
|
_intent.putExtra(RXScreenCaptureService.KEY_SMALL_ICON, R.drawable.launcher_quick_start);
|
|
@@ -58,7 +55,7 @@ public class ScreenCaptureHelper {
|
|
|
58
55
|
} else {
|
|
59
56
|
context.startService(RXScreenCaptureService.getServiceIntent(context, RXScreenCaptureService.COMMAND_LAUNCH, _intent));
|
|
60
57
|
}
|
|
61
|
-
mCallback.
|
|
58
|
+
mCallback.apply(_intent);
|
|
62
59
|
mCallback = null;
|
|
63
60
|
}
|
|
64
61
|
return;
|
|
@@ -66,7 +63,6 @@ public class ScreenCaptureHelper {
|
|
|
66
63
|
|
|
67
64
|
// error
|
|
68
65
|
if (mCallback != null) {
|
|
69
|
-
mCallback.resolve(new Exception("permission error"), null);
|
|
70
66
|
mCallback = null;
|
|
71
67
|
}
|
|
72
68
|
}
|
|
@@ -77,14 +73,13 @@ public class ScreenCaptureHelper {
|
|
|
77
73
|
});
|
|
78
74
|
}
|
|
79
75
|
|
|
80
|
-
public void
|
|
76
|
+
public void registerIntentCallback(Function<Intent, Integer> cb) {
|
|
81
77
|
this.mCallback = cb;
|
|
82
|
-
this.requestPermission();
|
|
83
78
|
}
|
|
84
79
|
|
|
85
|
-
|
|
86
|
-
MediaProjectionManager mediaProjectionManager = (MediaProjectionManager)
|
|
80
|
+
public void getScreenIntent() {
|
|
81
|
+
MediaProjectionManager mediaProjectionManager = (MediaProjectionManager) ScreenCaptureHelper.reactApplicationContext.getSystemService(MEDIA_PROJECTION_SERVICE);
|
|
87
82
|
Intent permissionIntent = mediaProjectionManager.createScreenCaptureIntent();
|
|
88
|
-
|
|
83
|
+
ScreenCaptureHelper.reactApplicationContext.getCurrentActivity().startActivityForResult(permissionIntent, SCREEN_RECORD_REQUEST_CODE);
|
|
89
84
|
}
|
|
90
85
|
}
|
|
@@ -9,17 +9,17 @@ import com.volcengine.VolcApiEngine.VolcApiEngine;
|
|
|
9
9
|
public class VertcApiEngineManager implements IVeEngine {
|
|
10
10
|
static public VertcApiEngineManager instance = new VertcApiEngineManager();
|
|
11
11
|
|
|
12
|
-
public
|
|
12
|
+
public VertcImpl vertcImpl;
|
|
13
13
|
|
|
14
14
|
@Override
|
|
15
15
|
public VolcApiEngine getApiEngine() {
|
|
16
|
-
if (
|
|
16
|
+
if (vertcImpl == null) {
|
|
17
17
|
return null;
|
|
18
18
|
}
|
|
19
|
-
return
|
|
19
|
+
return vertcImpl.apiEngine;
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
public void init(
|
|
23
|
-
|
|
22
|
+
public void init(VertcImpl impl) {
|
|
23
|
+
vertcImpl = impl;
|
|
24
24
|
}
|
|
25
25
|
}
|
|
@@ -3,13 +3,17 @@
|
|
|
3
3
|
|
|
4
4
|
package com.volcengine.reactnative.vertc;
|
|
5
5
|
|
|
6
|
+
import android.content.Intent;
|
|
6
7
|
import android.util.Log;
|
|
7
8
|
|
|
9
|
+
import com.facebook.react.bridge.ReactApplicationContext;
|
|
8
10
|
import com.ss.bytertc.engine.RTCVideo;
|
|
9
11
|
import com.ss.bytertc.engine.VideoEncoderConfig;
|
|
10
12
|
import com.ss.bytertc.engine.data.MirrorType;
|
|
13
|
+
import com.ss.bytertc.engine.data.ScreenMediaType;
|
|
11
14
|
import com.ss.bytertc.engine.live.IPushSingleStreamToCDNObserver;
|
|
12
15
|
import com.ss.bytertc.engine.live.PushSingleStreamParam;
|
|
16
|
+
import com.ss.bytertc.engine.type.AudioSceneType;
|
|
13
17
|
|
|
14
18
|
public class VertcHelper {
|
|
15
19
|
|
|
@@ -34,4 +38,30 @@ public class VertcHelper {
|
|
|
34
38
|
};
|
|
35
39
|
return engine.startPushSingleStreamToCDN(taskId, param, observer);
|
|
36
40
|
}
|
|
41
|
+
|
|
42
|
+
public int invokeStartScreenCapture(RTCVideo engine, ScreenMediaType mediaType) {
|
|
43
|
+
try {
|
|
44
|
+
ScreenCaptureHelper helper = new ScreenCaptureHelper();
|
|
45
|
+
helper.registerIntentCallback((Intent intent) -> {
|
|
46
|
+
engine.startScreenCapture(mediaType, intent);
|
|
47
|
+
return 0;
|
|
48
|
+
});
|
|
49
|
+
helper.setup();
|
|
50
|
+
helper.getScreenIntent();
|
|
51
|
+
return 0;
|
|
52
|
+
} catch (Exception e) {
|
|
53
|
+
e.printStackTrace();
|
|
54
|
+
return -1;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
public int invokeSetAudioScene(RTCVideo engine, int scene) {
|
|
59
|
+
try {
|
|
60
|
+
AudioSceneType sceneType = AudioSceneType.fromId(scene);
|
|
61
|
+
return engine.setAudioScene(sceneType);
|
|
62
|
+
} catch (Exception e) {
|
|
63
|
+
e.printStackTrace();
|
|
64
|
+
return -1;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
37
67
|
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
// Copyright © 2022 BytePlusRTC All rights reserved.
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
4
|
+
package com.volcengine.reactnative.vertc;
|
|
5
|
+
|
|
6
|
+
import com.facebook.react.bridge.Callback;
|
|
7
|
+
import com.facebook.react.bridge.ReactApplicationContext;
|
|
8
|
+
import com.volcengine.VolcApiEngine.IEventReceiver;
|
|
9
|
+
import com.volcengine.VolcApiEngine.VolcApiEngine;
|
|
10
|
+
import com.volcengine.reactnative.vertc.events.ClassHelper;
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
public class VertcImpl {
|
|
14
|
+
|
|
15
|
+
public VolcApiEngine apiEngine = null;
|
|
16
|
+
private ReactApplicationContext moduleContext;
|
|
17
|
+
private IEventReceiver module;
|
|
18
|
+
|
|
19
|
+
public static final String NAME = "Vertc";
|
|
20
|
+
public static final String EVENT_NAME = "VertcModule:onEvent";
|
|
21
|
+
VertcImpl(ReactApplicationContext context, IEventReceiver module ) {
|
|
22
|
+
ClassHelper.init();
|
|
23
|
+
this.moduleContext = context;
|
|
24
|
+
this.module = module;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
public boolean newApiEngine() {
|
|
28
|
+
if (apiEngine == null) {
|
|
29
|
+
apiEngine = new VolcApiEngine(moduleContext, this.module);
|
|
30
|
+
NativeVariableManager.init(apiEngine.msgClient, moduleContext);
|
|
31
|
+
return true;
|
|
32
|
+
}
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
public String callApiSync(String params) {
|
|
37
|
+
try {
|
|
38
|
+
newApiEngine();
|
|
39
|
+
return this.apiEngine.callApi(params);
|
|
40
|
+
} catch (Exception e) {
|
|
41
|
+
e.printStackTrace();
|
|
42
|
+
throw new RuntimeException(e);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
public void callApi(String params, Callback callback) {
|
|
47
|
+
try {
|
|
48
|
+
newApiEngine();
|
|
49
|
+
// 获取主线程处理器
|
|
50
|
+
android.os.Handler mainHandler =
|
|
51
|
+
new android.os.Handler(android.os.Looper.getMainLooper());
|
|
52
|
+
|
|
53
|
+
// 在主线程上执行 API 调用
|
|
54
|
+
mainHandler.post(() -> {
|
|
55
|
+
try {
|
|
56
|
+
this.apiEngine.callApi(
|
|
57
|
+
params, (res) -> {
|
|
58
|
+
callback.invoke(res.toJsonString());
|
|
59
|
+
});
|
|
60
|
+
} catch (Exception e) {
|
|
61
|
+
e.printStackTrace();
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
} catch (Exception e) {
|
|
65
|
+
e.printStackTrace();
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|