@byteplus/react-native-live-pull 1.4.0 → 1.5.1-rc.1
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/android/build.gradle +19 -3
- package/android/gradle.properties +1 -1
- package/android/src/main/java/com/volcengine/velive/rn/pull/EnvHelper.java +1 -1
- package/android/src/main/java/com/volcengine/velive/rn/pull/VeLivePullImpl.java +66 -0
- package/android/src/main/java/com/volcengine/velive/rn/pull/VeLivePullPackage.java +61 -0
- package/android/src/main/java/com/volcengine/velive/rn/pull/{VolcView.java → VeLivePullView.java} +12 -3
- package/android/src/main/java/com/volcengine/velive/rn/pull/{VolcViewManager.java → VeLivePullViewManager.java} +34 -19
- package/android/src/newarch/com/volcengine/velive/rn/pull/VeLivePullModule.java +83 -0
- package/android/src/{main/java/com/volcengine/velive/rn/pull/VolcLiveModule.java → oldarch/com/volcengine/velive/rn/pull/VeLivePullModule.java} +17 -47
- package/android/src/{main/java/com/volcengine/velive/rn/pull/VolcLiveModuleSpec.java → oldarch/com/volcengine/velive/rn/pull/VeLivePullModuleSpec.java} +4 -4
- package/ios/RCTVeLivePull/RCTVeLivePull.h +21 -0
- package/ios/RCTVeLivePull/RCTVeLivePull.mm +119 -0
- package/ios/VeLivePullImpl.h +29 -0
- package/ios/VeLivePullImpl.m +49 -0
- package/ios/VeLivePullView.h +3 -3
- package/ios/VeLivePullView.m +2 -2
- package/ios/VeLivePullViewManager.m +13 -9
- package/lib/commonjs/index.js +142 -22
- package/lib/module/index.js +143 -23
- package/lib/typescript/codegen/ios/errorcode.d.ts +2 -2
- package/lib/typescript/module.d.ts +4 -0
- package/lib/typescript/platforms/TurboModule/NativeVeLivePull.d.ts +29 -0
- package/lib/typescript/platforms/TurboModule/index.d.ts +1 -0
- package/lib/typescript/utils/index.d.ts +1 -0
- package/package.json +14 -5
- package/react-native-velive-pull.podspec +29 -24
- package/src/platforms/TurboModule/NativeVeLivePull.ts +38 -0
- package/src/platforms/TurboModule/index.ts +1 -0
- package/android/src/main/java/com/volcengine/velive/rn/pull/VolcLivePackage.java +0 -27
- package/ios/VeLivePullSDK.h +0 -24
- package/ios/VeLivePullSDK.m +0 -89
package/android/build.gradle
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
buildscript {
|
|
2
|
+
|
|
2
3
|
repositories {
|
|
3
4
|
google()
|
|
4
5
|
mavenCentral()
|
|
@@ -52,6 +53,7 @@ apply plugin: "com.android.library"
|
|
|
52
53
|
apply from: "https://ve-vos.volccdn.com/script/vevos-repo-base.gradle"
|
|
53
54
|
|
|
54
55
|
if (isNewArchitectureEnabled()) {
|
|
56
|
+
println "[LIVE PULL GRADLE INFO]: newArchitectureEnabled"
|
|
55
57
|
apply plugin: "com.facebook.react"
|
|
56
58
|
}
|
|
57
59
|
|
|
@@ -85,13 +87,26 @@ android {
|
|
|
85
87
|
|
|
86
88
|
compileSdkVersion getExtOrIntegerDefault("compileSdkVersion")
|
|
87
89
|
|
|
90
|
+
|
|
88
91
|
defaultConfig {
|
|
89
92
|
minSdkVersion getExtOrIntegerDefault("minSdkVersion")
|
|
90
93
|
targetSdkVersion getExtOrIntegerDefault("targetSdkVersion")
|
|
91
94
|
|
|
92
|
-
consumerProguardFiles 'proguard-rules.pro'
|
|
95
|
+
consumerProguardFiles 'proguard-rules.pro'
|
|
96
|
+
//注入配置,运行时判断
|
|
97
|
+
buildConfigField("boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString())
|
|
93
98
|
}
|
|
94
|
-
|
|
99
|
+
|
|
100
|
+
sourceSets {
|
|
101
|
+
main {
|
|
102
|
+
if (isNewArchitectureEnabled()) {
|
|
103
|
+
java.srcDirs += ['src/newarch']
|
|
104
|
+
} else {
|
|
105
|
+
java.srcDirs += ['src/oldarch']
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
95
110
|
buildTypes {
|
|
96
111
|
release {
|
|
97
112
|
minifyEnabled false
|
|
@@ -123,6 +138,7 @@ dependencies {
|
|
|
123
138
|
// noinspection GradleDynamicVersion
|
|
124
139
|
implementation "com.facebook.react:react-native:+"
|
|
125
140
|
|
|
141
|
+
//TODO 改成开发runtime
|
|
126
142
|
implementation "com.volcengine:VolcApiEngine:$volc_api_engine_version"
|
|
127
|
-
implementation "com.bytedanceapi:ttsdk-
|
|
143
|
+
implementation "com.bytedanceapi:ttsdk-ttlivepull_premium:$ttsdk_ttlivepull_rtc_version"
|
|
128
144
|
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
package com.volcengine.velive.rn.pull;
|
|
2
|
+
|
|
3
|
+
import com.facebook.react.bridge.Callback;
|
|
4
|
+
import com.facebook.react.bridge.ReactApplicationContext;
|
|
5
|
+
import com.volcengine.VolcApiEngine.IEventReceiver;
|
|
6
|
+
import com.volcengine.VolcApiEngine.VolcApiEngine;
|
|
7
|
+
import com.volcengine.velive.rn.pull.autogen.MethodSignature;
|
|
8
|
+
|
|
9
|
+
//LivePullProxy 代理 TurboModule 和 NativeModule,消息统一聚合
|
|
10
|
+
public class VeLivePullImpl {
|
|
11
|
+
|
|
12
|
+
private VolcApiEngine apiEngine = null;
|
|
13
|
+
private ReactApplicationContext moduleContext;
|
|
14
|
+
private IEventReceiver module;
|
|
15
|
+
|
|
16
|
+
public static final String NAME = "VeLivePull";
|
|
17
|
+
public static final String EVENT_NAME = "VeLivePull:onEvent";
|
|
18
|
+
VeLivePullImpl(ReactApplicationContext context, IEventReceiver module ) {
|
|
19
|
+
MethodSignature.init();
|
|
20
|
+
ClassHelper.init();
|
|
21
|
+
this.moduleContext = context;
|
|
22
|
+
this.module = module;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
public boolean newApiEngine() {
|
|
26
|
+
if (apiEngine == null) {
|
|
27
|
+
apiEngine = new VolcApiEngine(moduleContext, this.module);
|
|
28
|
+
NativeVariableManager.init(apiEngine.msgClient, moduleContext);
|
|
29
|
+
return true;
|
|
30
|
+
}
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
public String callApiSync(String params) {
|
|
35
|
+
try {
|
|
36
|
+
newApiEngine();
|
|
37
|
+
return this.apiEngine.callApi(params);
|
|
38
|
+
} catch (Exception e) {
|
|
39
|
+
e.printStackTrace();
|
|
40
|
+
throw new RuntimeException(e);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
public void callApi(String params, Callback callback) {
|
|
45
|
+
try {
|
|
46
|
+
newApiEngine();
|
|
47
|
+
// 获取主线程处理器
|
|
48
|
+
android.os.Handler mainHandler =
|
|
49
|
+
new android.os.Handler(android.os.Looper.getMainLooper());
|
|
50
|
+
|
|
51
|
+
// 在主线程上执行 API 调用
|
|
52
|
+
mainHandler.post(() -> {
|
|
53
|
+
try {
|
|
54
|
+
this.apiEngine.callApi(
|
|
55
|
+
params, (res) -> {
|
|
56
|
+
callback.invoke(res.toJsonString());
|
|
57
|
+
});
|
|
58
|
+
} catch (Exception e) {
|
|
59
|
+
e.printStackTrace();
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
} catch (Exception e) {
|
|
63
|
+
e.printStackTrace();
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
package com.volcengine.velive.rn.pull;
|
|
2
|
+
|
|
3
|
+
import androidx.annotation.NonNull;
|
|
4
|
+
import androidx.annotation.Nullable;
|
|
5
|
+
|
|
6
|
+
import com.facebook.react.TurboReactPackage;
|
|
7
|
+
import com.facebook.react.bridge.NativeModule;
|
|
8
|
+
import com.facebook.react.bridge.ReactApplicationContext;
|
|
9
|
+
import com.facebook.react.module.model.ReactModuleInfo;
|
|
10
|
+
import com.facebook.react.module.model.ReactModuleInfoProvider;
|
|
11
|
+
import com.facebook.react.uimanager.ViewManager;
|
|
12
|
+
|
|
13
|
+
import java.util.ArrayList;
|
|
14
|
+
import java.util.HashMap;
|
|
15
|
+
import java.util.List;
|
|
16
|
+
import java.util.Map;
|
|
17
|
+
|
|
18
|
+
//准备新老架构统一磨平
|
|
19
|
+
public class VeLivePullPackage extends TurboReactPackage {
|
|
20
|
+
private boolean isTurboModule = BuildConfig.IS_NEW_ARCHITECTURE_ENABLED;
|
|
21
|
+
@Override
|
|
22
|
+
public List<ViewManager> createViewManagers(@NonNull ReactApplicationContext reactContext) {
|
|
23
|
+
List<ViewManager> viewManagers = new ArrayList<>();
|
|
24
|
+
viewManagers.add(new VeLivePullViewManager());
|
|
25
|
+
return viewManagers;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
@Nullable
|
|
29
|
+
@Override
|
|
30
|
+
public NativeModule getModule(@NonNull String name, @NonNull ReactApplicationContext reactApplicationContext) {
|
|
31
|
+
if (name.equals(VeLivePullImpl.NAME)) {
|
|
32
|
+
return new VeLivePullModule(reactApplicationContext);
|
|
33
|
+
} else {
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// @Override
|
|
39
|
+
// public List<NativeModule> createNativeModules(@NonNull ReactApplicationContext reactContext) {
|
|
40
|
+
// List<NativeModule> modules = new ArrayList<>();
|
|
41
|
+
// modules.add(new VeLivePullModule(reactContext));
|
|
42
|
+
// return modules;
|
|
43
|
+
// }
|
|
44
|
+
|
|
45
|
+
@Override
|
|
46
|
+
public ReactModuleInfoProvider getReactModuleInfoProvider() {
|
|
47
|
+
return () -> {
|
|
48
|
+
final Map<String, ReactModuleInfo> moduleInfos = new HashMap<>();
|
|
49
|
+
moduleInfos.put(
|
|
50
|
+
VeLivePullImpl.NAME,
|
|
51
|
+
new ReactModuleInfo(
|
|
52
|
+
VeLivePullImpl.NAME,
|
|
53
|
+
VeLivePullImpl.NAME,
|
|
54
|
+
false,
|
|
55
|
+
false,true,false,this.isTurboModule
|
|
56
|
+
)
|
|
57
|
+
);
|
|
58
|
+
return moduleInfos;
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
}
|
package/android/src/main/java/com/volcengine/velive/rn/pull/{VolcView.java → VeLivePullView.java}
RENAMED
|
@@ -7,11 +7,13 @@ import com.facebook.react.bridge.ReactContext;
|
|
|
7
7
|
import com.facebook.react.bridge.WritableMap;
|
|
8
8
|
import com.facebook.react.uimanager.events.RCTEventEmitter;
|
|
9
9
|
|
|
10
|
-
public class
|
|
10
|
+
public class VeLivePullView extends FrameLayout {
|
|
11
11
|
public String viewId;
|
|
12
12
|
public boolean hasRegister = false;
|
|
13
|
+
|
|
14
|
+
private boolean hasLoad = false;
|
|
13
15
|
|
|
14
|
-
public
|
|
16
|
+
public VeLivePullView(Context context) {
|
|
15
17
|
super(context);
|
|
16
18
|
this.setKeepScreenOn(true);
|
|
17
19
|
}
|
|
@@ -19,10 +21,17 @@ public class VolcView extends FrameLayout {
|
|
|
19
21
|
public void setViewId(String viewId) {
|
|
20
22
|
this.viewId = viewId;
|
|
21
23
|
this.hasRegister = true;
|
|
22
|
-
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
public void loaded() {
|
|
28
|
+
this.hasLoad = true;
|
|
23
29
|
}
|
|
24
30
|
|
|
25
31
|
public void emitOnLoad() {
|
|
32
|
+
if (this.hasLoad) {
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
26
35
|
WritableMap event = Arguments.createMap();
|
|
27
36
|
ReactContext reactContext = (ReactContext)getContext();
|
|
28
37
|
reactContext.getJSModule(RCTEventEmitter.class)
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
package com.volcengine.velive.rn.pull;
|
|
2
2
|
|
|
3
|
+
import android.view.SurfaceHolder;
|
|
3
4
|
import android.view.SurfaceView;
|
|
4
5
|
import android.view.View;
|
|
5
6
|
|
|
@@ -15,9 +16,9 @@ import com.volcengine.VolcApiEngine.view.*;
|
|
|
15
16
|
|
|
16
17
|
import java.util.Map;
|
|
17
18
|
|
|
18
|
-
public class
|
|
19
|
-
public static final String NAME = "
|
|
20
|
-
|
|
19
|
+
public class VeLivePullViewManager extends SimpleViewManager<VeLivePullView> implements VolcViewManagerInterface<VeLivePullView> {
|
|
20
|
+
public static final String NAME = "VeLivePullView";
|
|
21
|
+
|
|
21
22
|
private ThemedReactContext context;
|
|
22
23
|
|
|
23
24
|
@NonNull
|
|
@@ -28,30 +29,44 @@ public class VolcViewManager extends SimpleViewManager<VolcView> implements Volc
|
|
|
28
29
|
|
|
29
30
|
@NonNull
|
|
30
31
|
@Override
|
|
31
|
-
public
|
|
32
|
+
public VeLivePullView createViewInstance(@NonNull ThemedReactContext themedReactContext) {
|
|
32
33
|
context = themedReactContext;
|
|
33
|
-
return new
|
|
34
|
+
return new VeLivePullView(themedReactContext);
|
|
34
35
|
}
|
|
35
|
-
|
|
36
|
+
|
|
36
37
|
@ReactProp(name = "viewId")
|
|
37
|
-
public void setViewId(
|
|
38
|
+
public void setViewId(VeLivePullView view, String viewId) {
|
|
38
39
|
view.setViewId(viewId);
|
|
39
40
|
com.volcengine.VolcApiEngine.view.VolcViewManager.putViewById(viewId, view);
|
|
40
41
|
}
|
|
41
42
|
|
|
42
43
|
@ReactProp(name = "kind")
|
|
43
|
-
public void setKind(
|
|
44
|
+
public void setKind(VeLivePullView view, String kind) {
|
|
44
45
|
var themedReactContext = this.context;
|
|
45
|
-
|
|
46
|
+
|
|
46
47
|
switch (kind) {
|
|
47
48
|
case "SurfaceView" -> {
|
|
48
49
|
SurfaceView subView = new SurfaceView(themedReactContext.getReactApplicationContext());
|
|
50
|
+
//增加callback
|
|
51
|
+
subView.getHolder().addCallback(new SurfaceHolder.Callback() {
|
|
52
|
+
@Override
|
|
53
|
+
public void surfaceCreated(@NonNull SurfaceHolder surfaceHolder) {
|
|
54
|
+
view.emitOnLoad();
|
|
55
|
+
view.loaded();
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
@Override
|
|
59
|
+
public void surfaceChanged(@NonNull SurfaceHolder surfaceHolder, int i, int i1, int i2) {}
|
|
60
|
+
|
|
61
|
+
@Override
|
|
62
|
+
public void surfaceDestroyed(@NonNull SurfaceHolder surfaceHolder) {}
|
|
63
|
+
});
|
|
49
64
|
view.addView(subView);
|
|
50
65
|
}
|
|
51
66
|
}
|
|
52
67
|
}
|
|
53
|
-
|
|
54
|
-
public void setVisible(
|
|
68
|
+
|
|
69
|
+
public void setVisible(VeLivePullView view, Boolean visible) {
|
|
55
70
|
if(visible) {
|
|
56
71
|
view.setVisibility(View.INVISIBLE);
|
|
57
72
|
} else {
|
|
@@ -63,9 +78,9 @@ public class VolcViewManager extends SimpleViewManager<VolcView> implements Volc
|
|
|
63
78
|
* Handle "create" command (called from JS) and call createFragment method
|
|
64
79
|
*/
|
|
65
80
|
public void receiveCommand(
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
81
|
+
@NonNull VeLivePullView root,
|
|
82
|
+
String command,
|
|
83
|
+
@Nullable ReadableArray args
|
|
69
84
|
) {
|
|
70
85
|
super.receiveCommand(root, command, args);
|
|
71
86
|
|
|
@@ -77,11 +92,11 @@ public class VolcViewManager extends SimpleViewManager<VolcView> implements Volc
|
|
|
77
92
|
|
|
78
93
|
public Map getExportedCustomBubblingEventTypeConstants() {
|
|
79
94
|
return MapBuilder.builder().put(
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
95
|
+
"load",
|
|
96
|
+
MapBuilder.of(
|
|
97
|
+
"phasedRegistrationNames",
|
|
98
|
+
MapBuilder.of("bubbled", "onViewLoad")
|
|
99
|
+
)
|
|
85
100
|
).build();
|
|
86
101
|
}
|
|
87
102
|
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
package com.volcengine.velive.rn.pull;
|
|
2
|
+
|
|
3
|
+
import androidx.annotation.NonNull;
|
|
4
|
+
import androidx.annotation.Nullable;
|
|
5
|
+
|
|
6
|
+
import com.facebook.react.bridge.Arguments;
|
|
7
|
+
import com.facebook.react.bridge.Callback;
|
|
8
|
+
import com.facebook.react.bridge.ReactApplicationContext;
|
|
9
|
+
import com.facebook.react.bridge.ReactContext;
|
|
10
|
+
import com.facebook.react.bridge.WritableMap;
|
|
11
|
+
import com.facebook.react.modules.core.DeviceEventManagerModule;
|
|
12
|
+
import com.volcengine.VolcApiEngine.IEventReceiver;
|
|
13
|
+
|
|
14
|
+
public class VeLivePullModule extends NativeVeLivePullSpec implements IEventReceiver {
|
|
15
|
+
private VeLivePullImpl impl;
|
|
16
|
+
VeLivePullModule(ReactApplicationContext context) {
|
|
17
|
+
super(context);
|
|
18
|
+
this.impl = new VeLivePullImpl(context, this);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
@Override
|
|
22
|
+
public boolean newApiEngine() {
|
|
23
|
+
return this.impl.newApiEngine();
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
@Override
|
|
27
|
+
public String callSync(String params) {
|
|
28
|
+
String result = impl.callApiSync(params);
|
|
29
|
+
return result;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
@Override
|
|
33
|
+
public void call(String params, Callback callback) {
|
|
34
|
+
Callback myCallback = args -> {
|
|
35
|
+
callback.invoke(args);
|
|
36
|
+
};
|
|
37
|
+
impl.callApi(params, myCallback);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
@Override
|
|
41
|
+
@NonNull
|
|
42
|
+
public String getName() {
|
|
43
|
+
return VeLivePullImpl.NAME;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
@Override
|
|
47
|
+
public void OnEvent(String event, String data) {
|
|
48
|
+
final WritableMap map = Arguments.createMap();
|
|
49
|
+
map.putString("event", event);
|
|
50
|
+
map.putString("data", data);
|
|
51
|
+
|
|
52
|
+
super.getReactApplicationContext()
|
|
53
|
+
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
|
|
54
|
+
.emit(VeLivePullImpl.EVENT_NAME, map);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
private int listenerCount = 0;
|
|
59
|
+
|
|
60
|
+
@Override
|
|
61
|
+
public void addListener(String eventName) {
|
|
62
|
+
if (listenerCount == 0) {
|
|
63
|
+
// Set up any upstream listeners or background tasks as necessary
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
listenerCount += 1;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
@Override
|
|
70
|
+
public void removeListeners(double count) {
|
|
71
|
+
listenerCount -= count;
|
|
72
|
+
if (listenerCount == 0) {
|
|
73
|
+
// Remove upstream listeners, stop unnecessary background tasks
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
private void sendEvent(ReactContext reactContext, String eventName,
|
|
78
|
+
@Nullable WritableMap params) {
|
|
79
|
+
reactContext
|
|
80
|
+
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
|
|
81
|
+
.emit(eventName, params);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
@@ -10,73 +10,43 @@ import com.facebook.react.bridge.ReadableMap;
|
|
|
10
10
|
import com.facebook.react.bridge.WritableMap;
|
|
11
11
|
import com.facebook.react.module.annotations.ReactModule;
|
|
12
12
|
import com.facebook.react.modules.core.DeviceEventManagerModule;
|
|
13
|
-
import com.ss.videoarch.liveplayer.VeLivePlayerDef;
|
|
14
13
|
import com.volcengine.VolcApiEngine.*;
|
|
15
14
|
import com.volcengine.velive.rn.pull.autogen.MethodSignature;
|
|
16
15
|
|
|
17
|
-
@ReactModule(name =
|
|
18
|
-
public class
|
|
19
|
-
extends
|
|
20
|
-
|
|
16
|
+
@ReactModule(name = VeLivePullImpl.NAME)
|
|
17
|
+
public class VeLivePullModule
|
|
18
|
+
extends VeLivePullModuleSpec implements IEventReceiver {
|
|
19
|
+
private VeLivePullImpl impl;
|
|
21
20
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
VolcLiveModule(ReactApplicationContext context) {
|
|
21
|
+
VeLivePullModule(ReactApplicationContext context) {
|
|
25
22
|
super(context);
|
|
26
|
-
MethodSignature.init();
|
|
27
|
-
ClassHelper.init();
|
|
23
|
+
// MethodSignature.init();
|
|
24
|
+
// ClassHelper.init();
|
|
25
|
+
this.impl = new VeLivePullImpl(context, this);
|
|
28
26
|
}
|
|
29
27
|
|
|
30
28
|
@Override
|
|
31
29
|
public String getName() {
|
|
32
|
-
return NAME;
|
|
30
|
+
return VeLivePullImpl.NAME;
|
|
33
31
|
}
|
|
34
32
|
|
|
35
33
|
@ReactMethod(isBlockingSynchronousMethod = true)
|
|
36
34
|
public boolean newApiEngine() {
|
|
37
|
-
|
|
38
|
-
apiEngine = new VolcApiEngine(super.context, this);
|
|
39
|
-
NativeVariableManager.init(apiEngine.msgClient, super.context);
|
|
40
|
-
return true;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
return false;
|
|
35
|
+
return this.impl.newApiEngine();
|
|
44
36
|
}
|
|
45
37
|
|
|
46
38
|
@ReactMethod(isBlockingSynchronousMethod = true)
|
|
47
39
|
public String callApiSync(ReadableMap arg) {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
String params = arg.getString("params");
|
|
51
|
-
return this.apiEngine.callApi(params);
|
|
52
|
-
} catch (Exception e) {
|
|
53
|
-
e.printStackTrace();
|
|
54
|
-
throw new RuntimeException(e);
|
|
55
|
-
}
|
|
40
|
+
String params = arg.getString("params");
|
|
41
|
+
return this.impl.callApiSync(params);
|
|
56
42
|
}
|
|
57
43
|
|
|
58
44
|
@ReactMethod(isBlockingSynchronousMethod = false)
|
|
59
45
|
public void callApi(ReadableMap arg, Callback callback) {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
// 获取主线程处理器
|
|
65
|
-
android.os.Handler mainHandler =
|
|
66
|
-
new android.os.Handler(android.os.Looper.getMainLooper());
|
|
67
|
-
|
|
68
|
-
// 在主线程上执行 API 调用
|
|
69
|
-
mainHandler.post(() -> {
|
|
70
|
-
try {
|
|
71
|
-
this.apiEngine.callApi(
|
|
72
|
-
params, (res) -> { callback.invoke(res.toJsonString()); });
|
|
73
|
-
} catch (Exception e) {
|
|
74
|
-
e.printStackTrace();
|
|
75
|
-
}
|
|
76
|
-
});
|
|
77
|
-
} catch (Exception e) {
|
|
78
|
-
e.printStackTrace();
|
|
79
|
-
}
|
|
46
|
+
String params = arg.getString("params");
|
|
47
|
+
this.impl.callApi(params, args -> {
|
|
48
|
+
callback.invoke(args);
|
|
49
|
+
});
|
|
80
50
|
}
|
|
81
51
|
|
|
82
52
|
private int listenerCount = 0;
|
|
@@ -113,6 +83,6 @@ public class VolcLiveModule
|
|
|
113
83
|
|
|
114
84
|
super.context
|
|
115
85
|
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
|
|
116
|
-
.emit(
|
|
86
|
+
.emit(VeLivePullModuleSpec.EVENT, map);
|
|
117
87
|
}
|
|
118
88
|
}
|
|
@@ -3,15 +3,15 @@ package com.volcengine.velive.rn.pull;
|
|
|
3
3
|
import com.facebook.react.bridge.ReactApplicationContext;
|
|
4
4
|
import com.facebook.react.bridge.ReactContextBaseJavaModule;
|
|
5
5
|
|
|
6
|
-
public abstract class
|
|
7
|
-
static final String EVENT = "
|
|
6
|
+
public abstract class VeLivePullModuleSpec extends ReactContextBaseJavaModule {
|
|
7
|
+
static final String EVENT = "VeLivePull:onEvent";
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
VeLivePullModuleSpec(ReactApplicationContext context) {
|
|
10
10
|
super(context);
|
|
11
11
|
this.context = context;
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
public
|
|
14
|
+
public ReactApplicationContext context;
|
|
15
15
|
|
|
16
16
|
public abstract void OnEvent(String eventName, String data);
|
|
17
17
|
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
//
|
|
2
|
+
// RCTVeLivePull.h
|
|
3
|
+
// react-native-velive-pull
|
|
4
|
+
//
|
|
5
|
+
// Created by ByteDance on 2025/10/11.
|
|
6
|
+
//
|
|
7
|
+
|
|
8
|
+
#import <React/RCTBridgeModule.h>
|
|
9
|
+
#import "VolcApiEngine/Engine.h"
|
|
10
|
+
#import "VeLivePullImpl.h"
|
|
11
|
+
#import <React/RCTEventEmitter.h>
|
|
12
|
+
|
|
13
|
+
NS_ASSUME_NONNULL_BEGIN
|
|
14
|
+
|
|
15
|
+
@interface RCTVeLivePull : RCTEventEmitter <RCTBridgeModule, EventObserver>
|
|
16
|
+
|
|
17
|
+
@property(nonatomic, strong) VeLivePullImpl* impl;
|
|
18
|
+
|
|
19
|
+
@end
|
|
20
|
+
|
|
21
|
+
NS_ASSUME_NONNULL_END
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
//
|
|
2
|
+
// RCTVeLivePull.m
|
|
3
|
+
// react-native-velive-pull
|
|
4
|
+
//
|
|
5
|
+
// Created by ByteDance on 2025/10/11.
|
|
6
|
+
//
|
|
7
|
+
|
|
8
|
+
#ifdef RCT_NEW_ARCH_ENABLED
|
|
9
|
+
#import <VeLivePullSpec/VeLivePullSpec.h>
|
|
10
|
+
#endif
|
|
11
|
+
|
|
12
|
+
#import <React/RCTEventEmitter.h>
|
|
13
|
+
#import "VolcApiEngine/VolcEventObserver.h"
|
|
14
|
+
#import "RCTVeLivePull.h"
|
|
15
|
+
#import "VeLivePullImpl.h"
|
|
16
|
+
#define EVENT_NAME @"VeLivePull:onEvent"
|
|
17
|
+
|
|
18
|
+
#ifdef RCT_NEW_ARCH_ENABLED
|
|
19
|
+
@interface RCTVeLivePull () <NativeVeLivePullSpec>
|
|
20
|
+
|
|
21
|
+
@end
|
|
22
|
+
#endif
|
|
23
|
+
|
|
24
|
+
static RCTVeLivePull *instance = nil;
|
|
25
|
+
|
|
26
|
+
@implementation RCTVeLivePull {
|
|
27
|
+
bool hasListeners;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
+ (instancetype)shareInstance {
|
|
31
|
+
return instance;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
//@See https://stackoverflow.com/questions/50773748/difference-requiresmainqueuesetup-and-dispatch-get-main-queue
|
|
35
|
+
+ (BOOL)requiresMainQueueSetup {
|
|
36
|
+
return YES;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
- (dispatch_queue_t)methodQueue {
|
|
40
|
+
return dispatch_get_main_queue();
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
- (instancetype) init {
|
|
44
|
+
self = [super init];
|
|
45
|
+
if (self) {
|
|
46
|
+
instance = self;
|
|
47
|
+
self.impl = [[VeLivePullImpl alloc] initWithModule: instance];
|
|
48
|
+
}
|
|
49
|
+
return self;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
- (NSArray<NSString *> *)supportedEvents {
|
|
53
|
+
return @[ EVENT_NAME ];
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
- (void)onEvent:(NSString *)eventName data:(id)eventData {
|
|
57
|
+
NSDictionary *dic = @{@"event" : eventName, @"data" : eventData};
|
|
58
|
+
[self sendEventWithName:EVENT_NAME body:dic];
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
//export api
|
|
62
|
+
RCT_EXPORT_MODULE(VeLivePull)
|
|
63
|
+
|
|
64
|
+
#ifdef RCT_NEW_ARCH_ENABLED
|
|
65
|
+
|
|
66
|
+
- (NSNumber *)newApiEngine {
|
|
67
|
+
return [self.impl newApiEngine];
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
- (void)call:(NSString *)params
|
|
71
|
+
callback: (RCTResponseSenderBlock)callback {
|
|
72
|
+
NSDictionary * args = @{@"params": params};
|
|
73
|
+
[self.impl callApi:args callback:^(id _Nonnull res) {
|
|
74
|
+
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:res options:0 error:nil];
|
|
75
|
+
NSString* jsonResult = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
|
|
76
|
+
callback(@[jsonResult]);
|
|
77
|
+
}];
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
- (NSString *)callSync: (NSString *) params {
|
|
81
|
+
NSDictionary* args = @{@"params": params};
|
|
82
|
+
NSDictionary* result = [self.impl callApiSync: args];
|
|
83
|
+
//result序列化 - 将NSDictionary转换为JSON字符串
|
|
84
|
+
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:result options:0 error:nil];
|
|
85
|
+
NSString* jsonResult = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
|
|
86
|
+
return jsonResult;
|
|
87
|
+
}
|
|
88
|
+
- (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:
|
|
89
|
+
(const facebook::react::ObjCTurboModule::InitParams &)params
|
|
90
|
+
{
|
|
91
|
+
return std::make_shared<facebook::react::NativeVeLivePullSpecJSI>(params);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
#else
|
|
95
|
+
RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(newApiEngine) {
|
|
96
|
+
return [self.impl newApiEngine];
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(callApiSync
|
|
100
|
+
: (nonnull NSDictionary *)args) {
|
|
101
|
+
NSDictionary* result = [self.impl callApiSync: args];
|
|
102
|
+
//result序列化 - 将NSDictionary转换为JSON字符串
|
|
103
|
+
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:result options:0 error:nil];
|
|
104
|
+
NSString* jsonResult = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
|
|
105
|
+
return jsonResult;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
RCT_EXPORT_METHOD(callApi
|
|
109
|
+
: (nonnull NSDictionary *)args callback
|
|
110
|
+
: (RCTResponseSenderBlock)callback) {
|
|
111
|
+
[self.impl callApi:args callback:^(id _Nonnull res) {
|
|
112
|
+
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:res options:0 error:nil];
|
|
113
|
+
NSString* jsonResult = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
|
|
114
|
+
callback(@[jsonResult]);
|
|
115
|
+
}];
|
|
116
|
+
}
|
|
117
|
+
#endif
|
|
118
|
+
|
|
119
|
+
@end
|