@byteplus/react-native-live-push 1.4.0 → 1.5.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/android/build.gradle +15 -3
- package/android/src/main/java/com/volcengine/velive/rn/push/EnvHelper.java +1 -1
- package/android/src/main/java/com/volcengine/velive/rn/push/VeLivePushImpl.java +73 -0
- package/android/src/main/java/com/volcengine/velive/rn/push/VeLivePushPackage.java +36 -11
- package/android/src/main/java/com/volcengine/velive/rn/push/VeLivePushView.java +1 -0
- package/android/src/main/java/com/volcengine/velive/rn/push/mixer/TextureMgr.java +1 -1
- package/android/src/newarch/com/volcengine/velive/rn/push/VeLivePushModule.java +92 -0
- package/android/src/{main/java → oldarch}/com/volcengine/velive/rn/push/VeLivePushModule.java +12 -48
- package/ios/RCTVeLivePush/RCTVeLivePush.h +22 -0
- package/ios/RCTVeLivePush/RCTVeLivePush.mm +141 -0
- package/ios/VeLivePushImpl.h +38 -0
- package/ios/VeLivePushImpl.m +51 -0
- package/lib/commonjs/index.js +462 -256
- package/lib/commonjs/typescript/index.d.ts +1 -0
- package/lib/commonjs/typescript/module.d.ts +4 -0
- package/lib/commonjs/typescript/platforms/TurboModule/NativeVeLivePush.d.ts +193 -0
- package/lib/commonjs/typescript/platforms/TurboModule/index.d.ts +1 -0
- package/lib/commonjs/typescript/utils/index.d.ts +1 -0
- package/lib/module/index.js +486 -282
- package/lib/module/typescript/index.d.ts +1 -0
- package/lib/module/typescript/module.d.ts +4 -0
- package/lib/module/typescript/platforms/TurboModule/NativeVeLivePush.d.ts +193 -0
- package/lib/module/typescript/platforms/TurboModule/index.d.ts +1 -0
- package/lib/module/typescript/utils/index.d.ts +1 -0
- package/lib/typescript/index.d.ts +1 -0
- package/lib/typescript/module.d.ts +4 -0
- package/lib/typescript/platforms/TurboModule/NativeVeLivePush.d.ts +193 -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-push.podspec +9 -5
- package/src/platforms/TurboModule/NativeVeLivePush.ts +242 -0
- package/src/platforms/TurboModule/index.ts +1 -0
- package/ios/VeLivePushSDK.h +0 -24
- package/ios/VeLivePushSDK.m +0 -98
- /package/android/src/{main/java → oldarch}/com/volcengine/velive/rn/push/VeLivePushModuleSpec.java +0 -0
package/android/build.gradle
CHANGED
|
@@ -52,6 +52,7 @@ apply plugin: "com.android.library"
|
|
|
52
52
|
apply from: "https://ve-vos.volccdn.com/script/vevos-repo-base.gradle"
|
|
53
53
|
|
|
54
54
|
if (isNewArchitectureEnabled()) {
|
|
55
|
+
println "[LIVE PUSH GRADLE INFO]: newArchitectureEnabled"
|
|
55
56
|
apply plugin: "com.facebook.react"
|
|
56
57
|
}
|
|
57
58
|
|
|
@@ -90,6 +91,17 @@ android {
|
|
|
90
91
|
targetSdkVersion getExtOrIntegerDefault("targetSdkVersion")
|
|
91
92
|
|
|
92
93
|
consumerProguardFiles 'proguard-rules.pro'
|
|
94
|
+
buildConfigField("boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString())
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
sourceSets {
|
|
98
|
+
main {
|
|
99
|
+
if (isNewArchitectureEnabled()) {
|
|
100
|
+
java.srcDirs += ['src/newarch']
|
|
101
|
+
} else {
|
|
102
|
+
java.srcDirs += ['src/oldarch']
|
|
103
|
+
}
|
|
104
|
+
}
|
|
93
105
|
}
|
|
94
106
|
|
|
95
107
|
buildTypes {
|
|
@@ -121,7 +133,7 @@ dependencies {
|
|
|
121
133
|
// For < 0.71, this will be from the local maven repo
|
|
122
134
|
// For > 0.71, this will be replaced by `com.facebook.react:react-android:$version` by react gradle plugin
|
|
123
135
|
//noinspection GradleDynamicVersion
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
136
|
+
implementation "com.facebook.react:react-native:+"
|
|
137
|
+
implementation "com.volcengine:VolcApiEngine:$volc_api_engine_version"
|
|
138
|
+
api "com.bytedanceapi:ttsdk-ttlivepush:$ttsdk_ttlivepush_rtc_version"
|
|
127
139
|
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
package com.volcengine.velive.rn.push;
|
|
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
|
+
|
|
8
|
+
public class VeLivePushImpl {
|
|
9
|
+
private VolcApiEngine apiEngine = null;
|
|
10
|
+
private ReactApplicationContext moduleContext;
|
|
11
|
+
private IEventReceiver module;
|
|
12
|
+
|
|
13
|
+
public static final String NAME = "VeLivePush";
|
|
14
|
+
public static final String EVENT_NAME = "VeLivePush:onEvent";
|
|
15
|
+
|
|
16
|
+
VeLivePushImpl(ReactApplicationContext context, IEventReceiver module) {
|
|
17
|
+
VeLiveEffectHelper.context = context;
|
|
18
|
+
this.moduleContext = context;
|
|
19
|
+
this.module = module;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
public boolean newApiEngine() {
|
|
24
|
+
if (apiEngine == null) {
|
|
25
|
+
apiEngine = new VolcApiEngine(moduleContext, this.module);
|
|
26
|
+
NativeVariableManager.init(apiEngine, moduleContext);
|
|
27
|
+
return true;
|
|
28
|
+
}
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
public boolean destoryApiEngine() {
|
|
33
|
+
if (apiEngine != null) {
|
|
34
|
+
apiEngine.msgClient.proto.dispose();
|
|
35
|
+
apiEngine = null;
|
|
36
|
+
}
|
|
37
|
+
return true;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
public String callApiSync(String params) {
|
|
41
|
+
try {
|
|
42
|
+
newApiEngine();
|
|
43
|
+
return this.apiEngine.callApi(params);
|
|
44
|
+
} catch (Exception e) {
|
|
45
|
+
e.printStackTrace();
|
|
46
|
+
throw new RuntimeException(e);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
public void callApi(String params, Callback callback) {
|
|
51
|
+
try {
|
|
52
|
+
newApiEngine();
|
|
53
|
+
// 获取主线程处理器
|
|
54
|
+
android.os.Handler mainHandler =
|
|
55
|
+
new android.os.Handler(android.os.Looper.getMainLooper());
|
|
56
|
+
|
|
57
|
+
// 在主线程上执行 API 调用
|
|
58
|
+
mainHandler.post(() -> {
|
|
59
|
+
try {
|
|
60
|
+
this.apiEngine.callApi(
|
|
61
|
+
params, (res) -> {
|
|
62
|
+
System.out.println("call result: " + res);
|
|
63
|
+
callback.invoke(res.toJsonString());
|
|
64
|
+
});
|
|
65
|
+
} catch (Exception e) {
|
|
66
|
+
e.printStackTrace();
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
} catch (Exception e) {
|
|
70
|
+
e.printStackTrace();
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
@@ -1,30 +1,55 @@
|
|
|
1
1
|
package com.volcengine.velive.rn.push;
|
|
2
2
|
|
|
3
|
-
import
|
|
3
|
+
import androidx.annotation.NonNull;
|
|
4
|
+
import androidx.annotation.Nullable;
|
|
5
|
+
|
|
6
|
+
import com.facebook.react.TurboReactPackage;
|
|
4
7
|
import com.facebook.react.bridge.NativeModule;
|
|
5
8
|
import com.facebook.react.bridge.ReactApplicationContext;
|
|
9
|
+
import com.facebook.react.module.model.ReactModuleInfo;
|
|
10
|
+
import com.facebook.react.module.model.ReactModuleInfoProvider;
|
|
6
11
|
import com.facebook.react.uimanager.ViewManager;
|
|
7
12
|
import com.volcengine.velive.rn.push.mixer.MixerViewManager;
|
|
8
13
|
import java.util.ArrayList;
|
|
9
14
|
import java.util.List;
|
|
15
|
+
import java.util.HashMap;
|
|
16
|
+
import java.util.Map;
|
|
10
17
|
|
|
11
|
-
|
|
18
|
+
//TODO: 后期磨平为一层
|
|
19
|
+
public class VeLivePushPackage extends TurboReactPackage {
|
|
20
|
+
private boolean isTurboModule = BuildConfig.IS_NEW_ARCHITECTURE_ENABLED;
|
|
12
21
|
@Override
|
|
13
|
-
public List<ViewManager>
|
|
14
|
-
createViewManagers(ReactApplicationContext reactContext) {
|
|
22
|
+
public List<ViewManager> createViewManagers(ReactApplicationContext reactContext) {
|
|
15
23
|
List<ViewManager> viewManagers = new ArrayList<>();
|
|
16
24
|
viewManagers.add(new VeLivePushViewManager());
|
|
17
25
|
viewManagers.add(new MixerViewManager());
|
|
18
26
|
return viewManagers;
|
|
19
27
|
}
|
|
20
|
-
|
|
28
|
+
|
|
29
|
+
@Nullable
|
|
21
30
|
@Override
|
|
22
|
-
public
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
31
|
+
public NativeModule getModule(@NonNull String name, @NonNull ReactApplicationContext reactApplicationContext) {
|
|
32
|
+
if (name.equals(VeLivePushImpl.NAME)) {
|
|
33
|
+
return new VeLivePushModule(reactApplicationContext);
|
|
34
|
+
} else {
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
27
38
|
|
|
28
|
-
|
|
39
|
+
@Override
|
|
40
|
+
public ReactModuleInfoProvider getReactModuleInfoProvider() {
|
|
41
|
+
return () -> {
|
|
42
|
+
final Map<String, ReactModuleInfo> moduleInfos = new HashMap<>();
|
|
43
|
+
moduleInfos.put(
|
|
44
|
+
VeLivePushImpl.NAME,
|
|
45
|
+
new ReactModuleInfo(
|
|
46
|
+
VeLivePushImpl.NAME,
|
|
47
|
+
VeLivePushImpl.NAME,
|
|
48
|
+
false,
|
|
49
|
+
false,true,false,isTurboModule
|
|
50
|
+
)
|
|
51
|
+
);
|
|
52
|
+
return moduleInfos;
|
|
53
|
+
};
|
|
29
54
|
}
|
|
30
55
|
}
|
|
@@ -52,7 +52,7 @@ public class TextureMgr {
|
|
|
52
52
|
Bitmap bmp = null;
|
|
53
53
|
Bitmap rotatedBmp = null;
|
|
54
54
|
try {
|
|
55
|
-
android.content.Context context = Env.getApplicationContext();
|
|
55
|
+
android.content.Context context = Env.getConfig().getApplicationContext();
|
|
56
56
|
if (context == null) {
|
|
57
57
|
// If context is null, skip processing and return
|
|
58
58
|
return;
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
package com.volcengine.velive.rn.push;
|
|
2
|
+
|
|
3
|
+
import static com.volcengine.VolcApiEngine.runtime.Util.JsonAbleClass;
|
|
4
|
+
import androidx.annotation.NonNull;
|
|
5
|
+
import androidx.annotation.Nullable;
|
|
6
|
+
|
|
7
|
+
import com.facebook.react.bridge.Arguments;
|
|
8
|
+
import com.facebook.react.bridge.Callback;
|
|
9
|
+
import com.facebook.react.bridge.ReactApplicationContext;
|
|
10
|
+
import com.facebook.react.bridge.ReactContext;
|
|
11
|
+
import com.facebook.react.bridge.WritableMap;
|
|
12
|
+
import com.facebook.react.modules.core.DeviceEventManagerModule;
|
|
13
|
+
import com.ss.avframework.live.statistics.VeLivePusherStatisticsExt;
|
|
14
|
+
import com.volcengine.VolcApiEngine.IEventReceiver;
|
|
15
|
+
|
|
16
|
+
public class VeLivePushModule extends NativeVeLivePushSpec implements IEventReceiver {
|
|
17
|
+
private VeLivePushImpl impl;
|
|
18
|
+
VeLivePushModule(ReactApplicationContext context) {
|
|
19
|
+
super(context);
|
|
20
|
+
this.impl = new VeLivePushImpl(context, this);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
static {
|
|
24
|
+
JsonAbleClass.add(VeLivePusherStatisticsExt.class);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
@Override
|
|
28
|
+
public boolean destroyApiEngine() {
|
|
29
|
+
return this.impl.destoryApiEngine();
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
@Override
|
|
33
|
+
public boolean newApiEngine() {
|
|
34
|
+
return this.impl.newApiEngine();
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
@Override
|
|
38
|
+
public String callSync(String params) {
|
|
39
|
+
return this.impl.callApiSync(params);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
@Override
|
|
43
|
+
public void call(String params, Callback callback) {
|
|
44
|
+
Callback myCallback = args -> {
|
|
45
|
+
callback.invoke(args);
|
|
46
|
+
};
|
|
47
|
+
impl.callApi(params, myCallback);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
@Override
|
|
51
|
+
@NonNull
|
|
52
|
+
public String getName() {
|
|
53
|
+
return VeLivePushImpl.NAME;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
private int listenerCount = 0;
|
|
57
|
+
|
|
58
|
+
@Override
|
|
59
|
+
public void addListener(String eventType) {
|
|
60
|
+
if (listenerCount == 0) {
|
|
61
|
+
// Set up any upstream listeners or background tasks as necessary
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
listenerCount += 1;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
@Override
|
|
68
|
+
public void removeListeners(double count) {
|
|
69
|
+
listenerCount -= count;
|
|
70
|
+
if (listenerCount == 0) {
|
|
71
|
+
// Remove upstream listeners, stop unnecessary background tasks
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
@Override
|
|
76
|
+
public void OnEvent(String event, String data) {
|
|
77
|
+
final WritableMap map = Arguments.createMap();
|
|
78
|
+
map.putString("event", event);
|
|
79
|
+
map.putString("data", data);
|
|
80
|
+
|
|
81
|
+
super.getReactApplicationContext()
|
|
82
|
+
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
|
|
83
|
+
.emit(VeLivePushImpl.EVENT_NAME, map);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
private void sendEvent(ReactContext reactContext, String eventName,
|
|
87
|
+
@Nullable WritableMap params) {
|
|
88
|
+
reactContext
|
|
89
|
+
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
|
|
90
|
+
.emit(eventName, params);
|
|
91
|
+
}
|
|
92
|
+
}
|
package/android/src/{main/java → oldarch}/com/volcengine/velive/rn/push/VeLivePushModule.java
RENAMED
|
@@ -25,6 +25,7 @@ import com.volcengine.VolcApiEngine.*;
|
|
|
25
25
|
import com.volcengine.VolcApiEngine.view.*;
|
|
26
26
|
import com.volcengine.velive.rn.push.VeLiveEffectHelper;
|
|
27
27
|
|
|
28
|
+
|
|
28
29
|
import java.util.WeakHashMap;
|
|
29
30
|
|
|
30
31
|
public class VeLivePushModule extends VeLivePushModuleSpec implements IEventReceiver {
|
|
@@ -32,77 +33,40 @@ public class VeLivePushModule extends VeLivePushModuleSpec implements IEventRece
|
|
|
32
33
|
JsonAbleClass.add(VeLivePusherStatisticsExt.class);
|
|
33
34
|
}
|
|
34
35
|
|
|
35
|
-
|
|
36
|
-
private WeakHashMap<String, VeLivePusher> mPusherMap = new WeakHashMap<>();
|
|
36
|
+
private VeLivePushImpl impl;
|
|
37
37
|
|
|
38
|
-
|
|
39
38
|
VeLivePushModule(ReactApplicationContext context) {
|
|
40
39
|
super(context);
|
|
41
|
-
|
|
40
|
+
this.impl = new VeLivePushImpl(context, this);
|
|
42
41
|
}
|
|
43
42
|
|
|
44
43
|
@Override
|
|
45
44
|
public String getName() {
|
|
46
|
-
return
|
|
45
|
+
return VeLivePushImpl.NAME;
|
|
47
46
|
}
|
|
48
47
|
|
|
49
48
|
@ReactMethod(isBlockingSynchronousMethod = true)
|
|
50
49
|
public boolean newApiEngine() {
|
|
51
|
-
|
|
52
|
-
apiEngine = new VolcApiEngine(getReactApplicationContext(), this);
|
|
53
|
-
|
|
54
|
-
NativeVariableManager.init(apiEngine, super.context);
|
|
55
|
-
ClassHelper.init();
|
|
56
|
-
return true;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
return false;
|
|
50
|
+
return this.impl.newApiEngine();
|
|
60
51
|
}
|
|
61
52
|
|
|
62
53
|
@ReactMethod(isBlockingSynchronousMethod = true)
|
|
63
54
|
public boolean destroyApiEngine() {
|
|
64
|
-
|
|
65
|
-
apiEngine.msgClient.proto.dispose();
|
|
66
|
-
apiEngine = null;
|
|
67
|
-
}
|
|
68
|
-
return true;
|
|
55
|
+
return this.impl.destoryApiEngine();
|
|
69
56
|
}
|
|
70
57
|
|
|
71
58
|
@ReactMethod(isBlockingSynchronousMethod = true)
|
|
72
59
|
public String callApiSync(ReadableMap arg) {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
String params = arg.getString("params");
|
|
76
|
-
return this.apiEngine.callApi(params);
|
|
77
|
-
} catch (Exception e) {
|
|
78
|
-
e.printStackTrace();
|
|
79
|
-
throw new RuntimeException(e);
|
|
80
|
-
}
|
|
60
|
+
String params = arg.getString("params");
|
|
61
|
+
return this.impl.callApiSync(params);
|
|
81
62
|
}
|
|
82
63
|
|
|
83
64
|
@ReactMethod(isBlockingSynchronousMethod = false)
|
|
84
65
|
public void callApi(ReadableMap arg, Callback callback) {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
// 获取主线程处理器
|
|
90
|
-
android.os.Handler mainHandler =
|
|
91
|
-
new android.os.Handler(android.os.Looper.getMainLooper());
|
|
92
|
-
|
|
93
|
-
// 在主线程上执行 API 调用
|
|
94
|
-
mainHandler.post(() -> {
|
|
95
|
-
try {
|
|
96
|
-
this.apiEngine.callApi(
|
|
97
|
-
params, (res) -> { callback.invoke(res.toJsonString()); });
|
|
98
|
-
} catch (Exception e) {
|
|
99
|
-
e.printStackTrace();
|
|
100
|
-
}
|
|
101
|
-
});
|
|
102
|
-
} catch (Exception e) {
|
|
103
|
-
e.printStackTrace();
|
|
104
|
-
throw new RuntimeException(e);
|
|
105
|
-
}
|
|
66
|
+
String params = arg.getString("params");
|
|
67
|
+
this.impl.callApi(params, args -> {
|
|
68
|
+
callback.invoke(args);
|
|
69
|
+
});
|
|
106
70
|
}
|
|
107
71
|
|
|
108
72
|
private int listenerCount = 0;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
//
|
|
2
|
+
// RCTVeLivePush.h
|
|
3
|
+
// DoubleConversion
|
|
4
|
+
//
|
|
5
|
+
// Created by ByteDance on 2025/9/18.
|
|
6
|
+
//
|
|
7
|
+
#import <React/RCTBridgeModule.h>
|
|
8
|
+
#import "VolcApiEngine/Engine.h"
|
|
9
|
+
#import <React/RCTEventEmitter.h>
|
|
10
|
+
#import "VeLivePushImpl.h"
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
NS_ASSUME_NONNULL_BEGIN
|
|
14
|
+
|
|
15
|
+
@interface RCTVeLivePush : RCTEventEmitter <RCTBridgeModule, EventObserver>
|
|
16
|
+
|
|
17
|
+
@property(nonatomic, strong) VeLivePushImpl* impl;
|
|
18
|
+
|
|
19
|
+
@end
|
|
20
|
+
|
|
21
|
+
NS_ASSUME_NONNULL_END
|
|
22
|
+
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
//
|
|
2
|
+
// RCTVeLivePush.m
|
|
3
|
+
// DoubleConversion
|
|
4
|
+
//
|
|
5
|
+
// Created by ByteDance on 2025/9/18.
|
|
6
|
+
//
|
|
7
|
+
|
|
8
|
+
#ifdef RCT_NEW_ARCH_ENABLED
|
|
9
|
+
#import <NativeVeLivePushSpec/NativeVeLivePushSpec.h>
|
|
10
|
+
#endif
|
|
11
|
+
|
|
12
|
+
#import <TTSDKFramework/TTSDKFramework.h>
|
|
13
|
+
#import <React/RCTEventEmitter.h>
|
|
14
|
+
#import "VolcApiEngine/VolcEventObserver.h"
|
|
15
|
+
#import "RCTVeLivePush.h"
|
|
16
|
+
#import "VeLivePushImpl.h"
|
|
17
|
+
#define EVENT_NAME @"VeLivePush:onEvent"
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
#ifdef RCT_NEW_ARCH_ENABLED
|
|
21
|
+
|
|
22
|
+
@interface RCTVeLivePush () <NativeVeLivePushSpec>
|
|
23
|
+
|
|
24
|
+
@end
|
|
25
|
+
#endif
|
|
26
|
+
@interface RCTVeLivePush () <VeLiveMediaPlayerListener>
|
|
27
|
+
|
|
28
|
+
@end
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
static RCTVeLivePush *instance = nil;
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
@implementation RCTVeLivePush {
|
|
36
|
+
bool hasListeners;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
+ (instancetype)shareInstance {
|
|
40
|
+
return instance;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
+ (BOOL)requiresMainQueueSetup {
|
|
44
|
+
return YES;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
- (dispatch_queue_t)methodQueue {
|
|
48
|
+
return dispatch_get_main_queue();
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
- (instancetype) init {
|
|
52
|
+
self = [super init];
|
|
53
|
+
if (self) {
|
|
54
|
+
instance = self;
|
|
55
|
+
// 使用局部强引用临时持有对象,避免立即释放
|
|
56
|
+
self.impl = [[VeLivePushImpl alloc] initWithModule: instance];
|
|
57
|
+
}
|
|
58
|
+
return self;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
- (NSArray<NSString *> *)supportedEvents {
|
|
62
|
+
return @[ EVENT_NAME ];
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
- (void)onEvent:(NSString *)eventName data:(id)eventData {
|
|
66
|
+
NSDictionary *dic = @{@"event" : eventName, @"data" : eventData};
|
|
67
|
+
[self sendEventWithName:EVENT_NAME body:dic];
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
//export api
|
|
71
|
+
|
|
72
|
+
RCT_EXPORT_MODULE(VeLivePush)
|
|
73
|
+
|
|
74
|
+
#ifdef RCT_NEW_ARCH_ENABLED
|
|
75
|
+
- (void)call:(NSString *)params
|
|
76
|
+
callback: (RCTResponseSenderBlock)callback {
|
|
77
|
+
NSDictionary * args = @{@"params": params};
|
|
78
|
+
[self.impl callApi:args callback:^(id _Nonnull res) {
|
|
79
|
+
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:res options:0 error:nil];
|
|
80
|
+
NSString* jsonResult = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
|
|
81
|
+
callback(@[jsonResult]);
|
|
82
|
+
}];
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
- (NSString *)callSync: (NSString *) params {
|
|
86
|
+
NSDictionary* args = @{@"params": params};
|
|
87
|
+
NSDictionary* result = [self.impl callApiSync: args];
|
|
88
|
+
//result序列化 - 将NSDictionary转换为JSON字符串
|
|
89
|
+
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:result options:0 error:nil];
|
|
90
|
+
NSString* jsonResult = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
|
|
91
|
+
return jsonResult;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
- (NSNumber *)destroyApiEngine {
|
|
95
|
+
return nil;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
- (NSNumber *)newApiEngine {
|
|
99
|
+
return [self.impl newApiEngine];
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
- (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:
|
|
104
|
+
(const facebook::react::ObjCTurboModule::InitParams &)params
|
|
105
|
+
{
|
|
106
|
+
return std::make_shared<facebook::react::NativeVeLivePushSpecJSI>(params);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
#else
|
|
110
|
+
RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(newApiEngine) {
|
|
111
|
+
return [self.impl newApiEngine];
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(destroyApiEngine) {
|
|
115
|
+
return [self.impl destoryApiEngine];
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(callApiSync
|
|
119
|
+
: (nonnull NSDictionary *)args) {
|
|
120
|
+
|
|
121
|
+
NSDictionary* result = [self.impl callApiSync: args];
|
|
122
|
+
//result序列化 - 将NSDictionary转换为JSON字符串
|
|
123
|
+
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:result options:0 error:nil];
|
|
124
|
+
NSString* jsonResult = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
|
|
125
|
+
return jsonResult;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
RCT_EXPORT_METHOD(callApi
|
|
129
|
+
: (nonnull NSDictionary *)args callback
|
|
130
|
+
: (RCTResponseSenderBlock)callback) {
|
|
131
|
+
|
|
132
|
+
[self.impl callApi:args callback:^(id _Nonnull res) {
|
|
133
|
+
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:res options:0 error:nil];
|
|
134
|
+
NSString* jsonResult = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
|
|
135
|
+
callback(@[jsonResult]);
|
|
136
|
+
}];
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
#endif
|
|
140
|
+
|
|
141
|
+
@end
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
//
|
|
2
|
+
// VeLivePushImpl.h
|
|
3
|
+
// Pods
|
|
4
|
+
//
|
|
5
|
+
// Created by ByteDance on 2025/9/18.
|
|
6
|
+
//
|
|
7
|
+
|
|
8
|
+
//
|
|
9
|
+
// VolcLiveImpl.h
|
|
10
|
+
// react-native-velive-pull
|
|
11
|
+
//
|
|
12
|
+
// Created by ByteDance on 2025/9/18.
|
|
13
|
+
//
|
|
14
|
+
|
|
15
|
+
#import <Foundation/Foundation.h>
|
|
16
|
+
#import "VolcApiEngine/Engine.h"
|
|
17
|
+
#import "VolcApiEngine/VolcEventObserver.h"
|
|
18
|
+
|
|
19
|
+
NS_ASSUME_NONNULL_BEGIN
|
|
20
|
+
|
|
21
|
+
@interface VeLivePushImpl : NSObject
|
|
22
|
+
|
|
23
|
+
@property(nonatomic, strong) VolcApiEngine *volcApiEngine;
|
|
24
|
+
@property(nonatomic, weak) NSObject<EventObserver>* module;
|
|
25
|
+
|
|
26
|
+
- (NSDictionary *) callApiSync: (nonnull NSDictionary*) args;
|
|
27
|
+
|
|
28
|
+
- (void)callApi: (nonnull NSDictionary*) args
|
|
29
|
+
callback: (void (^)(id))callback;
|
|
30
|
+
|
|
31
|
+
- (instancetype) initWithModule:(NSObject<EventObserver> *)module;
|
|
32
|
+
|
|
33
|
+
- (id)newApiEngine;
|
|
34
|
+
|
|
35
|
+
- (id)destoryApiEngine;
|
|
36
|
+
@end
|
|
37
|
+
|
|
38
|
+
NS_ASSUME_NONNULL_END
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
//
|
|
2
|
+
// VeLivePushImpl.m
|
|
3
|
+
// Pods
|
|
4
|
+
//
|
|
5
|
+
// Created by ByteDance on 2025/9/18.
|
|
6
|
+
//
|
|
7
|
+
|
|
8
|
+
#import "VeLivePushImpl.h"
|
|
9
|
+
#import "VolcApiEngine/VolcEventObserver.h"
|
|
10
|
+
#import <React/RCTBridgeModule.h>
|
|
11
|
+
|
|
12
|
+
@interface VeLivePushImpl()
|
|
13
|
+
|
|
14
|
+
@end
|
|
15
|
+
|
|
16
|
+
@implementation VeLivePushImpl
|
|
17
|
+
|
|
18
|
+
- (instancetype) initWithModule:(NSObject<EventObserver> *)module {
|
|
19
|
+
self = [super init];
|
|
20
|
+
if (self) {
|
|
21
|
+
self.module = module;
|
|
22
|
+
}
|
|
23
|
+
return self;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
- (id)newApiEngine {
|
|
27
|
+
if (self.volcApiEngine == nil) {
|
|
28
|
+
self.volcApiEngine = [[VolcApiEngine alloc] init];
|
|
29
|
+
[self.volcApiEngine setObserver:self.module];
|
|
30
|
+
}
|
|
31
|
+
return nil;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
- (id)destoryApiEngine {
|
|
35
|
+
return nil;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
- (NSDictionary *)callApiSync:(NSDictionary *)args {
|
|
39
|
+
[self newApiEngine];
|
|
40
|
+
return [self.volcApiEngine callApi:args];
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
- (void)callApi:(NSDictionary *)args callback:(void (^)(id))callback {
|
|
44
|
+
[self newApiEngine];
|
|
45
|
+
dispatch_async(dispatch_get_main_queue(), ^{
|
|
46
|
+
id _val = [self.volcApiEngine callApi:args];
|
|
47
|
+
callback(_val);
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
@end
|