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.
- package/LICENSE +11 -0
- package/README.md +140 -0
- package/TiRtcReactNative.podspec +35 -0
- package/android/build.gradle +37 -0
- package/android/src/main/AndroidManifest.xml +1 -0
- package/android/src/main/java/com/tange/ai/tirtc/reactnative/TiRtcModule.kt +482 -0
- package/android/src/main/java/com/tange/ai/tirtc/reactnative/TiRtcPackage.kt +43 -0
- package/android/src/main/java/com/tange/ai/tirtc/reactnative/TiRtcReactNativeErrors.kt +32 -0
- package/android/src/main/java/com/tange/ai/tirtc/reactnative/TiRtcReactNativeEventBinder.kt +99 -0
- package/android/src/main/java/com/tange/ai/tirtc/reactnative/TiRtcReactNativeEventSink.kt +168 -0
- package/android/src/main/java/com/tange/ai/tirtc/reactnative/TiRtcReactNativeMaps.kt +49 -0
- package/android/src/main/java/com/tange/ai/tirtc/reactnative/TiRtcReactNativeMetricsMaps.kt +173 -0
- package/android/src/main/java/com/tange/ai/tirtc/reactnative/TiRtcReactNativeModuleSupport.kt +91 -0
- package/android/src/main/java/com/tange/ai/tirtc/reactnative/TiRtcReactNativeOptions.kt +127 -0
- package/android/src/main/java/com/tange/ai/tirtc/reactnative/TiRtcReactNativeRegistry.kt +71 -0
- package/android/src/main/java/com/tange/ai/tirtc/reactnative/TiRtcVideoInputPreviewManager.kt +109 -0
- package/android/src/main/java/com/tange/ai/tirtc/reactnative/TiRtcVideoOutputViewManager.kt +109 -0
- package/ios/TiRtcReactNative+Conn.mm +112 -0
- package/ios/TiRtcReactNative+Input.mm +196 -0
- package/ios/TiRtcReactNative+Output.mm +172 -0
- package/ios/TiRtcReactNative+Private.h +28 -0
- package/ios/TiRtcReactNative.h +6 -0
- package/ios/TiRtcReactNative.mm +189 -0
- package/ios/TiRtcReactNativeErrors.h +18 -0
- package/ios/TiRtcReactNativeErrors.mm +105 -0
- package/ios/TiRtcReactNativeEventBinder.h +19 -0
- package/ios/TiRtcReactNativeEventBinder.mm +226 -0
- package/ios/TiRtcReactNativeEventSink.h +29 -0
- package/ios/TiRtcReactNativeEventSink.mm +125 -0
- package/ios/TiRtcReactNativeMaps.h +21 -0
- package/ios/TiRtcReactNativeMaps.mm +249 -0
- package/ios/TiRtcReactNativeNative.h +8 -0
- package/ios/TiRtcReactNativeOptions.h +11 -0
- package/ios/TiRtcReactNativeOptions.mm +123 -0
- package/ios/TiRtcReactNativeRegistry.h +20 -0
- package/ios/TiRtcReactNativeRegistry.mm +119 -0
- package/ios/TiRtcVideoInputPreview.h +5 -0
- package/ios/TiRtcVideoInputPreview.mm +149 -0
- package/ios/TiRtcVideoOutputView.h +5 -0
- package/ios/TiRtcVideoOutputView.mm +149 -0
- package/lib/module/audio_input.js +177 -0
- package/lib/module/audio_input.js.map +1 -0
- package/lib/module/audio_output.js +168 -0
- package/lib/module/audio_output.js.map +1 -0
- package/lib/module/conn.js +174 -0
- package/lib/module/conn.js.map +1 -0
- package/lib/module/errors.js +63 -0
- package/lib/module/errors.js.map +1 -0
- package/lib/module/events.js +37 -0
- package/lib/module/events.js.map +1 -0
- package/lib/module/index.js +9 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/logging.js +26 -0
- package/lib/module/logging.js.map +1 -0
- package/lib/module/native.js +5 -0
- package/lib/module/native.js.map +1 -0
- package/lib/module/native_object_id.js +47 -0
- package/lib/module/native_object_id.js.map +1 -0
- package/lib/module/runtime.js +27 -0
- package/lib/module/runtime.js.map +1 -0
- package/lib/module/specs/NativeTiRtc.js +3 -0
- package/lib/module/specs/NativeTiRtc.js.map +1 -0
- package/lib/module/specs/TiRtcVideoInputPreviewNativeComponent.js +24 -0
- package/lib/module/specs/TiRtcVideoOutputViewNativeComponent.js +24 -0
- package/lib/module/types.js +93 -0
- package/lib/module/types.js.map +1 -0
- package/lib/module/video_input.js +266 -0
- package/lib/module/video_input.js.map +1 -0
- package/lib/module/video_output.js +224 -0
- package/lib/module/video_output.js.map +1 -0
- package/lib/typescript/audio_input.d.ts +25 -0
- package/lib/typescript/audio_output.d.ts +25 -0
- package/lib/typescript/conn.d.ts +28 -0
- package/lib/typescript/errors.d.ts +19 -0
- package/lib/typescript/events.d.ts +6 -0
- package/lib/typescript/index.d.ts +9 -0
- package/lib/typescript/logging.d.ts +9 -0
- package/lib/typescript/native.d.ts +5 -0
- package/lib/typescript/native_object_id.d.ts +12 -0
- package/lib/typescript/runtime.d.ts +8 -0
- package/lib/typescript/specs/NativeTiRtc.d.ts +223 -0
- package/lib/typescript/specs/TiRtcVideoInputPreviewNativeComponent.d.ts +8 -0
- package/lib/typescript/specs/TiRtcVideoOutputViewNativeComponent.d.ts +8 -0
- package/lib/typescript/types.d.ts +281 -0
- package/lib/typescript/video_input.d.ts +50 -0
- package/lib/typescript/video_output.d.ts +46 -0
- package/package.json +80 -0
- package/react-native.config.js +10 -0
- package/src/audio_input.ts +205 -0
- package/src/audio_output.ts +202 -0
- package/src/conn.ts +222 -0
- package/src/errors.ts +81 -0
- package/src/events.ts +44 -0
- package/src/index.ts +61 -0
- package/src/logging.ts +33 -0
- package/src/native.ts +6 -0
- package/src/native_object_id.ts +63 -0
- package/src/runtime.ts +32 -0
- package/src/specs/NativeTiRtc.ts +256 -0
- package/src/specs/TiRtcVideoInputPreviewNativeComponent.ts +14 -0
- package/src/specs/TiRtcVideoOutputViewNativeComponent.ts +12 -0
- package/src/types.ts +340 -0
- package/src/video_input.ts +314 -0
- 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
|