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,109 @@
1
+ package com.tange.ai.tirtc.reactnative
2
+
3
+ import android.widget.FrameLayout
4
+ import com.facebook.react.uimanager.SimpleViewManager
5
+ import com.facebook.react.uimanager.ThemedReactContext
6
+ import com.facebook.react.uimanager.ViewManagerDelegate
7
+ import com.facebook.react.uimanager.annotations.ReactProp
8
+ import com.facebook.react.viewmanagers.TiRtcVideoInputPreviewManagerDelegate
9
+ import com.facebook.react.viewmanagers.TiRtcVideoInputPreviewManagerInterface
10
+ import com.tange.ai.tirtc.TiRtcVideoViewResizeMode
11
+
12
+ class TiRtcVideoInputPreviewManager :
13
+ SimpleViewManager<FrameLayout>(),
14
+ TiRtcVideoInputPreviewManagerInterface<FrameLayout> {
15
+ private val delegate: ViewManagerDelegate<FrameLayout> = TiRtcVideoInputPreviewManagerDelegate(this)
16
+
17
+ override fun getName(): String = "TiRtcVideoInputPreview"
18
+
19
+ public override fun getDelegate(): ViewManagerDelegate<FrameLayout> = delegate
20
+
21
+ override fun createViewInstance(reactContext: ThemedReactContext): FrameLayout = FrameLayout(reactContext)
22
+
23
+ override fun onDropViewInstance(view: FrameLayout) {
24
+ (view.getTag(ATTACHED_ID_TAG) as? Int)?.let { id ->
25
+ TiRtcReactNativeRegistry.videoInput(id)?.detachPreview()
26
+ }
27
+ super.onDropViewInstance(view)
28
+ }
29
+
30
+ @ReactProp(name = "nativeObjectId")
31
+ override fun setNativeObjectId(
32
+ view: FrameLayout,
33
+ nativeObjectId: Int,
34
+ ) {
35
+ view.setTag(NATIVE_ID_TAG, nativeObjectId)
36
+ updateAttachedPreview(view)
37
+ }
38
+
39
+ @ReactProp(name = "generation")
40
+ override fun setGeneration(
41
+ view: FrameLayout,
42
+ generation: Int,
43
+ ) {
44
+ view.setTag(GENERATION_TAG, generation)
45
+ updateAttachedPreview(view)
46
+ }
47
+
48
+ @ReactProp(name = "resizeMode")
49
+ override fun setResizeMode(
50
+ view: FrameLayout,
51
+ resizeMode: String?,
52
+ ) {
53
+ val mode = resizeModeFromProp(resizeMode)
54
+ view.setTag(RESIZE_MODE_TAG, mode)
55
+ (view.getTag(ATTACHED_ID_TAG) as? Int)?.let { id ->
56
+ TiRtcReactNativeRegistry.videoInput(id)?.previewResizeMode = mode
57
+ }
58
+ }
59
+
60
+ private fun updateAttachedPreview(view: FrameLayout) {
61
+ val nativeObjectId = view.getTag(NATIVE_ID_TAG) as? Int
62
+ val generation = view.getTag(GENERATION_TAG) as? Int
63
+ val attachedId = view.getTag(ATTACHED_ID_TAG) as? Int
64
+ val attachedGeneration = view.getTag(ATTACHED_GENERATION_TAG) as? Int
65
+ if (attachedId != null && (attachedId != nativeObjectId || attachedGeneration != generation)) {
66
+ TiRtcReactNativeRegistry.videoInput(attachedId)?.detachPreview()
67
+ view.setTag(ATTACHED_ID_TAG, null)
68
+ view.setTag(ATTACHED_GENERATION_TAG, null)
69
+ }
70
+ if (
71
+ nativeObjectId == null ||
72
+ generation == null ||
73
+ nativeObjectId <= 0 ||
74
+ generation <= 0 ||
75
+ TiRtcReactNativeRegistry.generation(nativeObjectId) != generation ||
76
+ (attachedId == nativeObjectId && attachedGeneration == generation)
77
+ ) {
78
+ return
79
+ }
80
+ TiRtcReactNativeRegistry.videoInput(nativeObjectId)?.let { input ->
81
+ input.previewResizeMode = resizeModeForView(view)
82
+ val code = input.attachPreview(view)
83
+ if (TiRtcReactNativeErrors.normalizeAndroid(code) != TiRtcReactNativeErrors.OK) {
84
+ TiRtcReactNativeRegistry.reportVideoInputError(nativeObjectId, code, "preview attach failed")
85
+ return
86
+ }
87
+ view.setTag(ATTACHED_ID_TAG, nativeObjectId)
88
+ view.setTag(ATTACHED_GENERATION_TAG, generation)
89
+ }
90
+ }
91
+
92
+ private fun resizeModeForView(view: FrameLayout): TiRtcVideoViewResizeMode =
93
+ view.getTag(RESIZE_MODE_TAG) as? TiRtcVideoViewResizeMode ?: TiRtcVideoViewResizeMode.CONTAIN
94
+
95
+ private fun resizeModeFromProp(resizeMode: String?): TiRtcVideoViewResizeMode =
96
+ when (resizeMode) {
97
+ "cover" -> TiRtcVideoViewResizeMode.COVER
98
+ "stretch" -> TiRtcVideoViewResizeMode.STRETCH
99
+ else -> TiRtcVideoViewResizeMode.CONTAIN
100
+ }
101
+
102
+ private companion object {
103
+ const val NATIVE_ID_TAG = 0x54495250
104
+ const val RESIZE_MODE_TAG = 0x54495251
105
+ const val GENERATION_TAG = 0x54495252
106
+ const val ATTACHED_ID_TAG = 0x54495253
107
+ const val ATTACHED_GENERATION_TAG = 0x54495254
108
+ }
109
+ }
@@ -0,0 +1,109 @@
1
+ package com.tange.ai.tirtc.reactnative
2
+
3
+ import android.widget.FrameLayout
4
+ import com.facebook.react.uimanager.SimpleViewManager
5
+ import com.facebook.react.uimanager.ThemedReactContext
6
+ import com.facebook.react.uimanager.ViewManagerDelegate
7
+ import com.facebook.react.uimanager.annotations.ReactProp
8
+ import com.facebook.react.viewmanagers.TiRtcVideoOutputViewManagerDelegate
9
+ import com.facebook.react.viewmanagers.TiRtcVideoOutputViewManagerInterface
10
+ import com.tange.ai.tirtc.TiRtcVideoViewResizeMode
11
+
12
+ class TiRtcVideoOutputViewManager :
13
+ SimpleViewManager<FrameLayout>(),
14
+ TiRtcVideoOutputViewManagerInterface<FrameLayout> {
15
+ private val delegate: ViewManagerDelegate<FrameLayout> = TiRtcVideoOutputViewManagerDelegate(this)
16
+
17
+ override fun getName(): String = "TiRtcVideoOutputView"
18
+
19
+ public override fun getDelegate(): ViewManagerDelegate<FrameLayout> = delegate
20
+
21
+ override fun createViewInstance(reactContext: ThemedReactContext): FrameLayout = FrameLayout(reactContext)
22
+
23
+ override fun onDropViewInstance(view: FrameLayout) {
24
+ (view.getTag(ATTACHED_ID_TAG) as? Int)?.let { id ->
25
+ TiRtcReactNativeRegistry.videoOutput(id)?.detachView()
26
+ }
27
+ super.onDropViewInstance(view)
28
+ }
29
+
30
+ @ReactProp(name = "nativeObjectId")
31
+ override fun setNativeObjectId(
32
+ view: FrameLayout,
33
+ nativeObjectId: Int,
34
+ ) {
35
+ view.setTag(NATIVE_ID_TAG, nativeObjectId)
36
+ updateAttachedOutput(view)
37
+ }
38
+
39
+ @ReactProp(name = "generation")
40
+ override fun setGeneration(
41
+ view: FrameLayout,
42
+ generation: Int,
43
+ ) {
44
+ view.setTag(GENERATION_TAG, generation)
45
+ updateAttachedOutput(view)
46
+ }
47
+
48
+ @ReactProp(name = "resizeMode")
49
+ override fun setResizeMode(
50
+ view: FrameLayout,
51
+ resizeMode: String?,
52
+ ) {
53
+ val mode = resizeModeFromProp(resizeMode)
54
+ view.setTag(RESIZE_MODE_TAG, mode)
55
+ (view.getTag(ATTACHED_ID_TAG) as? Int)?.let { id ->
56
+ TiRtcReactNativeRegistry.videoOutput(id)?.viewResizeMode = mode
57
+ }
58
+ }
59
+
60
+ private fun updateAttachedOutput(view: FrameLayout) {
61
+ val nativeObjectId = view.getTag(NATIVE_ID_TAG) as? Int
62
+ val generation = view.getTag(GENERATION_TAG) as? Int
63
+ val attachedId = view.getTag(ATTACHED_ID_TAG) as? Int
64
+ val attachedGeneration = view.getTag(ATTACHED_GENERATION_TAG) as? Int
65
+ if (attachedId != null && (attachedId != nativeObjectId || attachedGeneration != generation)) {
66
+ TiRtcReactNativeRegistry.videoOutput(attachedId)?.detachView()
67
+ view.setTag(ATTACHED_ID_TAG, null)
68
+ view.setTag(ATTACHED_GENERATION_TAG, null)
69
+ }
70
+ if (
71
+ nativeObjectId == null ||
72
+ generation == null ||
73
+ nativeObjectId <= 0 ||
74
+ generation <= 0 ||
75
+ TiRtcReactNativeRegistry.generation(nativeObjectId) != generation ||
76
+ (attachedId == nativeObjectId && attachedGeneration == generation)
77
+ ) {
78
+ return
79
+ }
80
+ TiRtcReactNativeRegistry.videoOutput(nativeObjectId)?.let { output ->
81
+ output.viewResizeMode = resizeModeForView(view)
82
+ val code = output.attachView(view)
83
+ if (TiRtcReactNativeErrors.normalizeAndroid(code) != TiRtcReactNativeErrors.OK) {
84
+ TiRtcReactNativeRegistry.reportVideoOutputError(nativeObjectId, code)
85
+ return
86
+ }
87
+ view.setTag(ATTACHED_ID_TAG, nativeObjectId)
88
+ view.setTag(ATTACHED_GENERATION_TAG, generation)
89
+ }
90
+ }
91
+
92
+ private fun resizeModeForView(view: FrameLayout): TiRtcVideoViewResizeMode =
93
+ view.getTag(RESIZE_MODE_TAG) as? TiRtcVideoViewResizeMode ?: TiRtcVideoViewResizeMode.CONTAIN
94
+
95
+ private fun resizeModeFromProp(resizeMode: String?): TiRtcVideoViewResizeMode =
96
+ when (resizeMode) {
97
+ "cover" -> TiRtcVideoViewResizeMode.COVER
98
+ "stretch" -> TiRtcVideoViewResizeMode.STRETCH
99
+ else -> TiRtcVideoViewResizeMode.CONTAIN
100
+ }
101
+
102
+ private companion object {
103
+ const val NATIVE_ID_TAG = 0x54495254
104
+ const val RESIZE_MODE_TAG = 0x54495255
105
+ const val GENERATION_TAG = 0x54495256
106
+ const val ATTACHED_ID_TAG = 0x54495257
107
+ const val ATTACHED_GENERATION_TAG = 0x54495258
108
+ }
109
+ }
@@ -0,0 +1,112 @@
1
+ #import "TiRtcReactNative+Private.h"
2
+ #import "TiRtcReactNativeErrors.h"
3
+ #import "TiRtcReactNativeMaps.h"
4
+
5
+ #pragma clang diagnostic push
6
+ #pragma clang diagnostic ignored "-Wobjc-protocol-method-implementation"
7
+ @implementation TiRtcReactNative (Conn)
8
+
9
+ - (NSDictionary*)createConn {
10
+ return [self
11
+ registerObject:^id {
12
+ return [[TiRtcConn alloc] initWithDelegate:nil];
13
+ }
14
+ wire:^id(NSInteger objectId, id object) {
15
+ return [[self eventBinder] wireConn:(TiRtcConn*)object objectId:objectId];
16
+ }];
17
+ }
18
+
19
+ - (NSDictionary*)connGetState:(double)objectId {
20
+ TiRtcConn* conn = [self conn:objectId];
21
+ if (conn == nil) {
22
+ return TiRtcReactNativeStateResult(TiRtcReactNativeErrorObjectReleased, nil);
23
+ }
24
+ return TiRtcReactNativeStateResult(TiRtcReactNativeErrorOK,
25
+ TiRtcReactNativeConnStateString(conn.state));
26
+ }
27
+
28
+ - (NSNumber*)connConnect:(double)objectId remoteId:(NSString*)remoteId token:(NSString*)token {
29
+ return [self connCode:[self conn:objectId]
30
+ block:^int32_t(TiRtcConn* conn) {
31
+ return [conn connectWithRemoteId:remoteId token:token];
32
+ }];
33
+ }
34
+
35
+ - (NSNumber*)connDisconnect:(double)objectId {
36
+ return [self connCode:[self conn:objectId]
37
+ block:^int32_t(TiRtcConn* conn) {
38
+ return [conn disconnect];
39
+ }];
40
+ }
41
+
42
+ - (NSNumber*)connSendCommand:(double)objectId commandId:(double)commandId data:(NSArray*)data {
43
+ NSData* payload = TiRtcReactNativeDataFromArray(data);
44
+ return [self connCode:[self conn:objectId]
45
+ block:^int32_t(TiRtcConn* conn) {
46
+ return [conn sendCommandWithCommandId:TiRtcReactNativeUInt32(commandId)
47
+ data:payload];
48
+ }];
49
+ }
50
+
51
+ - (NSNumber*)connSendStreamMessage:(double)objectId
52
+ streamId:(double)streamId
53
+ timestampMs:(double)timestampMs
54
+ data:(NSArray*)data {
55
+ NSData* payload = TiRtcReactNativeDataFromArray(data);
56
+ return [self connCode:[self conn:objectId]
57
+ block:^int32_t(TiRtcConn* conn) {
58
+ return [conn sendStreamMessageWithStreamId:TiRtcReactNativeStreamId(streamId)
59
+ timestampMs:TiRtcReactNativeUInt32(timestampMs)
60
+ data:payload];
61
+ }];
62
+ }
63
+
64
+ - (NSNumber*)connSubscribeVideo:(double)objectId streamId:(double)streamId {
65
+ return [self connCode:[self conn:objectId]
66
+ block:^int32_t(TiRtcConn* conn) {
67
+ return [conn subscribeVideoWithStreamId:TiRtcReactNativeStreamId(streamId)];
68
+ }];
69
+ }
70
+
71
+ - (NSNumber*)connUnsubscribeVideo:(double)objectId streamId:(double)streamId {
72
+ return [self connCode:[self conn:objectId]
73
+ block:^int32_t(TiRtcConn* conn) {
74
+ return [conn unsubscribeVideoWithStreamId:TiRtcReactNativeStreamId(streamId)];
75
+ }];
76
+ }
77
+
78
+ - (NSNumber*)connSubscribeAudio:(double)objectId streamId:(double)streamId {
79
+ return [self connCode:[self conn:objectId]
80
+ block:^int32_t(TiRtcConn* conn) {
81
+ return [conn subscribeAudioWithStreamId:TiRtcReactNativeStreamId(streamId)];
82
+ }];
83
+ }
84
+
85
+ - (NSNumber*)connUnsubscribeAudio:(double)objectId streamId:(double)streamId {
86
+ return [self connCode:[self conn:objectId]
87
+ block:^int32_t(TiRtcConn* conn) {
88
+ return [conn unsubscribeAudioWithStreamId:TiRtcReactNativeStreamId(streamId)];
89
+ }];
90
+ }
91
+
92
+ - (NSNumber*)connRequestKeyFrame:(double)objectId streamId:(double)streamId {
93
+ return [self connCode:[self conn:objectId]
94
+ block:^int32_t(TiRtcConn* conn) {
95
+ return [conn requestKeyFrameWithStreamId:TiRtcReactNativeStreamId(streamId)];
96
+ }];
97
+ }
98
+
99
+ - (NSDictionary*)connGetMetricsSnapshot:(double)objectId {
100
+ TiRtcConn* conn = [self conn:objectId];
101
+ return conn == nil ? TiRtcReactNativeReleasedSnapshotResult()
102
+ : TiRtcReactNativeConnMetricsResult([conn getMetricsSnapshot]);
103
+ }
104
+
105
+ - (NSNumber*)connDispose:(double)objectId {
106
+ TiRtcConn* conn = [self conn:objectId];
107
+ [conn dispose];
108
+ return [self releaseRegisteredObject:(NSInteger)objectId object:conn];
109
+ }
110
+
111
+ @end
112
+ #pragma clang diagnostic pop
@@ -0,0 +1,196 @@
1
+ #import "TiRtcReactNative+Private.h"
2
+ #import "TiRtcReactNativeErrors.h"
3
+ #import "TiRtcReactNativeMaps.h"
4
+ #import "TiRtcReactNativeOptions.h"
5
+
6
+ #pragma clang diagnostic push
7
+ #pragma clang diagnostic ignored "-Wobjc-protocol-method-implementation"
8
+ @implementation TiRtcReactNative (Input)
9
+
10
+ - (NSDictionary*)createAudioInput {
11
+ return [self
12
+ registerObject:^id {
13
+ return [TiRtcAudioInput new];
14
+ }
15
+ wire:^id(NSInteger objectId, id object) {
16
+ return [[self eventBinder] wireAudioInput:(TiRtcAudioInput*)object objectId:objectId];
17
+ }];
18
+ }
19
+
20
+ - (NSDictionary*)audioInputGetState:(double)objectId {
21
+ TiRtcAudioInput* input = [self audioInput:objectId];
22
+ if (input == nil) {
23
+ return TiRtcReactNativeStateResult(TiRtcReactNativeErrorObjectReleased, nil);
24
+ }
25
+ return TiRtcReactNativeStateResult(TiRtcReactNativeErrorOK,
26
+ TiRtcReactNativeInputStateString(input.state));
27
+ }
28
+
29
+ - (void)audioInputSetOptions:(double)objectId
30
+ options:(JS::NativeTiRtc::NativeAudioInputOptions&)options
31
+ resolve:(RCTPromiseResolveBlock)resolve
32
+ reject:(RCTPromiseRejectBlock)reject {
33
+ TiRtcAudioInputOptions* nativeOptions = TiRtcReactNativeAudioInputOptions(options);
34
+ resolve([self audioInputCode:[self audioInput:objectId]
35
+ block:^int32_t(TiRtcAudioInput* input) {
36
+ return [input setOptions:nativeOptions];
37
+ }]);
38
+ }
39
+
40
+ - (void)audioInputAttach:(double)objectId
41
+ connId:(double)connId
42
+ streamId:(double)streamId
43
+ resolve:(RCTPromiseResolveBlock)resolve
44
+ reject:(RCTPromiseRejectBlock)reject {
45
+ TiRtcConn* conn = [self conn:connId];
46
+ if (conn == nil) {
47
+ resolve(@(TiRtcReactNativeErrorObjectReleased));
48
+ return;
49
+ }
50
+ resolve([self audioInputCode:[self audioInput:objectId]
51
+ block:^int32_t(TiRtcAudioInput* input) {
52
+ return [input attachWithConnection:conn
53
+ streamId:TiRtcReactNativeStreamId(streamId)];
54
+ }]);
55
+ }
56
+
57
+ - (void)audioInputStart:(double)objectId
58
+ resolve:(RCTPromiseResolveBlock)resolve
59
+ reject:(RCTPromiseRejectBlock)reject {
60
+ resolve([self audioInputCode:[self audioInput:objectId]
61
+ block:^int32_t(TiRtcAudioInput* input) {
62
+ return [input start];
63
+ }]);
64
+ }
65
+
66
+ - (void)audioInputStop:(double)objectId
67
+ resolve:(RCTPromiseResolveBlock)resolve
68
+ reject:(RCTPromiseRejectBlock)reject {
69
+ resolve([self audioInputCode:[self audioInput:objectId]
70
+ block:^int32_t(TiRtcAudioInput* input) {
71
+ return [input stop];
72
+ }]);
73
+ }
74
+
75
+ - (void)audioInputDetach:(double)objectId
76
+ connId:(double)connId
77
+ resolve:(RCTPromiseResolveBlock)resolve
78
+ reject:(RCTPromiseRejectBlock)reject {
79
+ TiRtcConn* conn = [self conn:connId];
80
+ if (conn == nil) {
81
+ resolve(@(TiRtcReactNativeErrorObjectReleased));
82
+ return;
83
+ }
84
+ resolve([self audioInputCode:[self audioInput:objectId]
85
+ block:^int32_t(TiRtcAudioInput* input) {
86
+ return [input detachWithConnection:conn];
87
+ }]);
88
+ }
89
+
90
+ - (void)audioInputDispose:(double)objectId
91
+ resolve:(RCTPromiseResolveBlock)resolve
92
+ reject:(RCTPromiseRejectBlock)reject {
93
+ TiRtcAudioInput* input = [self audioInput:objectId];
94
+ [input dispose];
95
+ resolve([self releaseRegisteredObject:(NSInteger)objectId object:input]);
96
+ }
97
+
98
+ - (NSDictionary*)createVideoInput {
99
+ return [self
100
+ registerObject:^id {
101
+ return [TiRtcVideoInput new];
102
+ }
103
+ wire:^id(NSInteger objectId, id object) {
104
+ return [[self eventBinder] wireVideoInput:(TiRtcVideoInput*)object objectId:objectId];
105
+ }];
106
+ }
107
+
108
+ - (NSDictionary*)videoInputGetState:(double)objectId {
109
+ TiRtcVideoInput* input = [self videoInput:objectId];
110
+ if (input == nil) {
111
+ return TiRtcReactNativeStateResult(TiRtcReactNativeErrorObjectReleased, nil);
112
+ }
113
+ return TiRtcReactNativeStateResult(TiRtcReactNativeErrorOK,
114
+ TiRtcReactNativeInputStateString(input.state));
115
+ }
116
+
117
+ - (NSDictionary*)videoInputGetActualConfig:(double)objectId {
118
+ TiRtcVideoInput* input = [self videoInput:objectId];
119
+ NSMutableDictionary* result = [TiRtcReactNativeSizeResult(
120
+ input == nil ? TiRtcReactNativeErrorObjectReleased : TiRtcReactNativeErrorOK,
121
+ input == nil ? CGSizeZero : input.outputSize, input != nil) mutableCopy];
122
+ result[@"fps"] = input == nil ? (id)kCFNull : @(input.outputFps);
123
+ return result;
124
+ }
125
+
126
+ - (void)videoInputSetOptions:(double)objectId
127
+ options:(JS::NativeTiRtc::NativeVideoInputOptions&)options
128
+ resolve:(RCTPromiseResolveBlock)resolve
129
+ reject:(RCTPromiseRejectBlock)reject {
130
+ TiRtcVideoInputOptions* nativeOptions = TiRtcReactNativeVideoInputOptions(options);
131
+ resolve([self videoInputCode:[self videoInput:objectId]
132
+ block:^int32_t(TiRtcVideoInput* input) {
133
+ return [input setOptions:nativeOptions];
134
+ }]);
135
+ }
136
+
137
+ - (void)videoInputAttach:(double)objectId
138
+ connId:(double)connId
139
+ streamId:(double)streamId
140
+ resolve:(RCTPromiseResolveBlock)resolve
141
+ reject:(RCTPromiseRejectBlock)reject {
142
+ TiRtcConn* conn = [self conn:connId];
143
+ if (conn == nil) {
144
+ resolve(@(TiRtcReactNativeErrorObjectReleased));
145
+ return;
146
+ }
147
+ resolve([self videoInputCode:[self videoInput:objectId]
148
+ block:^int32_t(TiRtcVideoInput* input) {
149
+ return [input attachWithConnection:conn
150
+ streamId:TiRtcReactNativeStreamId(streamId)];
151
+ }]);
152
+ }
153
+
154
+ - (void)videoInputStart:(double)objectId
155
+ resolve:(RCTPromiseResolveBlock)resolve
156
+ reject:(RCTPromiseRejectBlock)reject {
157
+ resolve([self videoInputCode:[self videoInput:objectId]
158
+ block:^int32_t(TiRtcVideoInput* input) {
159
+ return [input start];
160
+ }]);
161
+ }
162
+
163
+ - (void)videoInputStop:(double)objectId
164
+ resolve:(RCTPromiseResolveBlock)resolve
165
+ reject:(RCTPromiseRejectBlock)reject {
166
+ resolve([self videoInputCode:[self videoInput:objectId]
167
+ block:^int32_t(TiRtcVideoInput* input) {
168
+ return [input stop];
169
+ }]);
170
+ }
171
+
172
+ - (void)videoInputDetach:(double)objectId
173
+ connId:(double)connId
174
+ resolve:(RCTPromiseResolveBlock)resolve
175
+ reject:(RCTPromiseRejectBlock)reject {
176
+ TiRtcConn* conn = [self conn:connId];
177
+ if (conn == nil) {
178
+ resolve(@(TiRtcReactNativeErrorObjectReleased));
179
+ return;
180
+ }
181
+ resolve([self videoInputCode:[self videoInput:objectId]
182
+ block:^int32_t(TiRtcVideoInput* input) {
183
+ return [input detachWithConnection:conn];
184
+ }]);
185
+ }
186
+
187
+ - (void)videoInputDispose:(double)objectId
188
+ resolve:(RCTPromiseResolveBlock)resolve
189
+ reject:(RCTPromiseRejectBlock)reject {
190
+ TiRtcVideoInput* input = [self videoInput:objectId];
191
+ [input dispose];
192
+ resolve([self releaseRegisteredObject:(NSInteger)objectId object:input]);
193
+ }
194
+
195
+ @end
196
+ #pragma clang diagnostic pop