@byteplus/react-native-rtc 1.1.2 → 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 -1
- package/android/src/main/java/com/volcengine/reactnative/vertc/events/IRTCRoomEventHandlerImpl.java +53 -8
- package/android/src/main/java/com/volcengine/reactnative/vertc/events/IRTCVideoEventHandlerImpl.java +62 -19
- 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/ios/live/VertcLive.m
CHANGED
|
@@ -6,16 +6,24 @@
|
|
|
6
6
|
#import <TTSDKFramework/TTSDKFramework.h>
|
|
7
7
|
#import <TTSDKFramework/VeLivePusherDef.h>
|
|
8
8
|
#import "VeLivePushHelper.h"
|
|
9
|
+
#import "VertcHelper.h"
|
|
9
10
|
|
|
10
|
-
|
|
11
|
+
@interface VeLiveFpsTracker : NSObject
|
|
12
|
+
- (void)start;
|
|
13
|
+
- (void)stop;
|
|
14
|
+
- (void)updateCaptureVieoWidth:(int)width height:(int)height;
|
|
15
|
+
- (void)updatePreEncodeVieoWidth:(int)width height:(int)height;
|
|
16
|
+
- (void)updateCaptureFrame:(NSInteger)frameCount;
|
|
17
|
+
- (void)updatePreEncodeFrame:(NSInteger)frameCount;
|
|
18
|
+
- (void)updateAfterRTCFrame:(NSInteger)frameCount;
|
|
19
|
+
@end
|
|
11
20
|
|
|
12
21
|
@interface VertcLive ()
|
|
13
|
-
|
|
14
22
|
@property (nonatomic, strong) NSDictionary *options;
|
|
15
23
|
@property (nonatomic, strong) ByteRTCVideo *rtcEngine;
|
|
16
24
|
@property (nonatomic, strong) VeLivePusher *livePusher;
|
|
17
25
|
@property (nonatomic, strong) id<VeLiveVideoFrameListener> videoFrameListener;
|
|
18
|
-
|
|
26
|
+
@property (nonatomic, strong) VeLiveFpsTracker *fpsTracker;
|
|
19
27
|
@end
|
|
20
28
|
|
|
21
29
|
@implementation VertcLive
|
|
@@ -27,6 +35,8 @@
|
|
|
27
35
|
self.livePusher = nil;
|
|
28
36
|
self.rtcEngine = nil;
|
|
29
37
|
self.options = nil;
|
|
38
|
+
[self.fpsTracker stop];
|
|
39
|
+
self.fpsTracker = nil;
|
|
30
40
|
}
|
|
31
41
|
|
|
32
42
|
- (int)startLiveVideoCapture:(ByteRTCVideo *)rtc viewId:(NSString *)viewId options:(NSDictionary *)options {
|
|
@@ -35,6 +45,11 @@
|
|
|
35
45
|
if (pusher == nil) {
|
|
36
46
|
@throw [NSException exceptionWithName:@"unknown videoEngine" reason:@"can't get pusher" userInfo:@{}];
|
|
37
47
|
}
|
|
48
|
+
// if (self.fpsTracker != nil) {
|
|
49
|
+
// [self.fpsTracker stop];
|
|
50
|
+
// } else {
|
|
51
|
+
// self.fpsTracker = [[VeLiveFpsTracker alloc] init];
|
|
52
|
+
// }
|
|
38
53
|
self.rtcEngine = rtc;
|
|
39
54
|
self.options = options;
|
|
40
55
|
self.livePusher = pusher;
|
|
@@ -42,21 +57,18 @@
|
|
|
42
57
|
NSInteger streamIndexValue = [options[@"streamIndex"] integerValue] ?: 0;
|
|
43
58
|
ByteRTCStreamIndex streamIndex = (streamIndexValue == 1) ? ByteRTCStreamIndexScreen : ByteRTCStreamIndexMain;
|
|
44
59
|
[rtc setVideoSourceType:ByteRTCVideoSourceTypeExternal WithStreamIndex:streamIndex];
|
|
45
|
-
|
|
60
|
+
|
|
61
|
+
// [self.fpsTracker start];
|
|
46
62
|
int addRes = [self.livePusher addVideoFrameListener:self];
|
|
47
63
|
NSLog(@"addVideoFrameListener result: %d", addRes);
|
|
48
|
-
|
|
49
64
|
return 0;
|
|
50
65
|
}
|
|
51
66
|
|
|
52
67
|
- (int)stopLiveVideoCapture {
|
|
53
68
|
if (self.rtcEngine == nil || self.livePusher == nil) {
|
|
69
|
+
// [self.fpsTracker stop];
|
|
54
70
|
return 0;
|
|
55
71
|
}
|
|
56
|
-
if (self.livePusher && self.videoFrameListener) {
|
|
57
|
-
[self.livePusher removeVideoFrameListener:self.videoFrameListener];
|
|
58
|
-
self.videoFrameListener = nil;
|
|
59
|
-
}
|
|
60
72
|
NSInteger streamIndexValue = [self.options[@"streamIndex"] integerValue] ?: 0;
|
|
61
73
|
ByteRTCStreamIndex streamIndex = (streamIndexValue == 1) ? ByteRTCStreamIndexScreen : ByteRTCStreamIndexMain;
|
|
62
74
|
[self.rtcEngine setVideoSourceType:ByteRTCVideoSourceTypeInternal WithStreamIndex:streamIndex];
|
|
@@ -66,11 +78,12 @@
|
|
|
66
78
|
self.options = nil;
|
|
67
79
|
self.rtcEngine = nil;
|
|
68
80
|
self.livePusher = nil;
|
|
81
|
+
// [self.fpsTracker stop];
|
|
69
82
|
return 0;
|
|
70
83
|
}
|
|
71
84
|
|
|
72
85
|
- (VeLiveVideoFrameSource)getObservedVideoFrameSource {
|
|
73
|
-
return VeLiveVideoFrameSourcePreEncode;
|
|
86
|
+
return VeLiveVideoFrameSourceCapture | VeLiveVideoFrameSourcePreEncode;
|
|
74
87
|
}
|
|
75
88
|
|
|
76
89
|
- (ByteRTCVideoPixelFormat)convertToRtcPixelFormat:(VeLivePixelFormat)format {
|
|
@@ -85,11 +98,16 @@
|
|
|
85
98
|
return ByteRTCVideoPixelFormatUnknown;
|
|
86
99
|
}
|
|
87
100
|
|
|
101
|
+
- (void)onCaptureVideoFrame:(VeLiveVideoFrame *)frame {
|
|
102
|
+
[self.fpsTracker updateCaptureFrame:1];
|
|
103
|
+
[self.fpsTracker updateCaptureVieoWidth:frame.width height:frame.height];
|
|
104
|
+
}
|
|
105
|
+
|
|
88
106
|
- (void)onPreEncodeVideoFrame:(VeLiveVideoFrame *)frame {
|
|
89
|
-
|
|
107
|
+
// [self.fpsTracker updatePreEncodeFrame:1];
|
|
108
|
+
// [self.fpsTracker updatePreEncodeVieoWidth:frame.width height:frame.height];
|
|
90
109
|
NSInteger streamIndexValue = [self.options[@"streamIndex"] integerValue] ?: 0;
|
|
91
110
|
ByteRTCStreamIndex streamIndex = (streamIndexValue == 1) ? ByteRTCStreamIndexScreen : ByteRTCStreamIndexMain;
|
|
92
|
-
|
|
93
111
|
int res = 0;
|
|
94
112
|
if (streamIndex == ByteRTCStreamIndexMain) {
|
|
95
113
|
ByteRTCVideoPixelFormat pixelFormat = [self convertToRtcPixelFormat:frame.pixelFormat];
|
|
@@ -112,9 +130,12 @@
|
|
|
112
130
|
}
|
|
113
131
|
|
|
114
132
|
res = [self.rtcEngine pushExternalVideoFrame: videoFrame];
|
|
133
|
+
|
|
134
|
+
// [self.fpsTracker updateAfterRTCFrame:1];
|
|
115
135
|
}
|
|
116
136
|
if (streamIndex == ByteRTCStreamIndexScreen) {
|
|
117
137
|
res = [self.rtcEngine pushScreenVideoFrame:frame.pixelBuffer time:frame.pts rotation:frame.rotation];
|
|
138
|
+
// [self.fpsTracker updateAfterRTCFrame:1];
|
|
118
139
|
}
|
|
119
140
|
if (res != 0 && res != -202) {
|
|
120
141
|
NSLog(@"bytertc push video frame fail return '%d'", res);
|
|
@@ -122,3 +143,134 @@
|
|
|
122
143
|
}
|
|
123
144
|
|
|
124
145
|
@end
|
|
146
|
+
|
|
147
|
+
@protocol VeLiveTrackerProtocol <NSObject>
|
|
148
|
+
+ (void)sendPusherEventWith:(NSString *)eventKey api:(nullable NSString *)api value:(nullable id)value result:(nullable id)result;
|
|
149
|
+
@end
|
|
150
|
+
|
|
151
|
+
@interface VeLiveFpsTracker ()
|
|
152
|
+
@property (nonatomic, strong) Class <VeLiveTrackerProtocol> trackerCls;
|
|
153
|
+
@property (nonatomic, assign) NSTimeInterval lastTimestamp;
|
|
154
|
+
@property (nonatomic, assign) NSInteger captureFrameCount;
|
|
155
|
+
@property (nonatomic, assign) NSInteger preEncodeFrameCount;
|
|
156
|
+
@property (nonatomic, assign) NSInteger afterRtcFrameCount;
|
|
157
|
+
@property (nonatomic, strong) dispatch_queue_t queue;
|
|
158
|
+
@property (nonatomic, copy) NSString *timerName;
|
|
159
|
+
@property (nonatomic, assign) CGSize captureSize;
|
|
160
|
+
@property (nonatomic, assign) CGSize preEncodeSize;
|
|
161
|
+
@end
|
|
162
|
+
|
|
163
|
+
@implementation VeLiveFpsTracker
|
|
164
|
+
- (instancetype)init {
|
|
165
|
+
if (self = [super init]) {
|
|
166
|
+
_timerName = @"VeLiveFpsTracker";
|
|
167
|
+
_trackerCls = NSClassFromString(@"VeLiveTracker");
|
|
168
|
+
_queue = dispatch_queue_create("VeLiveFpsTracker-Queue", DISPATCH_QUEUE_SERIAL);
|
|
169
|
+
}
|
|
170
|
+
return self;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
- (void)start {
|
|
174
|
+
[self clearFrameRecordAsync:NSDate.date.timeIntervalSince1970 * 1000];
|
|
175
|
+
__weak __typeof(self)weakSelf = self;
|
|
176
|
+
[[VertcHelper getInstance] schedualTimerWithIdentifier:self.timerName
|
|
177
|
+
interval:2
|
|
178
|
+
queue:self.queue
|
|
179
|
+
repeats:YES
|
|
180
|
+
action:^{
|
|
181
|
+
__strong __typeof(weakSelf)self = weakSelf;
|
|
182
|
+
[self reportIfNeed];
|
|
183
|
+
}];
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
- (void)stop {
|
|
187
|
+
[[VertcHelper getInstance] cancelTimerWithName:_timerName];
|
|
188
|
+
[self clearFrameRecordAsync:0];
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
- (void)clearFrameRecordAsync:(NSTimeInterval)timestamp {
|
|
192
|
+
__weak __typeof(self)weakSelf = self;
|
|
193
|
+
dispatch_async(self.queue, ^{
|
|
194
|
+
__strong __typeof(weakSelf)self = weakSelf;
|
|
195
|
+
[self clearFrameRecord:timestamp];
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
- (void)clearFrameRecord:(NSTimeInterval)timestamp {
|
|
200
|
+
self.lastTimestamp = timestamp;
|
|
201
|
+
self.captureFrameCount = 0;
|
|
202
|
+
self.preEncodeFrameCount = 0;
|
|
203
|
+
self.afterRtcFrameCount = 0;
|
|
204
|
+
self.captureSize = CGSizeZero;
|
|
205
|
+
self.preEncodeSize = CGSizeZero;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
- (void)updateCaptureFrame:(NSInteger)frameCount {
|
|
209
|
+
__weak __typeof(self)weakSelf = self;
|
|
210
|
+
dispatch_async(self.queue, ^{
|
|
211
|
+
__strong __typeof(weakSelf)self = weakSelf;
|
|
212
|
+
self.captureFrameCount += frameCount;
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
- (void)updatePreEncodeFrame:(NSInteger)frameCount {
|
|
217
|
+
__weak __typeof(self)weakSelf = self;
|
|
218
|
+
dispatch_async(self.queue, ^{
|
|
219
|
+
__strong __typeof(weakSelf)self = weakSelf;
|
|
220
|
+
self.preEncodeFrameCount += frameCount;
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
- (void)updateAfterRTCFrame:(NSInteger)frameCount {
|
|
225
|
+
__weak __typeof(self)weakSelf = self;
|
|
226
|
+
dispatch_async(self.queue, ^{
|
|
227
|
+
__strong __typeof(weakSelf)self = weakSelf;
|
|
228
|
+
self.afterRtcFrameCount += frameCount;
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
- (void)updateCaptureVieoWidth:(int)width height:(int)height {
|
|
233
|
+
__weak __typeof(self)weakSelf = self;
|
|
234
|
+
dispatch_async(self.queue, ^{
|
|
235
|
+
__strong __typeof(weakSelf)self = weakSelf;
|
|
236
|
+
self.captureSize = CGSizeMake((CGFloat)width, (CGFloat)height);
|
|
237
|
+
});
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
- (void)updatePreEncodeVieoWidth:(int)width height:(int)height {
|
|
241
|
+
__weak __typeof(self)weakSelf = self;
|
|
242
|
+
dispatch_async(self.queue, ^{
|
|
243
|
+
__strong __typeof(weakSelf)self = weakSelf;
|
|
244
|
+
self.preEncodeSize = CGSizeMake((CGFloat)width, (CGFloat)height);
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
- (void)reportIfNeed {
|
|
249
|
+
NSTimeInterval currentTime = NSDate.date.timeIntervalSince1970 * 1000;
|
|
250
|
+
NSTimeInterval duration = MAX(1, currentTime - self.lastTimestamp);
|
|
251
|
+
|
|
252
|
+
int captureFps = (int)((self.captureFrameCount * 1000.0) / duration);
|
|
253
|
+
int preEncodeFps = (int)((self.preEncodeFrameCount * 1000.0) / duration);
|
|
254
|
+
int afterRtcFps = (int)((self.afterRtcFrameCount * 1000.0) / duration);
|
|
255
|
+
|
|
256
|
+
[self reportEvent:@"livcore_statistics_fps" value:@{
|
|
257
|
+
@"captureFps" : @(captureFps),
|
|
258
|
+
@"preEncodeFps" : @(preEncodeFps),
|
|
259
|
+
@"afterRtcFps" : @(afterRtcFps),
|
|
260
|
+
@"captureSize" : NSStringFromCGSize(self.captureSize),
|
|
261
|
+
@"preEncodeSize" : NSStringFromCGSize(self.preEncodeSize),
|
|
262
|
+
}];
|
|
263
|
+
[self clearFrameRecord:currentTime];
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
- (void)reportEvent:(NSString *)key value:(NSDictionary *)value {
|
|
267
|
+
if (self.trackerCls != nil
|
|
268
|
+
&& [self.trackerCls respondsToSelector:@selector(sendPusherEventWith:api:value:result:)]) {
|
|
269
|
+
[self.trackerCls sendPusherEventWith:key api:@"" value:value result:@""];
|
|
270
|
+
}
|
|
271
|
+
#if DEBUG
|
|
272
|
+
NSLog(@"report: %@ %@", key, value);
|
|
273
|
+
#endif
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
@end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// Copyright © 2022 BytePlusRTC All rights reserved.
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
4
|
+
//
|
|
5
|
+
// VertcModule.h
|
|
6
|
+
//
|
|
7
|
+
|
|
8
|
+
#import <Foundation/Foundation.h>
|
|
9
|
+
#import <React/RCTBridgeModule.h>
|
|
10
|
+
#import <React/RCTEventEmitter.h>
|
|
11
|
+
#import "VolcApiEngine/Engine.h"
|
|
12
|
+
#import "VolcApiEngine/VolcEventObserver.h"
|
|
13
|
+
#import "VertcImpl.h"
|
|
14
|
+
#import "VertcSpec/VertcSpec.h"
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
@interface RCTVertc : RCTEventEmitter <RCTBridgeModule, EventObserver, NativeVertcSpec>
|
|
18
|
+
|
|
19
|
+
@property(nonatomic, strong) VertcImpl* impl;
|
|
20
|
+
|
|
21
|
+
+ (instancetype)shareInstance;
|
|
22
|
+
|
|
23
|
+
@end
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
//
|
|
2
|
+
// VertcModule.m
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
#import <UIKit/UIKit.h>
|
|
6
|
+
#import <Foundation/Foundation.h>
|
|
7
|
+
#import "VolcApiEngine/VolcEventObserver.h"
|
|
8
|
+
#import <React/RCTEventEmitter.h>
|
|
9
|
+
#import "VolcApiEngine/VolcEventObserver.h"
|
|
10
|
+
#import "VertcApiEngine.h"
|
|
11
|
+
#import "RTCHeader.h"
|
|
12
|
+
#import "RCTVertc.h"
|
|
13
|
+
#import "VertcImpl.h"
|
|
14
|
+
#import <VertcSpec/VertcSpec.h>
|
|
15
|
+
|
|
16
|
+
#define EVENT_NAME @"VertcModule:onEvent"
|
|
17
|
+
|
|
18
|
+
@interface RCTVertc () <NativeVertcSpec>
|
|
19
|
+
|
|
20
|
+
@end
|
|
21
|
+
|
|
22
|
+
static RCTVertc *instance = nil;
|
|
23
|
+
|
|
24
|
+
@implementation RCTVertc {
|
|
25
|
+
bool hasListeners;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
+ (instancetype)shareInstance {
|
|
29
|
+
return instance;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
//@See https://stackoverflow.com/questions/50773748/difference-requiresmainqueuesetup-and-dispatch-get-main-queue
|
|
33
|
+
+ (BOOL)requiresMainQueueSetup {
|
|
34
|
+
return YES;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
- (dispatch_queue_t)methodQueue {
|
|
38
|
+
return dispatch_get_main_queue();
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
- (instancetype) init {
|
|
42
|
+
self = [super init];
|
|
43
|
+
if (self) {
|
|
44
|
+
instance = self;
|
|
45
|
+
self.impl = [[VertcImpl alloc] initWithModule: instance];
|
|
46
|
+
}
|
|
47
|
+
return self;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
- (NSArray<NSString *> *)supportedEvents {
|
|
51
|
+
return @[ EVENT_NAME ];
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
- (void)onEvent:(NSString *)eventName data:(id)eventData {
|
|
55
|
+
NSDictionary *dic = @{@"event" : eventName, @"data" : eventData};
|
|
56
|
+
[self sendEventWithName:EVENT_NAME body:dic];
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
RCT_EXPORT_MODULE(Vertc)
|
|
60
|
+
|
|
61
|
+
- (NSNumber *)newApiEngine {
|
|
62
|
+
return [self.impl newApiEngine];
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
- (void)call:(NSString *)params
|
|
66
|
+
callback: (RCTResponseSenderBlock)callback {
|
|
67
|
+
NSDictionary * args = @{@"params": params};
|
|
68
|
+
[self.impl callApi:args callback:^(id _Nonnull res) {
|
|
69
|
+
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:res options:0 error:nil];
|
|
70
|
+
NSString* jsonResult = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
|
|
71
|
+
callback(@[jsonResult]);
|
|
72
|
+
}];
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
- (NSString *)callSync: (NSString *) params {
|
|
76
|
+
NSDictionary* args = @{@"params": params};
|
|
77
|
+
NSDictionary* result = [self.impl callApiSync: args];
|
|
78
|
+
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:result options:0 error:nil];
|
|
79
|
+
NSString* jsonResult = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
|
|
80
|
+
return jsonResult;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
- (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:
|
|
84
|
+
(const facebook::react::ObjCTurboModule::InitParams &)params
|
|
85
|
+
{
|
|
86
|
+
return std::make_shared<facebook::react::NativeVertcSpecJSI>(params);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
@end
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// Copyright © 2022 BytePlusRTC All rights reserved.
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
4
|
+
//
|
|
5
|
+
// VertcImpl.h
|
|
6
|
+
// Pods
|
|
7
|
+
//
|
|
8
|
+
// Created by ByteDance on 2025/10/28.
|
|
9
|
+
//
|
|
10
|
+
#import <Foundation/Foundation.h>
|
|
11
|
+
#import "VolcApiEngine/Engine.h"
|
|
12
|
+
#import "VolcApiEngine/VolcEventObserver.h"
|
|
13
|
+
|
|
14
|
+
NS_ASSUME_NONNULL_BEGIN
|
|
15
|
+
|
|
16
|
+
@interface VertcImpl : NSObject
|
|
17
|
+
|
|
18
|
+
@property(nonatomic, strong) VolcApiEngine *volcApiEngine;
|
|
19
|
+
|
|
20
|
+
@property(nonatomic, weak) NSObject<EventObserver>* module;
|
|
21
|
+
|
|
22
|
+
- (NSDictionary *) callApiSync: (nonnull NSDictionary*) args;
|
|
23
|
+
|
|
24
|
+
- (void)callApi: (nonnull NSDictionary*) args
|
|
25
|
+
callback: (void (^)(id))callback;
|
|
26
|
+
|
|
27
|
+
- (instancetype) initWithModule:(NSObject<EventObserver> *)module;
|
|
28
|
+
|
|
29
|
+
- (id)newApiEngine;
|
|
30
|
+
|
|
31
|
+
@end
|
|
32
|
+
|
|
33
|
+
NS_ASSUME_NONNULL_END
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
// Copyright © 2022 BytePlusRTC All rights reserved.
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
4
|
+
//
|
|
5
|
+
// VertcImpl.m
|
|
6
|
+
// react-native-rtc
|
|
7
|
+
//
|
|
8
|
+
// Created by ByteDance on 2025/10/28.
|
|
9
|
+
//
|
|
10
|
+
|
|
11
|
+
#import "VertcImpl.h"
|
|
12
|
+
#import "VertcApiEngine.h"
|
|
13
|
+
#import "VolcApiEngine/VolcEventObserver.h"
|
|
14
|
+
#import <React/RCTBridgeModule.h>
|
|
15
|
+
|
|
16
|
+
@interface VertcImpl()
|
|
17
|
+
|
|
18
|
+
@end
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
@implementation VertcImpl
|
|
22
|
+
|
|
23
|
+
- (instancetype) initWithModule:(NSObject<EventObserver> *)module {
|
|
24
|
+
self = [super init];
|
|
25
|
+
if (self) {
|
|
26
|
+
self.module = module;
|
|
27
|
+
}
|
|
28
|
+
return self;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
- (id)newApiEngine {
|
|
32
|
+
if (self.volcApiEngine == nil) {
|
|
33
|
+
self.volcApiEngine = [[VolcApiEngine alloc] init];
|
|
34
|
+
[self.volcApiEngine setObserver:self.module];
|
|
35
|
+
[VertcApiEngine.sharedInstance setApiEngine:[self volcApiEngine]];
|
|
36
|
+
}
|
|
37
|
+
return nil;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
- (NSDictionary *)callApiSync:(NSDictionary *)args {
|
|
41
|
+
[self newApiEngine];
|
|
42
|
+
return [self.volcApiEngine callApi:args];
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
- (void)callApi:(NSDictionary *)args callback:(void (^)(id))callback {
|
|
46
|
+
[self newApiEngine];
|
|
47
|
+
dispatch_async(dispatch_get_main_queue(), ^{
|
|
48
|
+
id _val = [self.volcApiEngine callApi:args];
|
|
49
|
+
callback(@[_val]);
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
@end
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
// Copyright © 2022 BytePlusRTC All rights reserved.
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
4
|
+
//
|
|
5
|
+
// VeUIView.m
|
|
6
|
+
// rn
|
|
7
|
+
//
|
|
8
|
+
// Created by ByteDance on 2024/3/27.
|
|
9
|
+
//
|
|
10
|
+
|
|
11
|
+
#import <Foundation/Foundation.h>
|
|
12
|
+
#import <React/RCTViewManager.h>
|
|
13
|
+
#import "VolcApiEngine/VolcViewManager.h"
|
|
14
|
+
#import "VertcView.h"
|
|
15
|
+
|
|
16
|
+
@interface VertcViewManager : RCTViewManager
|
|
17
|
+
|
|
18
|
+
@end
|
|
19
|
+
|
|
20
|
+
@implementation VertcViewManager
|
|
21
|
+
|
|
22
|
+
RCT_EXPORT_MODULE(VertcView)
|
|
23
|
+
|
|
24
|
+
RCT_EXPORT_VIEW_PROPERTY(onViewLoad, RCTBubblingEventBlock)
|
|
25
|
+
|
|
26
|
+
RCT_CUSTOM_VIEW_PROPERTY(viewId, NSString, VertcView)
|
|
27
|
+
{
|
|
28
|
+
if (json == nil) {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
NSString * viewId = [RCTConvert NSString:json];
|
|
33
|
+
[view setViewId:viewId];
|
|
34
|
+
[VolcViewManager registerView:viewId view:view];
|
|
35
|
+
NSLog(@"[View] register view success viewId=%@", viewId);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
RCT_CUSTOM_VIEW_PROPERTY(kind, NSString, VertcView)
|
|
39
|
+
{
|
|
40
|
+
if (json == nil) {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
- (VertcView *)view
|
|
46
|
+
{
|
|
47
|
+
VertcView *view = [[VertcView alloc] init];
|
|
48
|
+
return view;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
@end
|