@byteplus/react-native-live-push 1.0.0
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/LICENSE +21 -0
- package/README.md +2 -0
- package/android/build.gradle +92 -0
- package/android/gradle.properties +5 -0
- package/android/src/main/AndroidManifest.xml +16 -0
- package/android/src/main/AndroidManifestNew.xml +16 -0
- package/android/src/main/java/com/volcengine/velive/rn/push/ExternalSourceHelper.java +58 -0
- package/android/src/main/java/com/volcengine/velive/rn/push/NativeVariableManager.java +19 -0
- package/android/src/main/java/com/volcengine/velive/rn/push/ScreenCaptureHelper.java +73 -0
- package/android/src/main/java/com/volcengine/velive/rn/push/VeLivePushModule.java +182 -0
- package/android/src/main/java/com/volcengine/velive/rn/push/VeLivePushModuleSpec.java +16 -0
- package/android/src/main/java/com/volcengine/velive/rn/push/VeLivePushPackage.java +27 -0
- package/android/src/main/java/com/volcengine/velive/rn/push/VeLivePushView.java +45 -0
- package/android/src/main/java/com/volcengine/velive/rn/push/VeLivePushViewManager.java +87 -0
- package/ios/VeLivePushSDK.h +24 -0
- package/ios/VeLivePushSDK.m +109 -0
- package/ios/VeLivePushView.h +24 -0
- package/ios/VeLivePushView.m +74 -0
- package/ios/VeLivePushViewManager.m +59 -0
- package/lib/commonjs/index.js +24238 -0
- package/lib/module/index.js +24186 -0
- package/lib/typescript/android/index.d.ts +44 -0
- package/lib/typescript/codegen/android/api.d.ts +372 -0
- package/lib/typescript/codegen/android/callback.d.ts +91 -0
- package/lib/typescript/codegen/android/errorcode.d.ts +26 -0
- package/lib/typescript/codegen/android/index.d.ts +5 -0
- package/lib/typescript/codegen/android/keytype.d.ts +469 -0
- package/lib/typescript/codegen/android/types.d.ts +32 -0
- package/lib/typescript/codegen/ios/api.d.ts +257 -0
- package/lib/typescript/codegen/ios/callback.d.ts +88 -0
- package/lib/typescript/codegen/ios/errorcode.d.ts +54 -0
- package/lib/typescript/codegen/ios/index.d.ts +5 -0
- package/lib/typescript/codegen/ios/keytype.d.ts +488 -0
- package/lib/typescript/codegen/ios/types.d.ts +35 -0
- package/lib/typescript/codegen/pack/api.d.ts +1933 -0
- package/lib/typescript/codegen/pack/callback.d.ts +542 -0
- package/lib/typescript/codegen/pack/errorcode.d.ts +174 -0
- package/lib/typescript/codegen/pack/index.d.ts +5 -0
- package/lib/typescript/codegen/pack/keytype.d.ts +1952 -0
- package/lib/typescript/codegen/pack/types.d.ts +1 -0
- package/lib/typescript/codegen/type-shim.d.ts +6 -0
- package/lib/typescript/component.d.ts +8 -0
- package/lib/typescript/core/api.d.ts +2 -0
- package/lib/typescript/core/callback.d.ts +2 -0
- package/lib/typescript/core/env.d.ts +29 -0
- package/lib/typescript/core/errorcode.d.ts +2 -0
- package/lib/typescript/core/index.d.ts +6 -0
- package/lib/typescript/core/keytype.d.ts +7 -0
- package/lib/typescript/core/pusher.d.ts +16 -0
- package/lib/typescript/index.d.ts +2 -0
- package/lib/typescript/ios/extends.d.ts +41 -0
- package/lib/typescript/runtime.d.ts +1 -0
- package/package.json +31 -0
- package/react-native-velive-push.podspec +45 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright 2024 Beijing Volcano Engine Technology Co., Ltd.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
buildscript {
|
|
2
|
+
repositories {
|
|
3
|
+
google()
|
|
4
|
+
mavenCentral()
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
dependencies {
|
|
8
|
+
classpath "com.android.tools.build:gradle:7.2.1"
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
def isNewArchitectureEnabled() {
|
|
13
|
+
return rootProject.hasProperty("newArchEnabled") && rootProject.getProperty("newArchEnabled") == "true"
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
apply plugin: "com.android.library"
|
|
17
|
+
apply from: "https://ve-vos.volccdn.com/script/vevos-repo-base.gradle"
|
|
18
|
+
|
|
19
|
+
if (isNewArchitectureEnabled()) {
|
|
20
|
+
apply plugin: "com.facebook.react"
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
def getExtOrDefault(name) {
|
|
24
|
+
return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties["LivePull_" + name]
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
def getExtOrIntegerDefault(name) {
|
|
28
|
+
return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties["LivePull_" + name]).toInteger()
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
def supportsNamespace() {
|
|
32
|
+
def parsed = com.android.Version.ANDROID_GRADLE_PLUGIN_VERSION.tokenize('.')
|
|
33
|
+
def major = parsed[0].toInteger()
|
|
34
|
+
def minor = parsed[1].toInteger()
|
|
35
|
+
|
|
36
|
+
// Namespace support was added in 7.3.0
|
|
37
|
+
return (major == 7 && minor >= 3) || major >= 8
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
android {
|
|
41
|
+
if (supportsNamespace()) {
|
|
42
|
+
namespace "com.volcengine.velive.rn.push"
|
|
43
|
+
|
|
44
|
+
sourceSets {
|
|
45
|
+
main {
|
|
46
|
+
manifest.srcFile "src/main/AndroidManifestNew.xml"
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
compileSdkVersion getExtOrIntegerDefault("compileSdkVersion")
|
|
52
|
+
|
|
53
|
+
defaultConfig {
|
|
54
|
+
minSdkVersion getExtOrIntegerDefault("minSdkVersion")
|
|
55
|
+
targetSdkVersion getExtOrIntegerDefault("targetSdkVersion")
|
|
56
|
+
|
|
57
|
+
consumerProguardFiles 'proguard-rules.pro'
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
buildTypes {
|
|
61
|
+
release {
|
|
62
|
+
minifyEnabled false
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
lintOptions {
|
|
67
|
+
disable "GradleCompatible"
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
compileOptions {
|
|
71
|
+
sourceCompatibility JavaVersion.VERSION_1_8
|
|
72
|
+
targetCompatibility JavaVersion.VERSION_1_8
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
repositories {
|
|
77
|
+
mavenCentral()
|
|
78
|
+
google()
|
|
79
|
+
maven {
|
|
80
|
+
url "https://artifact.bytedance.com/repository/Volcengine/" // volc public maven repo
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
dependencies {
|
|
86
|
+
// For < 0.71, this will be from the local maven repo
|
|
87
|
+
// For > 0.71, this will be replaced by `com.facebook.react:react-android:$version` by react gradle plugin
|
|
88
|
+
//noinspection GradleDynamicVersion
|
|
89
|
+
implementation "com.facebook.react:react-native:+"
|
|
90
|
+
implementation "com.volcengine:VolcApiEngine:1.0.1"
|
|
91
|
+
implementation 'com.bytedanceapi:ttsdk-ttlivepush_rtc:1.41.3.4'
|
|
92
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
|
2
|
+
package="com.volcengine.velive.rn.push">
|
|
3
|
+
|
|
4
|
+
<uses-permission android:name="android.permission.CAMERA" />
|
|
5
|
+
<uses-permission android:name="android.permission.RECORD_AUDIO" />
|
|
6
|
+
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
|
|
7
|
+
<uses-permission android:name="android.permission.INTERNET" />
|
|
8
|
+
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
|
9
|
+
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
|
|
10
|
+
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
|
|
11
|
+
<uses-permission android:name="android.permission.RECEIVE_USER_PRESENT" />
|
|
12
|
+
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
|
13
|
+
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
|
|
14
|
+
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
|
|
15
|
+
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
|
|
16
|
+
</manifest>
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
|
2
|
+
|
|
3
|
+
<uses-permission android:name="android.permission.CAMERA" />
|
|
4
|
+
<uses-permission android:name="android.permission.RECORD_AUDIO" />
|
|
5
|
+
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
|
|
6
|
+
<uses-permission android:name="android.permission.INTERNET" />
|
|
7
|
+
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
|
8
|
+
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
|
|
9
|
+
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
|
|
10
|
+
<uses-permission android:name="android.permission.RECEIVE_USER_PRESENT" />
|
|
11
|
+
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
|
12
|
+
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
|
|
13
|
+
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
|
|
14
|
+
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
|
|
15
|
+
|
|
16
|
+
</manifest>
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
package com.volcengine.velive.rn.push;
|
|
2
|
+
|
|
3
|
+
import com.facebook.react.bridge.ReadableMap;
|
|
4
|
+
import com.ss.avframework.live.VeLiveAudioFrame;
|
|
5
|
+
import com.ss.avframework.live.VeLivePusher;
|
|
6
|
+
|
|
7
|
+
import java.util.HashMap;
|
|
8
|
+
|
|
9
|
+
public class ExternalSourceHelper {
|
|
10
|
+
interface IExternalFrameTask {
|
|
11
|
+
void onStart(VeLivePusher pusher, ReadableMap info);
|
|
12
|
+
void onStop();
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
static HashMap<Integer, ExternalFrameTask> Tasks = new HashMap<>();
|
|
16
|
+
|
|
17
|
+
static class ExternalFrameTask {
|
|
18
|
+
static public int TASK_ID = 1;
|
|
19
|
+
|
|
20
|
+
private final IExternalFrameTask impl;
|
|
21
|
+
private final VeLivePusher pusher;
|
|
22
|
+
private final ReadableMap arg;
|
|
23
|
+
public final int taskId;
|
|
24
|
+
|
|
25
|
+
ExternalFrameTask(IExternalFrameTask impl, VeLivePusher pusher, int fps, ReadableMap arg) {
|
|
26
|
+
this.impl = impl;
|
|
27
|
+
this.pusher = pusher;
|
|
28
|
+
this.arg = arg;
|
|
29
|
+
this.taskId = TASK_ID++;
|
|
30
|
+
|
|
31
|
+
Tasks.put(taskId, this);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
public void start() {
|
|
35
|
+
this.impl.onStart(pusher, arg);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
public void stop() {
|
|
39
|
+
this.impl.onStop();
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
public ExternalFrameTask startPushExternalVideoFrame(VeLivePusher pusher, String implClassName, ReadableMap arg) {
|
|
44
|
+
try {
|
|
45
|
+
Class<?> clazz = Class.forName(implClassName);
|
|
46
|
+
Object impl = clazz.newInstance();
|
|
47
|
+
var t = new ExternalFrameTask((IExternalFrameTask) impl, pusher, 30, arg);
|
|
48
|
+
t.start();
|
|
49
|
+
return t;
|
|
50
|
+
} catch (ClassNotFoundException e) {
|
|
51
|
+
throw new RuntimeException("unknown class " + implClassName);
|
|
52
|
+
} catch (IllegalAccessException e) {
|
|
53
|
+
throw new RuntimeException("class " + implClassName + " should impl IExternalFrameTask");
|
|
54
|
+
} catch (InstantiationException e) {
|
|
55
|
+
throw new RuntimeException("class " + implClassName + " should new with empty args");
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
package com.volcengine.velive.rn.push;
|
|
2
|
+
|
|
3
|
+
import androidx.annotation.NonNull;
|
|
4
|
+
|
|
5
|
+
import com.facebook.react.bridge.ReactApplicationContext;
|
|
6
|
+
import com.volcengine.VolcApiEngine.runtime.*;
|
|
7
|
+
|
|
8
|
+
public class NativeVariableManager {
|
|
9
|
+
static void init(@NonNull VolcApiEngine apiEngine, ReactApplicationContext reactContext) {
|
|
10
|
+
var m = apiEngine.msgClient.proto.variableManager;
|
|
11
|
+
|
|
12
|
+
m.registerVar("ApplicationContext", (Object[] args) -> reactContext.getApplicationContext());
|
|
13
|
+
m.registerVar("ReactApplicationContext", (Object[] args) -> reactContext);
|
|
14
|
+
|
|
15
|
+
var helper = new ScreenCaptureHelper(reactContext);
|
|
16
|
+
m.registerVar("screenIntent", helper::getScreenIntent);
|
|
17
|
+
helper.setup();
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
package com.volcengine.velive.rn.push;
|
|
2
|
+
|
|
3
|
+
import static android.content.Context.MEDIA_PROJECTION_SERVICE;
|
|
4
|
+
|
|
5
|
+
import static com.volcengine.VolcApiEngine.runtime.NativeVariableManager.*;
|
|
6
|
+
|
|
7
|
+
import android.app.Activity;
|
|
8
|
+
import android.content.Intent;
|
|
9
|
+
import android.media.projection.MediaProjectionManager;
|
|
10
|
+
|
|
11
|
+
import androidx.annotation.NonNull;
|
|
12
|
+
import androidx.annotation.Nullable;
|
|
13
|
+
import androidx.appcompat.app.AppCompatActivity;
|
|
14
|
+
|
|
15
|
+
import com.facebook.react.bridge.ActivityEventListener;
|
|
16
|
+
import com.facebook.react.bridge.ReactApplicationContext;
|
|
17
|
+
|
|
18
|
+
public class ScreenCaptureHelper {
|
|
19
|
+
static final int SCREEN_RECORD_REQUEST_CODE = 1010;
|
|
20
|
+
|
|
21
|
+
private final ReactApplicationContext reactApplicationContext;
|
|
22
|
+
|
|
23
|
+
private AsyncVariableGetterCallback<Intent> mCallback;
|
|
24
|
+
|
|
25
|
+
ScreenCaptureHelper(ReactApplicationContext reactApplicationContext) {
|
|
26
|
+
this.reactApplicationContext = reactApplicationContext;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
ReactApplicationContext getReactApplicationContext() {
|
|
30
|
+
return this.reactApplicationContext;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
public void setup() {
|
|
34
|
+
getReactApplicationContext().addActivityEventListener(new ActivityEventListener() {
|
|
35
|
+
@Override
|
|
36
|
+
public void onActivityResult(Activity activity, int requestCode, int resultCode, @Nullable Intent intent) {
|
|
37
|
+
if (requestCode != SCREEN_RECORD_REQUEST_CODE) {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// success
|
|
42
|
+
if (resultCode == AppCompatActivity.RESULT_OK) {
|
|
43
|
+
if (mCallback != null) {
|
|
44
|
+
mCallback.resolve(null, intent);
|
|
45
|
+
mCallback = null;
|
|
46
|
+
}
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// error
|
|
51
|
+
if (mCallback != null) {
|
|
52
|
+
mCallback.resolve(new Exception("permission error"), null);
|
|
53
|
+
mCallback = null;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
@Override
|
|
58
|
+
public void onNewIntent(Intent intent) {
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
public void getScreenIntent(Object[] args, @NonNull AsyncVariableGetterCallback cb) {
|
|
64
|
+
this.mCallback = cb;
|
|
65
|
+
this.requestPermission();
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
private void requestPermission() {
|
|
69
|
+
MediaProjectionManager mediaProjectionManager = (MediaProjectionManager) getReactApplicationContext().getSystemService(MEDIA_PROJECTION_SERVICE);
|
|
70
|
+
Intent permissionIntent = mediaProjectionManager.createScreenCaptureIntent();
|
|
71
|
+
getReactApplicationContext().getCurrentActivity().startActivityForResult(permissionIntent, SCREEN_RECORD_REQUEST_CODE);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
package com.volcengine.velive.rn.push;
|
|
2
|
+
|
|
3
|
+
import static com.volcengine.VolcApiEngine.runtime.Util.JsonAbleClass;
|
|
4
|
+
|
|
5
|
+
import android.util.Log;
|
|
6
|
+
|
|
7
|
+
import androidx.annotation.Nullable;
|
|
8
|
+
|
|
9
|
+
import com.facebook.react.bridge.Arguments;
|
|
10
|
+
import com.facebook.react.bridge.Callback;
|
|
11
|
+
import com.facebook.react.bridge.ReactApplicationContext;
|
|
12
|
+
import com.facebook.react.bridge.ReactContext;
|
|
13
|
+
import com.facebook.react.bridge.ReactMethod;
|
|
14
|
+
import com.facebook.react.bridge.ReadableMap;
|
|
15
|
+
import com.facebook.react.bridge.WritableMap;
|
|
16
|
+
import com.facebook.react.modules.core.DeviceEventManagerModule;
|
|
17
|
+
|
|
18
|
+
import com.ss.avframework.live.VeLivePusherConfiguration;
|
|
19
|
+
import com.ss.avframework.live.VeLivePusherDef;
|
|
20
|
+
import com.ss.avframework.live.VeLivePusherObserver;
|
|
21
|
+
import com.volcengine.VolcApiEngine.runtime.*;
|
|
22
|
+
import com.volcengine.VolcApiEngine.view.*;
|
|
23
|
+
|
|
24
|
+
public class VeLivePushModule extends VeLivePushModuleSpec implements IEventReceiver {
|
|
25
|
+
static {
|
|
26
|
+
JsonAbleClass.add(VeLivePusherDef.VeLivePusherStatistics.class);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
VolcApiEngine apiEngine = null;
|
|
30
|
+
|
|
31
|
+
VeLivePushModule(ReactApplicationContext context) {
|
|
32
|
+
super(context);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
@Override
|
|
36
|
+
public String getName() {
|
|
37
|
+
return "VeLivePushModule";
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
@ReactMethod(isBlockingSynchronousMethod = true)
|
|
41
|
+
public boolean newApiEngine() {
|
|
42
|
+
if (apiEngine == null) {
|
|
43
|
+
apiEngine = new VolcApiEngine(getReactApplicationContext(), this);
|
|
44
|
+
|
|
45
|
+
NativeVariableManager.init(apiEngine, super.context);
|
|
46
|
+
return true;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
@ReactMethod(isBlockingSynchronousMethod = true)
|
|
53
|
+
public boolean destroyApiEngine() {
|
|
54
|
+
if (apiEngine != null) {
|
|
55
|
+
apiEngine.msgClient.proto.dispose();
|
|
56
|
+
apiEngine = null;
|
|
57
|
+
}
|
|
58
|
+
return true;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
@ReactMethod(isBlockingSynchronousMethod = true)
|
|
62
|
+
public String callApiSync(ReadableMap arg) {
|
|
63
|
+
try {
|
|
64
|
+
newApiEngine();
|
|
65
|
+
String params = arg.getString("params");
|
|
66
|
+
return this.apiEngine.callApi(params);
|
|
67
|
+
} catch (Exception e) {
|
|
68
|
+
e.printStackTrace();
|
|
69
|
+
throw new RuntimeException(e);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
@ReactMethod(isBlockingSynchronousMethod = false)
|
|
74
|
+
public void callApi(ReadableMap arg, Callback callback) {
|
|
75
|
+
try {
|
|
76
|
+
newApiEngine();
|
|
77
|
+
String params = arg.getString("params");
|
|
78
|
+
this.apiEngine.callApi(params, (res) -> {
|
|
79
|
+
callback.invoke(res.toJsonString());
|
|
80
|
+
});
|
|
81
|
+
} catch (Exception e) {
|
|
82
|
+
e.printStackTrace();
|
|
83
|
+
throw new RuntimeException(e);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
private int listenerCount = 0;
|
|
88
|
+
|
|
89
|
+
@ReactMethod
|
|
90
|
+
public void addListener(String eventName) {
|
|
91
|
+
if (listenerCount == 0) {
|
|
92
|
+
// Set up any upstream listeners or background tasks as necessary
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
listenerCount += 1;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
@ReactMethod
|
|
99
|
+
public void removeListeners(Integer count) {
|
|
100
|
+
listenerCount -= count;
|
|
101
|
+
if (listenerCount == 0) {
|
|
102
|
+
// Remove upstream listeners, stop unnecessary background tasks
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
private void sendEvent(ReactContext reactContext,
|
|
107
|
+
String eventName,
|
|
108
|
+
@Nullable WritableMap params) {
|
|
109
|
+
reactContext
|
|
110
|
+
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
|
|
111
|
+
.emit(eventName, params);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
@Override
|
|
115
|
+
public void OnEvent(String event, String data) {
|
|
116
|
+
final WritableMap map = Arguments.createMap();
|
|
117
|
+
map.putString("event", event);
|
|
118
|
+
map.putString("data", data);
|
|
119
|
+
|
|
120
|
+
getReactApplicationContext()
|
|
121
|
+
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
|
|
122
|
+
.emit(VeLivePushModuleSpec.EVENT, map);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
@ReactMethod(isBlockingSynchronousMethod = false)
|
|
126
|
+
public void test() {
|
|
127
|
+
VeLivePusherConfiguration config = new VeLivePusherConfiguration();
|
|
128
|
+
config.setContext(this.getReactApplicationContext());
|
|
129
|
+
config.setReconnectCount(10);
|
|
130
|
+
|
|
131
|
+
var mLivePusher = config.build();
|
|
132
|
+
mLivePusher.setObserver(new VeLivePusherObserver() {
|
|
133
|
+
@Override
|
|
134
|
+
public void onAudioPowerQuality(VeLivePusherDef.VeLiveAudioPowerLevel level, float value) {
|
|
135
|
+
Log.d("VeLivePusherObserver", "onAudioPowerQuality");
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
@Override
|
|
139
|
+
public void onNetworkQuality(VeLivePusherDef.VeLiveNetworkQuality quality) {
|
|
140
|
+
Log.d("VeLivePusherObserver", "onNetworkQuality");
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
@Override
|
|
144
|
+
public void onScreenRecording(boolean open) {
|
|
145
|
+
Log.d("VeLivePusherObserver", "onScreenRecording");
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
@Override
|
|
149
|
+
public void onMicrophoneOpened(boolean open) {
|
|
150
|
+
Log.d("VeLivePusherObserver", "onMicrophoneOpened");
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
@Override
|
|
154
|
+
public void onCameraOpened(boolean open) {
|
|
155
|
+
Log.d("VeLivePusherObserver", "onCameraOpened");
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
@Override
|
|
159
|
+
public void onFirstAudioFrame(VeLivePusherDef.VeLiveFirstFrameType type, long timestampMs) {
|
|
160
|
+
Log.d("VeLivePusherObserver", "onFirstAudioFrame");
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
@Override
|
|
164
|
+
public void onFirstVideoFrame(VeLivePusherDef.VeLiveFirstFrameType type, long timestampMs) {
|
|
165
|
+
Log.d("VeLivePusherObserver", "onFirstVideoFrame");
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
@Override
|
|
169
|
+
public void onStatusChange(VeLivePusherDef.VeLivePusherStatus status) {
|
|
170
|
+
Log.d("VeLivePusherObserver", "onStatusChange");
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
@Override
|
|
174
|
+
public void onError(int code, int subCode, String msg) {
|
|
175
|
+
Log.d("VeLivePusherObserver", "onError");
|
|
176
|
+
}
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
mLivePusher.setRenderView(VolcViewManager.getViewById("live-pusher"));
|
|
180
|
+
mLivePusher.startVideoCapture(VeLivePusherDef.VeLiveVideoCaptureType.VeLiveVideoCaptureFrontCamera);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
package com.volcengine.velive.rn.push;
|
|
2
|
+
|
|
3
|
+
import com.facebook.react.bridge.ReactApplicationContext;
|
|
4
|
+
import com.facebook.react.bridge.ReactContextBaseJavaModule;
|
|
5
|
+
|
|
6
|
+
public abstract class VeLivePushModuleSpec extends ReactContextBaseJavaModule {
|
|
7
|
+
static final String EVENT = "VeLivePush:onEvent";
|
|
8
|
+
protected final ReactApplicationContext context;
|
|
9
|
+
|
|
10
|
+
VeLivePushModuleSpec(ReactApplicationContext context) {
|
|
11
|
+
super(context);
|
|
12
|
+
this.context = context;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
public abstract void OnEvent(String eventName, String data);
|
|
16
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
package com.volcengine.velive.rn.push;
|
|
2
|
+
|
|
3
|
+
import com.facebook.react.ReactPackage;
|
|
4
|
+
import com.facebook.react.bridge.NativeModule;
|
|
5
|
+
import com.facebook.react.bridge.ReactApplicationContext;
|
|
6
|
+
import com.facebook.react.uimanager.ViewManager;
|
|
7
|
+
|
|
8
|
+
import java.util.ArrayList;
|
|
9
|
+
import java.util.List;
|
|
10
|
+
|
|
11
|
+
public class VeLivePushPackage implements ReactPackage {
|
|
12
|
+
@Override
|
|
13
|
+
public List<ViewManager> createViewManagers(ReactApplicationContext reactContext) {
|
|
14
|
+
List<ViewManager> viewManagers = new ArrayList<>();
|
|
15
|
+
viewManagers.add(new VeLivePushViewManager());
|
|
16
|
+
return viewManagers;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
@Override
|
|
20
|
+
public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) {
|
|
21
|
+
List<NativeModule> modules = new ArrayList<>();
|
|
22
|
+
|
|
23
|
+
modules.add(new VeLivePushModule(reactContext));
|
|
24
|
+
|
|
25
|
+
return modules;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
package com.volcengine.velive.rn.push;
|
|
2
|
+
|
|
3
|
+
import android.content.Context;
|
|
4
|
+
import android.util.Log;
|
|
5
|
+
import android.view.SurfaceView;
|
|
6
|
+
import android.view.View;
|
|
7
|
+
import android.widget.FrameLayout;
|
|
8
|
+
|
|
9
|
+
import com.facebook.react.bridge.Arguments;
|
|
10
|
+
import com.facebook.react.bridge.ReactContext;
|
|
11
|
+
import com.facebook.react.bridge.WritableMap;
|
|
12
|
+
import com.facebook.react.uimanager.events.RCTEventEmitter;
|
|
13
|
+
|
|
14
|
+
public class VeLivePushView extends FrameLayout {
|
|
15
|
+
public String viewId;
|
|
16
|
+
public boolean hasRegister = false;
|
|
17
|
+
|
|
18
|
+
public VeLivePushView(Context context) {
|
|
19
|
+
super(context);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
public void setViewId(String viewId) {
|
|
23
|
+
this.viewId = viewId;
|
|
24
|
+
this.hasRegister = true;
|
|
25
|
+
this.emitOnLoad();
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
public void setVisible(Boolean visible) {
|
|
29
|
+
Log.i("surfaceView", "setVisible");
|
|
30
|
+
View subview = this.getChildAt(0);
|
|
31
|
+
if(visible) {
|
|
32
|
+
subview.setVisibility(View.VISIBLE);
|
|
33
|
+
} else {
|
|
34
|
+
subview.setVisibility(View.INVISIBLE);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
public void emitOnLoad() {
|
|
39
|
+
WritableMap event = Arguments.createMap();
|
|
40
|
+
ReactContext reactContext = (ReactContext)getContext();
|
|
41
|
+
reactContext
|
|
42
|
+
.getJSModule(RCTEventEmitter.class)
|
|
43
|
+
.receiveEvent(getId(), "load", event);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
package com.volcengine.velive.rn.push;
|
|
2
|
+
|
|
3
|
+
import android.view.SurfaceView;
|
|
4
|
+
import android.view.View;
|
|
5
|
+
|
|
6
|
+
import androidx.annotation.NonNull;
|
|
7
|
+
import androidx.annotation.Nullable;
|
|
8
|
+
|
|
9
|
+
import com.facebook.react.bridge.ReadableArray;
|
|
10
|
+
import com.facebook.react.common.MapBuilder;
|
|
11
|
+
import com.facebook.react.uimanager.SimpleViewManager;
|
|
12
|
+
import com.facebook.react.uimanager.ThemedReactContext;
|
|
13
|
+
import com.facebook.react.uimanager.annotations.ReactProp;
|
|
14
|
+
import com.volcengine.VolcApiEngine.view.*;
|
|
15
|
+
|
|
16
|
+
import java.util.Map;
|
|
17
|
+
|
|
18
|
+
public class VeLivePushViewManager extends SimpleViewManager<VeLivePushView> implements VolcViewManagerInterface<VeLivePushView> {
|
|
19
|
+
public static final String NAME = "VeLivePushView";
|
|
20
|
+
|
|
21
|
+
private ThemedReactContext context;
|
|
22
|
+
|
|
23
|
+
@NonNull
|
|
24
|
+
@Override
|
|
25
|
+
public String getName() {
|
|
26
|
+
return NAME;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
@NonNull
|
|
30
|
+
@Override
|
|
31
|
+
public VeLivePushView createViewInstance(@NonNull ThemedReactContext themedReactContext) {
|
|
32
|
+
context = themedReactContext;
|
|
33
|
+
return new VeLivePushView(themedReactContext);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
@ReactProp(name = "viewId")
|
|
37
|
+
public void setViewId(VeLivePushView view, String viewId) {
|
|
38
|
+
view.setViewId(viewId);
|
|
39
|
+
VolcViewManager.putViewById(viewId, view);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
@ReactProp(name = "kind")
|
|
43
|
+
public void setKind(VeLivePushView view, String kind) {
|
|
44
|
+
var themedReactContext = this.context;
|
|
45
|
+
|
|
46
|
+
switch (kind) {
|
|
47
|
+
case "SurfaceView" -> {
|
|
48
|
+
SurfaceView subView = new SurfaceView(themedReactContext.getReactApplicationContext());
|
|
49
|
+
view.addView(subView);
|
|
50
|
+
}
|
|
51
|
+
case "View" -> {
|
|
52
|
+
View subView = new View(themedReactContext.getApplicationContext());
|
|
53
|
+
view.addView(subView);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
public void setVisible(VeLivePushView view, Boolean visible) {
|
|
59
|
+
view.setVisible(visible);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Handle "create" command (called from JS) and call createFragment method
|
|
64
|
+
*/
|
|
65
|
+
public void receiveCommand(
|
|
66
|
+
@NonNull VeLivePushView root,
|
|
67
|
+
String command,
|
|
68
|
+
@Nullable ReadableArray args
|
|
69
|
+
) {
|
|
70
|
+
super.receiveCommand(root, command, args);
|
|
71
|
+
|
|
72
|
+
if (command.equals("setVisible")) {
|
|
73
|
+
assert args != null;
|
|
74
|
+
setVisible(root, args.getBoolean(0));
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
public Map getExportedCustomBubblingEventTypeConstants() {
|
|
79
|
+
return MapBuilder.builder().put(
|
|
80
|
+
"load",
|
|
81
|
+
MapBuilder.of(
|
|
82
|
+
"phasedRegistrationNames",
|
|
83
|
+
MapBuilder.of("bubbled", "onLoad")
|
|
84
|
+
)
|
|
85
|
+
).build();
|
|
86
|
+
}
|
|
87
|
+
}
|