tirtc-react-native 2.2.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.
Files changed (104) hide show
  1. package/LICENSE +11 -0
  2. package/README.md +140 -0
  3. package/TiRtcReactNative.podspec +35 -0
  4. package/android/build.gradle +37 -0
  5. package/android/src/main/AndroidManifest.xml +1 -0
  6. package/android/src/main/java/com/tange/ai/tirtc/reactnative/TiRtcModule.kt +482 -0
  7. package/android/src/main/java/com/tange/ai/tirtc/reactnative/TiRtcPackage.kt +43 -0
  8. package/android/src/main/java/com/tange/ai/tirtc/reactnative/TiRtcReactNativeErrors.kt +32 -0
  9. package/android/src/main/java/com/tange/ai/tirtc/reactnative/TiRtcReactNativeEventBinder.kt +99 -0
  10. package/android/src/main/java/com/tange/ai/tirtc/reactnative/TiRtcReactNativeEventSink.kt +168 -0
  11. package/android/src/main/java/com/tange/ai/tirtc/reactnative/TiRtcReactNativeMaps.kt +49 -0
  12. package/android/src/main/java/com/tange/ai/tirtc/reactnative/TiRtcReactNativeMetricsMaps.kt +173 -0
  13. package/android/src/main/java/com/tange/ai/tirtc/reactnative/TiRtcReactNativeModuleSupport.kt +91 -0
  14. package/android/src/main/java/com/tange/ai/tirtc/reactnative/TiRtcReactNativeOptions.kt +127 -0
  15. package/android/src/main/java/com/tange/ai/tirtc/reactnative/TiRtcReactNativeRegistry.kt +71 -0
  16. package/android/src/main/java/com/tange/ai/tirtc/reactnative/TiRtcVideoInputPreviewManager.kt +109 -0
  17. package/android/src/main/java/com/tange/ai/tirtc/reactnative/TiRtcVideoOutputViewManager.kt +109 -0
  18. package/ios/TiRtcReactNative+Conn.mm +112 -0
  19. package/ios/TiRtcReactNative+Input.mm +196 -0
  20. package/ios/TiRtcReactNative+Output.mm +172 -0
  21. package/ios/TiRtcReactNative+Private.h +28 -0
  22. package/ios/TiRtcReactNative.h +6 -0
  23. package/ios/TiRtcReactNative.mm +189 -0
  24. package/ios/TiRtcReactNativeErrors.h +18 -0
  25. package/ios/TiRtcReactNativeErrors.mm +105 -0
  26. package/ios/TiRtcReactNativeEventBinder.h +19 -0
  27. package/ios/TiRtcReactNativeEventBinder.mm +226 -0
  28. package/ios/TiRtcReactNativeEventSink.h +29 -0
  29. package/ios/TiRtcReactNativeEventSink.mm +125 -0
  30. package/ios/TiRtcReactNativeMaps.h +21 -0
  31. package/ios/TiRtcReactNativeMaps.mm +249 -0
  32. package/ios/TiRtcReactNativeNative.h +8 -0
  33. package/ios/TiRtcReactNativeOptions.h +11 -0
  34. package/ios/TiRtcReactNativeOptions.mm +123 -0
  35. package/ios/TiRtcReactNativeRegistry.h +20 -0
  36. package/ios/TiRtcReactNativeRegistry.mm +119 -0
  37. package/ios/TiRtcVideoInputPreview.h +5 -0
  38. package/ios/TiRtcVideoInputPreview.mm +149 -0
  39. package/ios/TiRtcVideoOutputView.h +5 -0
  40. package/ios/TiRtcVideoOutputView.mm +149 -0
  41. package/lib/module/audio_input.js +177 -0
  42. package/lib/module/audio_input.js.map +1 -0
  43. package/lib/module/audio_output.js +168 -0
  44. package/lib/module/audio_output.js.map +1 -0
  45. package/lib/module/conn.js +174 -0
  46. package/lib/module/conn.js.map +1 -0
  47. package/lib/module/errors.js +63 -0
  48. package/lib/module/errors.js.map +1 -0
  49. package/lib/module/events.js +37 -0
  50. package/lib/module/events.js.map +1 -0
  51. package/lib/module/index.js +9 -0
  52. package/lib/module/index.js.map +1 -0
  53. package/lib/module/logging.js +26 -0
  54. package/lib/module/logging.js.map +1 -0
  55. package/lib/module/native.js +5 -0
  56. package/lib/module/native.js.map +1 -0
  57. package/lib/module/native_object_id.js +47 -0
  58. package/lib/module/native_object_id.js.map +1 -0
  59. package/lib/module/runtime.js +27 -0
  60. package/lib/module/runtime.js.map +1 -0
  61. package/lib/module/specs/NativeTiRtc.js +3 -0
  62. package/lib/module/specs/NativeTiRtc.js.map +1 -0
  63. package/lib/module/specs/TiRtcVideoInputPreviewNativeComponent.js +24 -0
  64. package/lib/module/specs/TiRtcVideoOutputViewNativeComponent.js +24 -0
  65. package/lib/module/types.js +93 -0
  66. package/lib/module/types.js.map +1 -0
  67. package/lib/module/video_input.js +266 -0
  68. package/lib/module/video_input.js.map +1 -0
  69. package/lib/module/video_output.js +224 -0
  70. package/lib/module/video_output.js.map +1 -0
  71. package/lib/typescript/audio_input.d.ts +25 -0
  72. package/lib/typescript/audio_output.d.ts +25 -0
  73. package/lib/typescript/conn.d.ts +28 -0
  74. package/lib/typescript/errors.d.ts +19 -0
  75. package/lib/typescript/events.d.ts +6 -0
  76. package/lib/typescript/index.d.ts +9 -0
  77. package/lib/typescript/logging.d.ts +9 -0
  78. package/lib/typescript/native.d.ts +5 -0
  79. package/lib/typescript/native_object_id.d.ts +12 -0
  80. package/lib/typescript/runtime.d.ts +8 -0
  81. package/lib/typescript/specs/NativeTiRtc.d.ts +223 -0
  82. package/lib/typescript/specs/TiRtcVideoInputPreviewNativeComponent.d.ts +8 -0
  83. package/lib/typescript/specs/TiRtcVideoOutputViewNativeComponent.d.ts +8 -0
  84. package/lib/typescript/types.d.ts +281 -0
  85. package/lib/typescript/video_input.d.ts +50 -0
  86. package/lib/typescript/video_output.d.ts +46 -0
  87. package/package.json +80 -0
  88. package/react-native.config.js +10 -0
  89. package/src/audio_input.ts +205 -0
  90. package/src/audio_output.ts +202 -0
  91. package/src/conn.ts +222 -0
  92. package/src/errors.ts +81 -0
  93. package/src/events.ts +44 -0
  94. package/src/index.ts +61 -0
  95. package/src/logging.ts +33 -0
  96. package/src/native.ts +6 -0
  97. package/src/native_object_id.ts +63 -0
  98. package/src/runtime.ts +32 -0
  99. package/src/specs/NativeTiRtc.ts +256 -0
  100. package/src/specs/TiRtcVideoInputPreviewNativeComponent.ts +14 -0
  101. package/src/specs/TiRtcVideoOutputViewNativeComponent.ts +12 -0
  102. package/src/types.ts +340 -0
  103. package/src/video_input.ts +314 -0
  104. package/src/video_output.ts +273 -0
@@ -0,0 +1,226 @@
1
+ #import "TiRtcReactNativeEventBinder.h"
2
+
3
+ #import "TiRtcReactNativeErrors.h"
4
+ #import "TiRtcReactNativeEventSink.h"
5
+ #import "TiRtcReactNativeNative.h"
6
+ #import "TiRtcReactNativeRegistry.h"
7
+
8
+ @interface TiRtcReactNativeConnDelegate : NSObject <TiRtcConnDelegate>
9
+ - (instancetype)initWithObjectId:(NSInteger)objectId
10
+ eventSink:(TiRtcReactNativeEventSink*)eventSink;
11
+ @end
12
+
13
+ @implementation TiRtcReactNativeConnDelegate {
14
+ NSInteger _objectId;
15
+ TiRtcReactNativeEventSink* _eventSink;
16
+ }
17
+
18
+ - (instancetype)initWithObjectId:(NSInteger)objectId
19
+ eventSink:(TiRtcReactNativeEventSink*)eventSink {
20
+ if (self = [super init]) {
21
+ _objectId = objectId;
22
+ _eventSink = eventSink;
23
+ }
24
+ return self;
25
+ }
26
+
27
+ - (void)conn:(TiRtcConn*)conn didChangeState:(TiRtcConnState)state errorCode:(int32_t)errorCode {
28
+ [_eventSink connStateChanged:_objectId
29
+ state:TiRtcReactNativeConnStateString(state)
30
+ errorCode:errorCode];
31
+ }
32
+
33
+ - (void)conn:(TiRtcConn*)conn didReceiveCommand:(uint32_t)commandId data:(NSData*)data {
34
+ [_eventSink connCommand:_objectId commandId:commandId data:data];
35
+ }
36
+
37
+ - (void)conn:(TiRtcConn*)conn
38
+ didReceiveStreamMessage:(uint8_t)streamId
39
+ timestampMs:(uint32_t)timestampMs
40
+ data:(NSData*)data {
41
+ [_eventSink connStreamMessage:_objectId streamId:streamId timestampMs:timestampMs data:data];
42
+ }
43
+
44
+ @end
45
+
46
+ @interface TiRtcReactNativeAudioOutputDelegate : NSObject <TiRtcAudioOutputDelegate>
47
+ - (instancetype)initWithObjectId:(NSInteger)objectId
48
+ eventSink:(TiRtcReactNativeEventSink*)eventSink;
49
+ @end
50
+
51
+ @implementation TiRtcReactNativeAudioOutputDelegate {
52
+ NSInteger _objectId;
53
+ TiRtcReactNativeEventSink* _eventSink;
54
+ }
55
+
56
+ - (instancetype)initWithObjectId:(NSInteger)objectId
57
+ eventSink:(TiRtcReactNativeEventSink*)eventSink {
58
+ if (self = [super init]) {
59
+ _objectId = objectId;
60
+ _eventSink = eventSink;
61
+ }
62
+ return self;
63
+ }
64
+
65
+ - (void)audioOutput:(TiRtcAudioOutput*)output didChangeState:(TiRtcAudioOutputState)state {
66
+ [_eventSink audioOutputStateChanged:_objectId
67
+ state:TiRtcReactNativeAudioOutputStateString(state)];
68
+ }
69
+
70
+ - (void)audioOutput:(TiRtcAudioOutput*)output
71
+ didFailWithCode:(int32_t)code
72
+ message:(NSString*)message {
73
+ [_eventSink audioOutputError:_objectId code:code message:message];
74
+ }
75
+
76
+ @end
77
+
78
+ @interface TiRtcReactNativeVideoOutputDelegate : NSObject <TiRtcVideoOutputDelegate>
79
+ - (instancetype)initWithObjectId:(NSInteger)objectId
80
+ eventSink:(TiRtcReactNativeEventSink*)eventSink;
81
+ @end
82
+
83
+ @implementation TiRtcReactNativeVideoOutputDelegate {
84
+ NSInteger _objectId;
85
+ TiRtcReactNativeEventSink* _eventSink;
86
+ }
87
+
88
+ - (instancetype)initWithObjectId:(NSInteger)objectId
89
+ eventSink:(TiRtcReactNativeEventSink*)eventSink {
90
+ if (self = [super init]) {
91
+ _objectId = objectId;
92
+ _eventSink = eventSink;
93
+ }
94
+ return self;
95
+ }
96
+
97
+ - (void)videoOutput:(TiRtcVideoOutput*)output didChangeState:(TiRtcVideoOutputState)state {
98
+ [_eventSink videoOutputStateChanged:_objectId
99
+ state:TiRtcReactNativeVideoOutputStateString(state)];
100
+ }
101
+
102
+ - (void)videoOutput:(TiRtcVideoOutput*)output didChangeRenderSize:(CGSize)size {
103
+ [_eventSink videoOutputRenderSizeChanged:_objectId size:size];
104
+ }
105
+
106
+ - (void)videoOutput:(TiRtcVideoOutput*)output
107
+ didFailWithCode:(int32_t)code
108
+ message:(NSString*)message {
109
+ [_eventSink videoOutputError:_objectId code:code message:message];
110
+ }
111
+
112
+ @end
113
+
114
+ @interface TiRtcReactNativeAudioInputDelegate : NSObject <TiRtcAudioInputDelegate>
115
+ - (instancetype)initWithObjectId:(NSInteger)objectId
116
+ eventSink:(TiRtcReactNativeEventSink*)eventSink;
117
+ @end
118
+
119
+ @implementation TiRtcReactNativeAudioInputDelegate {
120
+ NSInteger _objectId;
121
+ TiRtcReactNativeEventSink* _eventSink;
122
+ }
123
+
124
+ - (instancetype)initWithObjectId:(NSInteger)objectId
125
+ eventSink:(TiRtcReactNativeEventSink*)eventSink {
126
+ if (self = [super init]) {
127
+ _objectId = objectId;
128
+ _eventSink = eventSink;
129
+ }
130
+ return self;
131
+ }
132
+
133
+ - (void)audioInput:(TiRtcAudioInput*)input didChangeState:(TiRtcInputState)state {
134
+ [_eventSink audioInputStateChanged:_objectId state:TiRtcReactNativeInputStateString(state)];
135
+ }
136
+
137
+ - (void)audioInput:(TiRtcAudioInput*)input
138
+ didFailWithCode:(int32_t)code
139
+ message:(NSString*)message {
140
+ [_eventSink audioInputError:_objectId code:code message:message];
141
+ }
142
+
143
+ @end
144
+
145
+ @interface TiRtcReactNativeVideoInputDelegate : NSObject <TiRtcVideoInputDelegate>
146
+ - (instancetype)initWithObjectId:(NSInteger)objectId
147
+ eventSink:(TiRtcReactNativeEventSink*)eventSink;
148
+ @end
149
+
150
+ @implementation TiRtcReactNativeVideoInputDelegate {
151
+ NSInteger _objectId;
152
+ TiRtcReactNativeEventSink* _eventSink;
153
+ }
154
+
155
+ - (instancetype)initWithObjectId:(NSInteger)objectId
156
+ eventSink:(TiRtcReactNativeEventSink*)eventSink {
157
+ if (self = [super init]) {
158
+ _objectId = objectId;
159
+ _eventSink = eventSink;
160
+ }
161
+ return self;
162
+ }
163
+
164
+ - (void)videoInput:(TiRtcVideoInput*)input didChangeState:(TiRtcInputState)state {
165
+ [_eventSink videoInputStateChanged:_objectId state:TiRtcReactNativeInputStateString(state)];
166
+ }
167
+
168
+ - (void)videoInput:(TiRtcVideoInput*)input didChangeActualConfig:(CGSize)size fps:(int32_t)fps {
169
+ [_eventSink videoInputActualConfigChanged:_objectId size:size fps:fps];
170
+ }
171
+
172
+ - (void)videoInput:(TiRtcVideoInput*)input
173
+ didFailWithCode:(int32_t)code
174
+ message:(NSString*)message {
175
+ [_eventSink videoInputError:_objectId code:code message:message];
176
+ }
177
+
178
+ @end
179
+
180
+ @implementation TiRtcReactNativeEventBinder {
181
+ TiRtcReactNativeEventSink* _eventSink;
182
+ }
183
+
184
+ - (instancetype)initWithEventSink:(TiRtcReactNativeEventSink*)eventSink {
185
+ if (self = [super init]) {
186
+ _eventSink = eventSink;
187
+ }
188
+ return self;
189
+ }
190
+
191
+ - (id)wireConn:(TiRtcConn*)conn objectId:(NSInteger)objectId {
192
+ TiRtcReactNativeConnDelegate* delegate =
193
+ [[TiRtcReactNativeConnDelegate alloc] initWithObjectId:objectId eventSink:_eventSink];
194
+ conn.delegate = delegate;
195
+ return delegate;
196
+ }
197
+
198
+ - (id)wireAudioOutput:(TiRtcAudioOutput*)output objectId:(NSInteger)objectId {
199
+ TiRtcReactNativeAudioOutputDelegate* delegate =
200
+ [[TiRtcReactNativeAudioOutputDelegate alloc] initWithObjectId:objectId eventSink:_eventSink];
201
+ output.delegate = delegate;
202
+ return delegate;
203
+ }
204
+
205
+ - (id)wireVideoOutput:(TiRtcVideoOutput*)output objectId:(NSInteger)objectId {
206
+ TiRtcReactNativeVideoOutputDelegate* delegate =
207
+ [[TiRtcReactNativeVideoOutputDelegate alloc] initWithObjectId:objectId eventSink:_eventSink];
208
+ output.delegate = delegate;
209
+ return delegate;
210
+ }
211
+
212
+ - (id)wireAudioInput:(TiRtcAudioInput*)input objectId:(NSInteger)objectId {
213
+ TiRtcReactNativeAudioInputDelegate* delegate =
214
+ [[TiRtcReactNativeAudioInputDelegate alloc] initWithObjectId:objectId eventSink:_eventSink];
215
+ input.delegate = delegate;
216
+ return delegate;
217
+ }
218
+
219
+ - (id)wireVideoInput:(TiRtcVideoInput*)input objectId:(NSInteger)objectId {
220
+ TiRtcReactNativeVideoInputDelegate* delegate =
221
+ [[TiRtcReactNativeVideoInputDelegate alloc] initWithObjectId:objectId eventSink:_eventSink];
222
+ input.delegate = delegate;
223
+ return delegate;
224
+ }
225
+
226
+ @end
@@ -0,0 +1,29 @@
1
+ #import <CoreGraphics/CoreGraphics.h>
2
+ #import <Foundation/Foundation.h>
3
+
4
+ typedef void (^TiRtcReactNativeEmitBlock)(NSDictionary* event);
5
+
6
+ @class TiRtcReactNativeRegistry;
7
+
8
+ @interface TiRtcReactNativeEventSink : NSObject
9
+
10
+ - (instancetype)initWithRegistry:(TiRtcReactNativeRegistry*)registry
11
+ emitBlock:(TiRtcReactNativeEmitBlock)emitBlock;
12
+ - (void)connStateChanged:(NSInteger)objectId state:(NSString*)state errorCode:(int32_t)errorCode;
13
+ - (void)connCommand:(NSInteger)objectId commandId:(uint32_t)commandId data:(NSData*)data;
14
+ - (void)connStreamMessage:(NSInteger)objectId
15
+ streamId:(uint8_t)streamId
16
+ timestampMs:(uint32_t)timestampMs
17
+ data:(NSData*)data;
18
+ - (void)audioOutputStateChanged:(NSInteger)objectId state:(NSString*)state;
19
+ - (void)audioOutputError:(NSInteger)objectId code:(int32_t)code message:(NSString*)message;
20
+ - (void)videoOutputStateChanged:(NSInteger)objectId state:(NSString*)state;
21
+ - (void)videoOutputRenderSizeChanged:(NSInteger)objectId size:(CGSize)size;
22
+ - (void)videoOutputError:(NSInteger)objectId code:(int32_t)code message:(NSString*)message;
23
+ - (void)audioInputStateChanged:(NSInteger)objectId state:(NSString*)state;
24
+ - (void)audioInputError:(NSInteger)objectId code:(int32_t)code message:(NSString*)message;
25
+ - (void)videoInputStateChanged:(NSInteger)objectId state:(NSString*)state;
26
+ - (void)videoInputActualConfigChanged:(NSInteger)objectId size:(CGSize)size fps:(int32_t)fps;
27
+ - (void)videoInputError:(NSInteger)objectId code:(int32_t)code message:(NSString*)message;
28
+
29
+ @end
@@ -0,0 +1,125 @@
1
+ #import "TiRtcReactNativeEventSink.h"
2
+
3
+ #import "TiRtcReactNativeErrors.h"
4
+ #import "TiRtcReactNativeMaps.h"
5
+ #import "TiRtcReactNativeRegistry.h"
6
+
7
+ @implementation TiRtcReactNativeEventSink {
8
+ TiRtcReactNativeRegistry* _registry;
9
+ TiRtcReactNativeEmitBlock _emitBlock;
10
+ }
11
+
12
+ - (instancetype)initWithRegistry:(TiRtcReactNativeRegistry*)registry
13
+ emitBlock:(TiRtcReactNativeEmitBlock)emitBlock {
14
+ if (self = [super init]) {
15
+ _registry = registry;
16
+ _emitBlock = [emitBlock copy];
17
+ }
18
+ return self;
19
+ }
20
+
21
+ - (void)connStateChanged:(NSInteger)objectId state:(NSString*)state errorCode:(int32_t)errorCode {
22
+ NSMutableDictionary* event = [self base:@"connStateChanged" objectId:objectId];
23
+ event[@"state"] = state;
24
+ event[@"errorCode"] = @(TiRtcReactNativeNormalizeDarwin(errorCode));
25
+ [self emit:event];
26
+ }
27
+
28
+ - (void)connCommand:(NSInteger)objectId commandId:(uint32_t)commandId data:(NSData*)data {
29
+ NSMutableDictionary* event = [self base:@"connCommand" objectId:objectId];
30
+ event[@"commandId"] = @(commandId);
31
+ event[@"data"] = TiRtcReactNativeByteArray(data);
32
+ [self emit:event];
33
+ }
34
+
35
+ - (void)connStreamMessage:(NSInteger)objectId
36
+ streamId:(uint8_t)streamId
37
+ timestampMs:(uint32_t)timestampMs
38
+ data:(NSData*)data {
39
+ NSMutableDictionary* event = [self base:@"connStreamMessage" objectId:objectId];
40
+ event[@"streamId"] = @(streamId);
41
+ event[@"timestampMs"] = @(timestampMs);
42
+ event[@"data"] = TiRtcReactNativeByteArray(data);
43
+ [self emit:event];
44
+ }
45
+
46
+ - (void)audioOutputStateChanged:(NSInteger)objectId state:(NSString*)state {
47
+ NSMutableDictionary* event = [self base:@"audioOutputStateChanged" objectId:objectId];
48
+ event[@"state"] = state;
49
+ [self emit:event];
50
+ }
51
+
52
+ - (void)audioOutputError:(NSInteger)objectId code:(int32_t)code message:(NSString*)message {
53
+ NSMutableDictionary* event = [self base:@"audioOutputError" objectId:objectId];
54
+ event[@"code"] = @(TiRtcReactNativeNormalizeDarwin(code));
55
+ event[@"message"] = message ?: (id)kCFNull;
56
+ [self emit:event];
57
+ }
58
+
59
+ - (void)videoOutputStateChanged:(NSInteger)objectId state:(NSString*)state {
60
+ NSMutableDictionary* event = [self base:@"videoOutputStateChanged" objectId:objectId];
61
+ event[@"state"] = state;
62
+ [self emit:event];
63
+ }
64
+
65
+ - (void)videoOutputRenderSizeChanged:(NSInteger)objectId size:(CGSize)size {
66
+ NSMutableDictionary* event = [self base:@"videoOutputRenderSizeChanged" objectId:objectId];
67
+ event[@"size"] = @{@"width" : @((NSInteger)size.width), @"height" : @((NSInteger)size.height)};
68
+ [self emit:event];
69
+ }
70
+
71
+ - (void)videoOutputError:(NSInteger)objectId code:(int32_t)code message:(NSString*)message {
72
+ NSMutableDictionary* event = [self base:@"videoOutputError" objectId:objectId];
73
+ event[@"code"] = @(TiRtcReactNativeNormalizeDarwin(code));
74
+ event[@"message"] = message ?: (id)kCFNull;
75
+ [self emit:event];
76
+ }
77
+
78
+ - (void)audioInputStateChanged:(NSInteger)objectId state:(NSString*)state {
79
+ NSMutableDictionary* event = [self base:@"audioInputStateChanged" objectId:objectId];
80
+ event[@"state"] = state;
81
+ [self emit:event];
82
+ }
83
+
84
+ - (void)audioInputError:(NSInteger)objectId code:(int32_t)code message:(NSString*)message {
85
+ NSMutableDictionary* event = [self base:@"audioInputError" objectId:objectId];
86
+ event[@"code"] = @(TiRtcReactNativeNormalizeDarwin(code));
87
+ event[@"message"] = message ?: (id)kCFNull;
88
+ [self emit:event];
89
+ }
90
+
91
+ - (void)videoInputStateChanged:(NSInteger)objectId state:(NSString*)state {
92
+ NSMutableDictionary* event = [self base:@"videoInputStateChanged" objectId:objectId];
93
+ event[@"state"] = state;
94
+ [self emit:event];
95
+ }
96
+
97
+ - (void)videoInputActualConfigChanged:(NSInteger)objectId size:(CGSize)size fps:(int32_t)fps {
98
+ NSMutableDictionary* event = [self base:@"videoInputActualConfigChanged" objectId:objectId];
99
+ event[@"size"] = @{@"width" : @((NSInteger)size.width), @"height" : @((NSInteger)size.height)};
100
+ event[@"fps"] = @(fps);
101
+ [self emit:event];
102
+ }
103
+
104
+ - (void)videoInputError:(NSInteger)objectId code:(int32_t)code message:(NSString*)message {
105
+ NSMutableDictionary* event = [self base:@"videoInputError" objectId:objectId];
106
+ event[@"code"] = @(TiRtcReactNativeNormalizeDarwin(code));
107
+ event[@"message"] = message ?: (id)kCFNull;
108
+ [self emit:event];
109
+ }
110
+
111
+ - (NSMutableDictionary*)base:(NSString*)type objectId:(NSInteger)objectId {
112
+ return [@{
113
+ @"type" : type,
114
+ @"objectId" : @(objectId),
115
+ @"generation" : @([_registry generationForObjectId:objectId]),
116
+ } mutableCopy];
117
+ }
118
+
119
+ - (void)emit:(NSDictionary*)event {
120
+ if (_emitBlock != nil) {
121
+ _emitBlock(event);
122
+ }
123
+ }
124
+
125
+ @end
@@ -0,0 +1,21 @@
1
+ #import <CoreGraphics/CoreGraphics.h>
2
+ #import <Foundation/Foundation.h>
3
+
4
+ @class TiRtcAudioOutputDebugSnapshotResult;
5
+ @class TiRtcAudioOutputMetricsResult;
6
+ @class TiRtcConnMetricsResult;
7
+ @class TiRtcVideoOutputDebugSnapshotResult;
8
+ @class TiRtcVideoOutputMetricsResult;
9
+
10
+ NSDictionary* TiRtcReactNativeCreateResult(NSInteger code, NSInteger objectId, NSInteger generation,
11
+ NSString* message);
12
+ NSDictionary* TiRtcReactNativeStateResult(NSInteger code, NSString* state);
13
+ NSDictionary* TiRtcReactNativeSizeResult(NSInteger code, CGSize size, BOOL hasSize);
14
+ NSDictionary* TiRtcReactNativeConnMetricsResult(TiRtcConnMetricsResult* result);
15
+ NSDictionary* TiRtcReactNativeAudioMetricsResult(TiRtcAudioOutputMetricsResult* result);
16
+ NSDictionary* TiRtcReactNativeVideoMetricsResult(TiRtcVideoOutputMetricsResult* result);
17
+ NSDictionary* TiRtcReactNativeAudioDebugResult(TiRtcAudioOutputDebugSnapshotResult* result);
18
+ NSDictionary* TiRtcReactNativeVideoDebugResult(TiRtcVideoOutputDebugSnapshotResult* result);
19
+ NSDictionary* TiRtcReactNativeReleasedSnapshotResult(void);
20
+ NSArray<NSNumber*>* TiRtcReactNativeByteArray(NSData* data);
21
+ NSData* TiRtcReactNativeDataFromArray(NSArray* array);
@@ -0,0 +1,249 @@
1
+ #import "TiRtcReactNativeMaps.h"
2
+
3
+ #import "TiRtcReactNativeErrors.h"
4
+ #import "TiRtcReactNativeNative.h"
5
+
6
+ static NSDictionary* TiRtcReactNativeSizeMap(CGSize size) {
7
+ return @{
8
+ @"width" : @((NSInteger)size.width),
9
+ @"height" : @((NSInteger)size.height),
10
+ };
11
+ }
12
+
13
+ static NSDictionary* TiRtcReactNativeSnapshotResult(NSInteger code, NSDictionary* snapshot) {
14
+ return @{
15
+ @"code" : @(TiRtcReactNativeNormalizeDarwin((int32_t)code)),
16
+ @"snapshot" : snapshot ?: (id)kCFNull,
17
+ };
18
+ }
19
+
20
+ static id TiRtcReactNativeAudioCodec(NSInteger codec) {
21
+ switch (codec) {
22
+ case 1:
23
+ return @"g711a";
24
+ case 2:
25
+ return @"aac";
26
+ case 3:
27
+ return @"pcm";
28
+ case 4:
29
+ return @"opus";
30
+ case 5:
31
+ return @"amr";
32
+ default:
33
+ return (id)kCFNull;
34
+ }
35
+ }
36
+
37
+ static id TiRtcReactNativeVideoCodec(NSInteger codec) {
38
+ switch (codec) {
39
+ case 65:
40
+ return @"h264";
41
+ case 66:
42
+ return @"h265";
43
+ case 67:
44
+ return @"mjpeg";
45
+ default:
46
+ return (id)kCFNull;
47
+ }
48
+ }
49
+
50
+ static NSString* TiRtcReactNativeDecoderBackend(NSInteger backend) {
51
+ switch (backend) {
52
+ case 1:
53
+ return @"software";
54
+ case 2:
55
+ return @"hardware";
56
+ default:
57
+ return @"unknown";
58
+ }
59
+ }
60
+
61
+ static NSString* TiRtcReactNativeDecoderPreference(NSInteger preference) {
62
+ switch (preference) {
63
+ case 1:
64
+ return @"software";
65
+ case 2:
66
+ return @"hardware";
67
+ default:
68
+ return @"auto";
69
+ }
70
+ }
71
+
72
+ static NSString* TiRtcReactNativeBitstreamFormat(NSInteger format) {
73
+ switch (format) {
74
+ case 1:
75
+ return @"h264AnnexB";
76
+ case 2:
77
+ return @"h265AnnexB";
78
+ case 3:
79
+ return @"mjpegJfif";
80
+ default:
81
+ return @"unknown";
82
+ }
83
+ }
84
+
85
+ static NSDictionary* TiRtcReactNativeStutter(TiRtcOutputStutterMetrics* metrics) {
86
+ return @{
87
+ @"stutterThresholdMs" : @(metrics.stutterThresholdMs),
88
+ @"outputDurationMs" : @(metrics.outputDurationMs),
89
+ @"stutterTotalMs" : @(metrics.stutterTotalMs),
90
+ @"stutterCount" : @(metrics.stutterCount),
91
+ @"stutterPeakMs" : @(metrics.stutterPeakMs),
92
+ @"stutterAverageMs" : @(metrics.stutterAverageMs),
93
+ @"stutterRatePercent" : @(metrics.stutterRate),
94
+ };
95
+ }
96
+
97
+ static NSDictionary* TiRtcReactNativeStartup(TiRtcOutputStartupMetrics* metrics) {
98
+ return @{
99
+ @"hasConnectStart" : @(metrics.hasConnectStart),
100
+ @"hasConnected" : @(metrics.hasConnected),
101
+ @"hasFirstPacket" : @(metrics.hasFirstPacket),
102
+ @"hasFirstOutput" : @(metrics.hasFirstOutput),
103
+ @"connectStartMonotonicMs" : @(metrics.connectStartMonotonicMs),
104
+ @"connectedMonotonicMs" : @(metrics.connectedMonotonicMs),
105
+ @"firstPacketMonotonicMs" : @(metrics.firstPacketMonotonicMs),
106
+ @"firstOutputMonotonicMs" : @(metrics.firstOutputMonotonicMs),
107
+ @"firstPacketAfterConnectedMs" : @(metrics.firstPacketAfterConnectedMs),
108
+ @"firstOutputAfterConnectedMs" : @(metrics.firstOutputAfterConnectedMs),
109
+ @"timeToFirstOutputMs" : @(metrics.timeToFirstOutputMs),
110
+ };
111
+ }
112
+
113
+ NSDictionary* TiRtcReactNativeCreateResult(NSInteger code, NSInteger objectId, NSInteger generation,
114
+ NSString* message) {
115
+ return @{
116
+ @"code" : @(TiRtcReactNativeNormalizeDarwin((int32_t)code)),
117
+ @"objectId" : @(objectId),
118
+ @"generation" : @(generation),
119
+ @"message" : message ?: (id)kCFNull,
120
+ };
121
+ }
122
+
123
+ NSDictionary* TiRtcReactNativeStateResult(NSInteger code, NSString* state) {
124
+ return @{
125
+ @"code" : @(TiRtcReactNativeNormalizeDarwin((int32_t)code)),
126
+ @"state" : state ?: (id)kCFNull,
127
+ };
128
+ }
129
+
130
+ NSDictionary* TiRtcReactNativeSizeResult(NSInteger code, CGSize size, BOOL hasSize) {
131
+ return @{
132
+ @"code" : @(TiRtcReactNativeNormalizeDarwin((int32_t)code)),
133
+ @"size" : hasSize ? TiRtcReactNativeSizeMap(size) : (id)kCFNull,
134
+ };
135
+ }
136
+
137
+ NSDictionary* TiRtcReactNativeConnMetricsResult(TiRtcConnMetricsResult* result) {
138
+ TiRtcConnMetricsSnapshot* snapshot = result.snapshot;
139
+ NSDictionary* snapshotMap = nil;
140
+ if (snapshot != nil) {
141
+ NSNumber* duration = snapshot.isReady
142
+ ? @(snapshot.connectedMonotonicMs - snapshot.connectStartMonotonicMs)
143
+ : (NSNumber*)nil;
144
+ snapshotMap = @{
145
+ @"hasConnectStart" : @(snapshot.hasConnectStart),
146
+ @"hasConnected" : @(snapshot.hasConnected),
147
+ @"connectStartMonotonicMs" : @(snapshot.connectStartMonotonicMs),
148
+ @"connectedMonotonicMs" : @(snapshot.connectedMonotonicMs),
149
+ @"isReady" : @(snapshot.isReady),
150
+ @"connectDurationMs" : duration ?: (id)kCFNull,
151
+ };
152
+ }
153
+ return TiRtcReactNativeSnapshotResult(result.code, snapshotMap);
154
+ }
155
+
156
+ NSDictionary* TiRtcReactNativeAudioMetricsResult(TiRtcAudioOutputMetricsResult* result) {
157
+ TiRtcAudioOutputMetricsSnapshot* snapshot = result.snapshot;
158
+ NSDictionary* snapshotMap = nil;
159
+ if (snapshot != nil) {
160
+ snapshotMap = @{
161
+ @"startup" : TiRtcReactNativeStartup(snapshot.startup),
162
+ @"stutter" : TiRtcReactNativeStutter(snapshot.stutter),
163
+ @"estimatedOutputLatencyMs" : @(snapshot.estimatedOutputLatencyMs),
164
+ @"audioCodec" : TiRtcReactNativeAudioCodec(snapshot.audioCodec),
165
+ @"audioSampleRateHz" : @(snapshot.audioSampleRateHz),
166
+ @"audioChannels" : @(snapshot.audioChannels),
167
+ @"audioInputBitrateKbps" : @(snapshot.audioInputBitrateKbps),
168
+ @"audioInputPacketRate" : @(snapshot.audioInputPacketRate),
169
+ @"audioRenderCallbackRate" : @(snapshot.audioRenderCallbackRate),
170
+ @"statsRefreshIntervalMs" : @(snapshot.statsRefreshIntervalMs),
171
+ @"statsUpdatedAtMonotonicMs" : @(snapshot.statsUpdatedAtMs),
172
+ };
173
+ }
174
+ return TiRtcReactNativeSnapshotResult(result.code, snapshotMap);
175
+ }
176
+
177
+ NSDictionary* TiRtcReactNativeVideoMetricsResult(TiRtcVideoOutputMetricsResult* result) {
178
+ TiRtcVideoOutputMetricsSnapshot* snapshot = result.snapshot;
179
+ NSDictionary* snapshotMap = nil;
180
+ if (snapshot != nil) {
181
+ snapshotMap = @{
182
+ @"startup" : TiRtcReactNativeStartup(snapshot.startup),
183
+ @"stutter" : TiRtcReactNativeStutter(snapshot.stutter),
184
+ @"estimatedOutputLatencyMs" : @(snapshot.estimatedOutputLatencyMs),
185
+ @"videoCodec" : TiRtcReactNativeVideoCodec(snapshot.videoCodec),
186
+ @"videoWidth" : @(snapshot.videoWidth),
187
+ @"videoHeight" : @(snapshot.videoHeight),
188
+ @"decoderBackend" : TiRtcReactNativeDecoderBackend(snapshot.decoderBackend),
189
+ @"videoInputBitrateKbps" : @(snapshot.videoInputBitrateKbps),
190
+ @"videoInputFps" : @(snapshot.videoInputFps),
191
+ @"videoDecodedFps" : @(snapshot.videoDecodedFps),
192
+ @"videoRenderFps" : @(snapshot.videoRenderFps),
193
+ @"statsRefreshIntervalMs" : @(snapshot.statsRefreshIntervalMs),
194
+ @"statsUpdatedAtMonotonicMs" : @(snapshot.statsUpdatedAtMs),
195
+ };
196
+ }
197
+ return TiRtcReactNativeSnapshotResult(result.code, snapshotMap);
198
+ }
199
+
200
+ NSDictionary* TiRtcReactNativeAudioDebugResult(TiRtcAudioOutputDebugSnapshotResult* result) {
201
+ TiRtcAudioOutputDebugSnapshot* snapshot = result.snapshot;
202
+ NSDictionary* snapshotMap = nil;
203
+ if (snapshot != nil) {
204
+ snapshotMap = @{
205
+ @"codec" : TiRtcReactNativeAudioCodec(snapshot.codec),
206
+ @"sampleRateHz" : @(snapshot.sampleRate),
207
+ @"channels" : @(snapshot.channels),
208
+ };
209
+ }
210
+ return TiRtcReactNativeSnapshotResult(result.code, snapshotMap);
211
+ }
212
+
213
+ NSDictionary* TiRtcReactNativeVideoDebugResult(TiRtcVideoOutputDebugSnapshotResult* result) {
214
+ TiRtcVideoOutputDebugSnapshot* snapshot = result.snapshot;
215
+ NSDictionary* snapshotMap = nil;
216
+ if (snapshot != nil) {
217
+ snapshotMap = @{
218
+ @"codec" : TiRtcReactNativeVideoCodec(snapshot.codec),
219
+ @"bitstreamFormat" : TiRtcReactNativeBitstreamFormat(snapshot.bitstreamFormat),
220
+ @"width" : @(snapshot.width),
221
+ @"height" : @(snapshot.height),
222
+ @"decoderPreference" : TiRtcReactNativeDecoderPreference(snapshot.decoderPreference),
223
+ @"resolvedDecoderBackend" : TiRtcReactNativeDecoderBackend(snapshot.resolvedDecoderBackend),
224
+ };
225
+ }
226
+ return TiRtcReactNativeSnapshotResult(result.code, snapshotMap);
227
+ }
228
+
229
+ NSDictionary* TiRtcReactNativeReleasedSnapshotResult(void) {
230
+ return TiRtcReactNativeSnapshotResult(TiRtcReactNativeErrorObjectReleased, nil);
231
+ }
232
+
233
+ NSArray<NSNumber*>* TiRtcReactNativeByteArray(NSData* data) {
234
+ NSMutableArray<NSNumber*>* bytes = [NSMutableArray arrayWithCapacity:data.length];
235
+ const uint8_t* buffer = (const uint8_t*)data.bytes;
236
+ for (NSUInteger index = 0; index < data.length; index++) {
237
+ [bytes addObject:@(buffer[index])];
238
+ }
239
+ return bytes;
240
+ }
241
+
242
+ NSData* TiRtcReactNativeDataFromArray(NSArray* array) {
243
+ NSMutableData* data = [NSMutableData dataWithCapacity:array.count];
244
+ for (id value in array) {
245
+ uint8_t byte = (uint8_t)[value integerValue];
246
+ [data appendBytes:&byte length:1];
247
+ }
248
+ return data;
249
+ }
@@ -0,0 +1,8 @@
1
+ #import <Foundation/Foundation.h>
2
+ #import <UIKit/UIKit.h>
3
+
4
+ #if __has_include(<TiRTC/TiRTC-Swift.h>)
5
+ #import <TiRTC/TiRTC-Swift.h>
6
+ #else
7
+ #import "TiRTC-Swift.h"
8
+ #endif
@@ -0,0 +1,11 @@
1
+ #import "TiRtcSpec.h"
2
+ #import "TiRtcReactNativeNative.h"
3
+
4
+ TiRtcAudioOutputOptions* TiRtcReactNativeAudioOutputOptions(
5
+ JS::NativeTiRtc::NativeAudioOutputOptions& options);
6
+ TiRtcVideoOutputOptions* TiRtcReactNativeVideoOutputOptions(
7
+ JS::NativeTiRtc::NativeVideoOutputOptions& options);
8
+ TiRtcAudioInputOptions* TiRtcReactNativeAudioInputOptions(
9
+ JS::NativeTiRtc::NativeAudioInputOptions& options);
10
+ TiRtcVideoInputOptions* TiRtcReactNativeVideoInputOptions(
11
+ JS::NativeTiRtc::NativeVideoInputOptions& options);