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,281 @@
|
|
|
1
|
+
import type { ViewProps } from 'react-native';
|
|
2
|
+
import type { TiRtcVideoInput } from './video_input';
|
|
3
|
+
import type { TiRtcVideoOutput } from './video_output';
|
|
4
|
+
export type TiRtcSize = Readonly<{
|
|
5
|
+
width: number;
|
|
6
|
+
height: number;
|
|
7
|
+
}>;
|
|
8
|
+
export declare const TiRtcOutputBufferStrategy: {
|
|
9
|
+
readonly automatic: "automatic";
|
|
10
|
+
readonly noBuffer: "noBuffer";
|
|
11
|
+
};
|
|
12
|
+
export type TiRtcOutputBufferStrategy = (typeof TiRtcOutputBufferStrategy)[keyof typeof TiRtcOutputBufferStrategy];
|
|
13
|
+
export declare const TiRtcConnState: {
|
|
14
|
+
readonly idle: "idle";
|
|
15
|
+
readonly connecting: "connecting";
|
|
16
|
+
readonly connected: "connected";
|
|
17
|
+
readonly disconnected: "disconnected";
|
|
18
|
+
};
|
|
19
|
+
export type TiRtcConnState = (typeof TiRtcConnState)[keyof typeof TiRtcConnState];
|
|
20
|
+
export declare const TiRtcInputState: {
|
|
21
|
+
readonly idle: "idle";
|
|
22
|
+
readonly running: "running";
|
|
23
|
+
readonly stopped: "stopped";
|
|
24
|
+
readonly failed: "failed";
|
|
25
|
+
};
|
|
26
|
+
export type TiRtcInputState = (typeof TiRtcInputState)[keyof typeof TiRtcInputState];
|
|
27
|
+
export declare const TiRtcAudioCodec: {
|
|
28
|
+
readonly g711a: "g711a";
|
|
29
|
+
readonly aac: "aac";
|
|
30
|
+
readonly pcm: "pcm";
|
|
31
|
+
readonly opus: "opus";
|
|
32
|
+
readonly amr: "amr";
|
|
33
|
+
};
|
|
34
|
+
export type TiRtcAudioCodec = (typeof TiRtcAudioCodec)[keyof typeof TiRtcAudioCodec];
|
|
35
|
+
export declare const TiRtcAudioSampleRate: {
|
|
36
|
+
readonly rate8k: "rate8k";
|
|
37
|
+
readonly rate16k: "rate16k";
|
|
38
|
+
};
|
|
39
|
+
export type TiRtcAudioSampleRate = (typeof TiRtcAudioSampleRate)[keyof typeof TiRtcAudioSampleRate];
|
|
40
|
+
export declare const TiRtcAudioChannelCount: {
|
|
41
|
+
readonly mono: "mono";
|
|
42
|
+
};
|
|
43
|
+
export type TiRtcAudioChannelCount = (typeof TiRtcAudioChannelCount)[keyof typeof TiRtcAudioChannelCount];
|
|
44
|
+
export declare const TiRtcAudioAecMode: {
|
|
45
|
+
readonly disabled: "disabled";
|
|
46
|
+
readonly enabled: "enabled";
|
|
47
|
+
};
|
|
48
|
+
export type TiRtcAudioAecMode = (typeof TiRtcAudioAecMode)[keyof typeof TiRtcAudioAecMode];
|
|
49
|
+
export declare const TiRtcAudioAgcLevel: {
|
|
50
|
+
readonly disabled: "disabled";
|
|
51
|
+
readonly low: "low";
|
|
52
|
+
readonly medium: "medium";
|
|
53
|
+
readonly high: "high";
|
|
54
|
+
};
|
|
55
|
+
export type TiRtcAudioAgcLevel = (typeof TiRtcAudioAgcLevel)[keyof typeof TiRtcAudioAgcLevel];
|
|
56
|
+
export declare const TiRtcAudioAnsLevel: {
|
|
57
|
+
readonly disabled: "disabled";
|
|
58
|
+
readonly low: "low";
|
|
59
|
+
readonly medium: "medium";
|
|
60
|
+
readonly high: "high";
|
|
61
|
+
};
|
|
62
|
+
export type TiRtcAudioAnsLevel = (typeof TiRtcAudioAnsLevel)[keyof typeof TiRtcAudioAnsLevel];
|
|
63
|
+
export declare const TiRtcVideoCodec: {
|
|
64
|
+
readonly h264: "h264";
|
|
65
|
+
readonly h265: "h265";
|
|
66
|
+
readonly mjpeg: "mjpeg";
|
|
67
|
+
};
|
|
68
|
+
export type TiRtcVideoCodec = (typeof TiRtcVideoCodec)[keyof typeof TiRtcVideoCodec];
|
|
69
|
+
export declare const TiRtcVideoEncoderCodec: {
|
|
70
|
+
readonly h264: "h264";
|
|
71
|
+
readonly mjpeg: "mjpeg";
|
|
72
|
+
};
|
|
73
|
+
export type TiRtcVideoEncoderCodec = (typeof TiRtcVideoEncoderCodec)[keyof typeof TiRtcVideoEncoderCodec];
|
|
74
|
+
export declare const TiRtcVideoFrameRate: {
|
|
75
|
+
readonly fps10: "fps10";
|
|
76
|
+
readonly fps15: "fps15";
|
|
77
|
+
readonly fps30: "fps30";
|
|
78
|
+
};
|
|
79
|
+
export type TiRtcVideoFrameRate = (typeof TiRtcVideoFrameRate)[keyof typeof TiRtcVideoFrameRate];
|
|
80
|
+
export declare const TiRtcCameraFacing: {
|
|
81
|
+
readonly front: "front";
|
|
82
|
+
readonly back: "back";
|
|
83
|
+
};
|
|
84
|
+
export type TiRtcCameraFacing = (typeof TiRtcCameraFacing)[keyof typeof TiRtcCameraFacing];
|
|
85
|
+
export declare const TiRtcVideoDecoderPreference: {
|
|
86
|
+
readonly auto: "auto";
|
|
87
|
+
readonly software: "software";
|
|
88
|
+
readonly hardware: "hardware";
|
|
89
|
+
};
|
|
90
|
+
export type TiRtcVideoDecoderPreference = (typeof TiRtcVideoDecoderPreference)[keyof typeof TiRtcVideoDecoderPreference];
|
|
91
|
+
export declare const TiRtcVideoDecoderBackend: {
|
|
92
|
+
readonly unknown: "unknown";
|
|
93
|
+
readonly software: "software";
|
|
94
|
+
readonly hardware: "hardware";
|
|
95
|
+
};
|
|
96
|
+
export type TiRtcVideoDecoderBackend = (typeof TiRtcVideoDecoderBackend)[keyof typeof TiRtcVideoDecoderBackend];
|
|
97
|
+
export declare const TiRtcVideoBitstreamFormat: {
|
|
98
|
+
readonly unknown: "unknown";
|
|
99
|
+
readonly h264AnnexB: "h264AnnexB";
|
|
100
|
+
readonly h265AnnexB: "h265AnnexB";
|
|
101
|
+
readonly mjpegJfif: "mjpegJfif";
|
|
102
|
+
};
|
|
103
|
+
export type TiRtcVideoBitstreamFormat = (typeof TiRtcVideoBitstreamFormat)[keyof typeof TiRtcVideoBitstreamFormat];
|
|
104
|
+
export declare const TiRtcAudioOutputState: {
|
|
105
|
+
readonly idle: "idle";
|
|
106
|
+
readonly buffering: "buffering";
|
|
107
|
+
readonly playing: "playing";
|
|
108
|
+
readonly failed: "failed";
|
|
109
|
+
};
|
|
110
|
+
export type TiRtcAudioOutputState = (typeof TiRtcAudioOutputState)[keyof typeof TiRtcAudioOutputState];
|
|
111
|
+
export declare const TiRtcVideoOutputState: {
|
|
112
|
+
readonly idle: "idle";
|
|
113
|
+
readonly buffering: "buffering";
|
|
114
|
+
readonly rendering: "rendering";
|
|
115
|
+
readonly failed: "failed";
|
|
116
|
+
};
|
|
117
|
+
export type TiRtcVideoOutputState = (typeof TiRtcVideoOutputState)[keyof typeof TiRtcVideoOutputState];
|
|
118
|
+
export type TiRtcInitOptions = Readonly<{
|
|
119
|
+
appId?: string;
|
|
120
|
+
endpoint?: string;
|
|
121
|
+
consoleLogEnabled?: boolean;
|
|
122
|
+
}>;
|
|
123
|
+
export type TiRtcAudioOutputOptions = Readonly<{
|
|
124
|
+
agcLevel?: TiRtcAudioAgcLevel;
|
|
125
|
+
ansLevel?: TiRtcAudioAnsLevel;
|
|
126
|
+
bufferStrategy?: TiRtcOutputBufferStrategy;
|
|
127
|
+
maxBufferWatermarkMs?: number;
|
|
128
|
+
}>;
|
|
129
|
+
export type TiRtcVideoOutputOptions = Readonly<{
|
|
130
|
+
decoderPreference?: TiRtcVideoDecoderPreference;
|
|
131
|
+
bufferStrategy?: TiRtcOutputBufferStrategy;
|
|
132
|
+
maxBufferWatermarkMs?: number;
|
|
133
|
+
}>;
|
|
134
|
+
/**
|
|
135
|
+
* Props for the public remote video Fabric surface.
|
|
136
|
+
*
|
|
137
|
+
* Pass the owning `TiRtcVideoOutput` instance, not a native id. The component
|
|
138
|
+
* renders an inert React Native `View` until the output has a live native
|
|
139
|
+
* identity, and returns to that placeholder after the owner is disposed.
|
|
140
|
+
*/
|
|
141
|
+
export type TiRtcVideoOutputViewProps = ViewProps & Readonly<{
|
|
142
|
+
/** Video output owner whose attached stream should render in this surface. */
|
|
143
|
+
output: TiRtcVideoOutput;
|
|
144
|
+
/** Surface scaling mode. Defaults to `contain`. */
|
|
145
|
+
resizeMode?: 'contain' | 'cover' | 'stretch';
|
|
146
|
+
}>;
|
|
147
|
+
export type TiRtcAudioInputOptions = Readonly<{
|
|
148
|
+
codec?: TiRtcAudioCodec;
|
|
149
|
+
sampleRate?: TiRtcAudioSampleRate;
|
|
150
|
+
channels?: TiRtcAudioChannelCount;
|
|
151
|
+
aecMode?: TiRtcAudioAecMode;
|
|
152
|
+
agcLevel?: TiRtcAudioAgcLevel;
|
|
153
|
+
ansLevel?: TiRtcAudioAnsLevel;
|
|
154
|
+
}>;
|
|
155
|
+
export type TiRtcVideoInputOptions = Readonly<{
|
|
156
|
+
codec?: TiRtcVideoEncoderCodec;
|
|
157
|
+
width?: number;
|
|
158
|
+
height?: number;
|
|
159
|
+
frameRate?: TiRtcVideoFrameRate;
|
|
160
|
+
bitrateKbps?: number;
|
|
161
|
+
cameraFacing?: TiRtcCameraFacing;
|
|
162
|
+
}>;
|
|
163
|
+
/**
|
|
164
|
+
* Props for the public local camera preview Fabric surface.
|
|
165
|
+
*
|
|
166
|
+
* Pass the owning `TiRtcVideoInput` instance, not a native id. The component
|
|
167
|
+
* renders an inert React Native `View` until the input has a live native
|
|
168
|
+
* identity, and returns to that placeholder after the owner is disposed.
|
|
169
|
+
*/
|
|
170
|
+
export type TiRtcVideoInputPreviewProps = ViewProps & Readonly<{
|
|
171
|
+
/** Video input owner whose local capture preview should render here. */
|
|
172
|
+
input: TiRtcVideoInput;
|
|
173
|
+
/** Surface scaling mode. Defaults to `contain`. */
|
|
174
|
+
resizeMode?: 'contain' | 'cover' | 'stretch';
|
|
175
|
+
}>;
|
|
176
|
+
export type TiRtcOnConnStateChanged = (state: TiRtcConnState, errorCode: number) => void;
|
|
177
|
+
export type TiRtcOnConnCommand = (commandId: number, data: Uint8Array) => void;
|
|
178
|
+
export type TiRtcOnConnStreamMessage = (streamId: number, timestampMs: number, data: Uint8Array) => void;
|
|
179
|
+
export type TiRtcOnAudioOutputStateChanged = (state: TiRtcAudioOutputState) => void;
|
|
180
|
+
export type TiRtcOnAudioOutputError = (code: number) => void;
|
|
181
|
+
export type TiRtcOnVideoOutputStateChanged = (state: TiRtcVideoOutputState) => void;
|
|
182
|
+
export type TiRtcOnVideoOutputRenderSizeChanged = (size: TiRtcSize) => void;
|
|
183
|
+
export type TiRtcOnVideoOutputError = (code: number) => void;
|
|
184
|
+
export type TiRtcOnInputStateChanged = (state: TiRtcInputState) => void;
|
|
185
|
+
export type TiRtcOnInputError = (code: number, message: string | null) => void;
|
|
186
|
+
export type TiRtcOnVideoInputActualConfigChanged = (size: TiRtcSize, fps: number) => void;
|
|
187
|
+
export type TiRtcConnMetricsResult = Readonly<{
|
|
188
|
+
code: number;
|
|
189
|
+
snapshot: TiRtcConnMetricsSnapshot | null;
|
|
190
|
+
}>;
|
|
191
|
+
export type TiRtcConnMetricsSnapshot = Readonly<{
|
|
192
|
+
hasConnectStart: boolean;
|
|
193
|
+
hasConnected: boolean;
|
|
194
|
+
connectStartMonotonicMs: number;
|
|
195
|
+
connectedMonotonicMs: number;
|
|
196
|
+
isReady: boolean;
|
|
197
|
+
connectDurationMs: number | null;
|
|
198
|
+
}>;
|
|
199
|
+
export type TiRtcOutputStartupMetrics = Readonly<{
|
|
200
|
+
hasConnectStart: boolean;
|
|
201
|
+
hasConnected: boolean;
|
|
202
|
+
hasFirstPacket: boolean;
|
|
203
|
+
hasFirstOutput: boolean;
|
|
204
|
+
connectStartMonotonicMs: number;
|
|
205
|
+
connectedMonotonicMs: number;
|
|
206
|
+
firstPacketMonotonicMs: number;
|
|
207
|
+
firstOutputMonotonicMs: number;
|
|
208
|
+
firstPacketAfterConnectedMs: number;
|
|
209
|
+
firstOutputAfterConnectedMs: number;
|
|
210
|
+
timeToFirstOutputMs: number;
|
|
211
|
+
}>;
|
|
212
|
+
export type TiRtcOutputStutterMetrics = Readonly<{
|
|
213
|
+
stutterThresholdMs: number;
|
|
214
|
+
outputDurationMs: number;
|
|
215
|
+
stutterTotalMs: number;
|
|
216
|
+
stutterCount: number;
|
|
217
|
+
stutterPeakMs: number;
|
|
218
|
+
stutterAverageMs: number;
|
|
219
|
+
stutterRatePercent: number;
|
|
220
|
+
}>;
|
|
221
|
+
export type TiRtcAudioOutputMetricsResult = Readonly<{
|
|
222
|
+
code: number;
|
|
223
|
+
snapshot: TiRtcAudioOutputMetricsSnapshot | null;
|
|
224
|
+
}>;
|
|
225
|
+
export type TiRtcAudioOutputMetricsSnapshot = Readonly<{
|
|
226
|
+
startup: TiRtcOutputStartupMetrics;
|
|
227
|
+
stutter: TiRtcOutputStutterMetrics;
|
|
228
|
+
estimatedOutputLatencyMs: number;
|
|
229
|
+
audioCodec: TiRtcAudioCodec | null;
|
|
230
|
+
audioSampleRateHz: number;
|
|
231
|
+
audioChannels: number;
|
|
232
|
+
audioInputBitrateKbps: number;
|
|
233
|
+
audioInputPacketRate: number;
|
|
234
|
+
audioRenderCallbackRate: number;
|
|
235
|
+
statsRefreshIntervalMs: number;
|
|
236
|
+
statsUpdatedAtMonotonicMs: number;
|
|
237
|
+
}>;
|
|
238
|
+
export type TiRtcVideoOutputMetricsResult = Readonly<{
|
|
239
|
+
code: number;
|
|
240
|
+
snapshot: TiRtcVideoOutputMetricsSnapshot | null;
|
|
241
|
+
}>;
|
|
242
|
+
export type TiRtcVideoOutputMetricsSnapshot = Readonly<{
|
|
243
|
+
startup: TiRtcOutputStartupMetrics;
|
|
244
|
+
stutter: TiRtcOutputStutterMetrics;
|
|
245
|
+
estimatedOutputLatencyMs: number;
|
|
246
|
+
videoCodec: TiRtcVideoCodec | null;
|
|
247
|
+
videoWidth: number;
|
|
248
|
+
videoHeight: number;
|
|
249
|
+
decoderBackend: TiRtcVideoDecoderBackend;
|
|
250
|
+
videoInputBitrateKbps: number;
|
|
251
|
+
videoInputFps: number;
|
|
252
|
+
videoDecodedFps: number;
|
|
253
|
+
videoRenderFps: number;
|
|
254
|
+
statsRefreshIntervalMs: number;
|
|
255
|
+
statsUpdatedAtMonotonicMs: number;
|
|
256
|
+
}>;
|
|
257
|
+
export type TiRtcAudioOutputDebugSnapshotResult = Readonly<{
|
|
258
|
+
code: number;
|
|
259
|
+
snapshot: TiRtcAudioOutputDebugSnapshot | null;
|
|
260
|
+
}>;
|
|
261
|
+
export type TiRtcAudioOutputDebugSnapshot = Readonly<{
|
|
262
|
+
codec: TiRtcAudioCodec | null;
|
|
263
|
+
sampleRateHz: number;
|
|
264
|
+
channels: number;
|
|
265
|
+
}>;
|
|
266
|
+
export type TiRtcVideoOutputDebugSnapshotResult = Readonly<{
|
|
267
|
+
code: number;
|
|
268
|
+
snapshot: TiRtcVideoOutputDebugSnapshot | null;
|
|
269
|
+
}>;
|
|
270
|
+
export type TiRtcVideoOutputDebugSnapshot = Readonly<{
|
|
271
|
+
codec: TiRtcVideoCodec | null;
|
|
272
|
+
bitstreamFormat: TiRtcVideoBitstreamFormat;
|
|
273
|
+
width: number;
|
|
274
|
+
height: number;
|
|
275
|
+
decoderPreference: TiRtcVideoDecoderPreference;
|
|
276
|
+
resolvedDecoderBackend: TiRtcVideoDecoderBackend;
|
|
277
|
+
}>;
|
|
278
|
+
export type TiRtcLoggingUploadResult = Readonly<{
|
|
279
|
+
code: number;
|
|
280
|
+
logId: string | null;
|
|
281
|
+
}>;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { TiRtcConn } from './conn';
|
|
3
|
+
import type { TiRtcInputState, TiRtcOnInputError, TiRtcOnInputStateChanged, TiRtcOnVideoInputActualConfigChanged, TiRtcSize, TiRtcVideoInputOptions, TiRtcVideoInputPreviewProps } from './types';
|
|
4
|
+
type VideoInputPreviewPropsWithoutOwner = Omit<TiRtcVideoInputPreviewProps, 'input'>;
|
|
5
|
+
export declare class TiRtcVideoInput {
|
|
6
|
+
private identity;
|
|
7
|
+
private disposed;
|
|
8
|
+
private createCode;
|
|
9
|
+
private queue;
|
|
10
|
+
private currentState;
|
|
11
|
+
private currentOutputSize;
|
|
12
|
+
private currentOutputFps;
|
|
13
|
+
private options;
|
|
14
|
+
onStateChanged: TiRtcOnInputStateChanged | null;
|
|
15
|
+
onActualConfigChanged: TiRtcOnVideoInputActualConfigChanged | null;
|
|
16
|
+
onError: TiRtcOnInputError | null;
|
|
17
|
+
constructor();
|
|
18
|
+
get state(): TiRtcInputState;
|
|
19
|
+
get outputSize(): TiRtcSize | null;
|
|
20
|
+
get outputFps(): number | null;
|
|
21
|
+
setOptions(options: TiRtcVideoInputOptions): Promise<number>;
|
|
22
|
+
start(): Promise<number>;
|
|
23
|
+
attach(connection: TiRtcConn, streamId: number): Promise<number>;
|
|
24
|
+
detach(connection: TiRtcConn): Promise<number>;
|
|
25
|
+
stop(): Promise<number>;
|
|
26
|
+
/**
|
|
27
|
+
* Creates a React element bound to this input owner.
|
|
28
|
+
*
|
|
29
|
+
* The returned element renders a placeholder until this input has a live
|
|
30
|
+
* native identity. Configure and start the input before expecting camera
|
|
31
|
+
* frames, and dispose the input when capture is no longer needed.
|
|
32
|
+
*/
|
|
33
|
+
preview(props?: VideoInputPreviewPropsWithoutOwner): React.ReactElement;
|
|
34
|
+
dispose(): Promise<number>;
|
|
35
|
+
private enqueue;
|
|
36
|
+
private ensureIdentity;
|
|
37
|
+
private adoptIdentity;
|
|
38
|
+
private refreshActualConfig;
|
|
39
|
+
private clearCallbacks;
|
|
40
|
+
private handleEvent;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Renders the local preview surface for a `TiRtcVideoInput`.
|
|
44
|
+
*
|
|
45
|
+
* The component observes the owner identity and never accepts raw native ids.
|
|
46
|
+
* If the owner is not created, has been disposed, or is not a `TiRtcVideoInput`,
|
|
47
|
+
* it renders a regular `View` with the remaining props.
|
|
48
|
+
*/
|
|
49
|
+
export declare function TiRtcVideoInputPreview(props: TiRtcVideoInputPreviewProps): React.ReactElement;
|
|
50
|
+
export {};
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { TiRtcConn } from './conn';
|
|
3
|
+
import type { TiRtcOnVideoOutputError, TiRtcOnVideoOutputRenderSizeChanged, TiRtcOnVideoOutputStateChanged, TiRtcSize, TiRtcVideoOutputDebugSnapshotResult, TiRtcVideoOutputMetricsResult, TiRtcVideoOutputOptions, TiRtcVideoOutputState, TiRtcVideoOutputViewProps } from './types';
|
|
4
|
+
type VideoOutputViewPropsWithoutOwner = Omit<TiRtcVideoOutputViewProps, 'output'>;
|
|
5
|
+
export declare class TiRtcVideoOutput {
|
|
6
|
+
private identity;
|
|
7
|
+
private disposed;
|
|
8
|
+
private createCode;
|
|
9
|
+
private currentState;
|
|
10
|
+
private currentRenderSize;
|
|
11
|
+
private options;
|
|
12
|
+
onStateChanged: TiRtcOnVideoOutputStateChanged | null;
|
|
13
|
+
onRenderSizeChanged: TiRtcOnVideoOutputRenderSizeChanged | null;
|
|
14
|
+
onError: TiRtcOnVideoOutputError | null;
|
|
15
|
+
constructor();
|
|
16
|
+
get state(): TiRtcVideoOutputState;
|
|
17
|
+
get renderSize(): TiRtcSize | null;
|
|
18
|
+
setOptions(options: TiRtcVideoOutputOptions): number;
|
|
19
|
+
attach(connection: TiRtcConn, streamId: number): number;
|
|
20
|
+
detach(): number;
|
|
21
|
+
/**
|
|
22
|
+
* Creates a React element bound to this output owner.
|
|
23
|
+
*
|
|
24
|
+
* The returned element renders a placeholder until this output has a live
|
|
25
|
+
* native identity. Attach the output to a connection before expecting remote
|
|
26
|
+
* frames, and dispose the output when the render surface is no longer needed.
|
|
27
|
+
*/
|
|
28
|
+
view(props?: VideoOutputViewPropsWithoutOwner): React.ReactElement;
|
|
29
|
+
getMetricsSnapshot(): TiRtcVideoOutputMetricsResult;
|
|
30
|
+
resetMetricsSession(): number;
|
|
31
|
+
getDebugSnapshot(): TiRtcVideoOutputDebugSnapshotResult;
|
|
32
|
+
dispose(): number;
|
|
33
|
+
private ensureIdentity;
|
|
34
|
+
private adoptIdentity;
|
|
35
|
+
private clearCallbacks;
|
|
36
|
+
private handleEvent;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Renders the remote video stream attached to a `TiRtcVideoOutput`.
|
|
40
|
+
*
|
|
41
|
+
* The component observes the owner identity and never accepts raw native ids.
|
|
42
|
+
* If the owner is not created, has been disposed, or is not a `TiRtcVideoOutput`,
|
|
43
|
+
* it renders a regular `View` with the remaining props.
|
|
44
|
+
*/
|
|
45
|
+
export declare function TiRtcVideoOutputView(props: TiRtcVideoOutputViewProps): React.ReactElement;
|
|
46
|
+
export {};
|
package/package.json
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "tirtc-react-native",
|
|
3
|
+
"version": "2.2.0",
|
|
4
|
+
"description": "TiRTC React Native SDK",
|
|
5
|
+
"homepage": "https://tange.ai/",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://gitlab.tange-ai.com/tirtc-nexus/tirtc.git",
|
|
9
|
+
"directory": "react-native/tirtc"
|
|
10
|
+
},
|
|
11
|
+
"bugs": {
|
|
12
|
+
"url": "https://gitlab.tange-ai.com/tirtc-nexus/tirtc/-/issues"
|
|
13
|
+
},
|
|
14
|
+
"keywords": [
|
|
15
|
+
"tirtc",
|
|
16
|
+
"react-native",
|
|
17
|
+
"audio",
|
|
18
|
+
"video",
|
|
19
|
+
"webrtc",
|
|
20
|
+
"new-architecture"
|
|
21
|
+
],
|
|
22
|
+
"main": "./lib/module/index.js",
|
|
23
|
+
"module": "./lib/module/index.js",
|
|
24
|
+
"types": "./lib/typescript/index.d.ts",
|
|
25
|
+
"react-native": "./lib/module/index.js",
|
|
26
|
+
"source": "src/index.ts",
|
|
27
|
+
"exports": {
|
|
28
|
+
".": {
|
|
29
|
+
"react-native": "./lib/module/index.js",
|
|
30
|
+
"import": "./lib/module/index.js",
|
|
31
|
+
"types": "./lib/typescript/index.d.ts",
|
|
32
|
+
"default": "./lib/module/index.js"
|
|
33
|
+
},
|
|
34
|
+
"./package.json": "./package.json"
|
|
35
|
+
},
|
|
36
|
+
"files": [
|
|
37
|
+
"android/build.gradle",
|
|
38
|
+
"android/src/",
|
|
39
|
+
"ios/",
|
|
40
|
+
"src/",
|
|
41
|
+
"lib/module/",
|
|
42
|
+
"lib/typescript/",
|
|
43
|
+
"README.md",
|
|
44
|
+
"LICENSE",
|
|
45
|
+
"TiRtcReactNative.podspec",
|
|
46
|
+
"react-native.config.js"
|
|
47
|
+
],
|
|
48
|
+
"scripts": {
|
|
49
|
+
"build": "node scripts/clean_generated_lib.mjs && tsc -p tsconfig.build.json && node scripts/write_codegen_component_specs.mjs",
|
|
50
|
+
"lint": "node test/source_guard.mjs",
|
|
51
|
+
"preflight:npm": "node scripts/npm_preflight.mjs",
|
|
52
|
+
"test": "node test/parity_guard.mjs && node test/package_artifact_guard.mjs && node test/lifecycle_contract_guard.mjs && node test/lifecycle_behavior_guard.mjs && node test/integration_contract_guard.mjs && node test/runner_schema_guard.mjs",
|
|
53
|
+
"test:contract-red": "node test/contract_red_summary.mjs",
|
|
54
|
+
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
55
|
+
"codegen:check": "node test/codegen_contract_guard.mjs"
|
|
56
|
+
},
|
|
57
|
+
"peerDependencies": {
|
|
58
|
+
"react": "*",
|
|
59
|
+
"react-native": ">=0.80.0"
|
|
60
|
+
},
|
|
61
|
+
"devDependencies": {
|
|
62
|
+
"@types/react": "^19.2.17",
|
|
63
|
+
"typescript": "^5.9.0"
|
|
64
|
+
},
|
|
65
|
+
"codegenConfig": {
|
|
66
|
+
"name": "TiRtcSpec",
|
|
67
|
+
"type": "all",
|
|
68
|
+
"jsSrcsDir": "src/specs",
|
|
69
|
+
"ios": {
|
|
70
|
+
"componentProvider": {
|
|
71
|
+
"TiRtcVideoOutputView": "TiRtcVideoOutputView",
|
|
72
|
+
"TiRtcVideoInputPreview": "TiRtcVideoInputPreview"
|
|
73
|
+
}
|
|
74
|
+
},
|
|
75
|
+
"android": {
|
|
76
|
+
"javaPackageName": "com.tange.ai.tirtc.reactnative"
|
|
77
|
+
}
|
|
78
|
+
},
|
|
79
|
+
"license": "BSD-3-Clause"
|
|
80
|
+
}
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
import {
|
|
2
|
+
isPlainObject,
|
|
3
|
+
isUInt8,
|
|
4
|
+
normalizeCreateResult,
|
|
5
|
+
returnReleasedIfDisposed,
|
|
6
|
+
TIRTC_ERROR_INVALID_ARGUMENT,
|
|
7
|
+
TIRTC_ERROR_OK,
|
|
8
|
+
TIRTC_HOST_ERROR_OBJECT_RELEASED,
|
|
9
|
+
} from './errors';
|
|
10
|
+
import {registerNativeEventHandler, unregisterNativeEventHandler} from './events';
|
|
11
|
+
import {clearNativeIdentity, readNativeIdentity, setNativeIdentity, type NativeIdentity} from './native_object_id';
|
|
12
|
+
import {NativeTiRtc, type NativeTiRtcEvent} from './native';
|
|
13
|
+
import {TiRtcConn} from './conn';
|
|
14
|
+
import type {
|
|
15
|
+
TiRtcAudioInputOptions,
|
|
16
|
+
TiRtcInputState,
|
|
17
|
+
TiRtcOnInputError,
|
|
18
|
+
TiRtcOnInputStateChanged,
|
|
19
|
+
} from './types';
|
|
20
|
+
|
|
21
|
+
export class TiRtcAudioInput {
|
|
22
|
+
private identity: NativeIdentity | null = null;
|
|
23
|
+
private disposed = false;
|
|
24
|
+
private createCode: number = TIRTC_ERROR_OK;
|
|
25
|
+
private queue: Promise<unknown> = Promise.resolve();
|
|
26
|
+
private currentState: TiRtcInputState = 'idle';
|
|
27
|
+
private options: Required<TiRtcAudioInputOptions> = {
|
|
28
|
+
codec: 'g711a',
|
|
29
|
+
sampleRate: 'rate16k',
|
|
30
|
+
channels: 'mono',
|
|
31
|
+
aecMode: 'disabled',
|
|
32
|
+
agcLevel: 'disabled',
|
|
33
|
+
ansLevel: 'disabled',
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
onStateChanged: TiRtcOnInputStateChanged | null = null;
|
|
37
|
+
onError: TiRtcOnInputError | null = null;
|
|
38
|
+
|
|
39
|
+
constructor() {
|
|
40
|
+
const result = normalizeCreateResult(NativeTiRtc.createAudioInput());
|
|
41
|
+
this.createCode = result.code;
|
|
42
|
+
if (result.code === TIRTC_ERROR_OK) {
|
|
43
|
+
this.adoptIdentity({objectId: result.objectId, generation: result.generation});
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
get state(): TiRtcInputState {
|
|
48
|
+
if (this.identity !== null && !this.disposed) {
|
|
49
|
+
const result = NativeTiRtc.audioInputGetState(this.identity.objectId);
|
|
50
|
+
if (result.state !== null) {
|
|
51
|
+
this.currentState = result.state as TiRtcInputState;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return this.currentState;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
setOptions(options: TiRtcAudioInputOptions): Promise<number> {
|
|
58
|
+
if (!isPlainObject(options)) {
|
|
59
|
+
return Promise.resolve(TIRTC_ERROR_INVALID_ARGUMENT);
|
|
60
|
+
}
|
|
61
|
+
const normalized = {
|
|
62
|
+
codec: options.codec ?? 'g711a',
|
|
63
|
+
sampleRate: options.sampleRate ?? 'rate16k',
|
|
64
|
+
channels: options.channels ?? 'mono',
|
|
65
|
+
aecMode: options.aecMode ?? 'disabled',
|
|
66
|
+
agcLevel: options.agcLevel ?? 'disabled',
|
|
67
|
+
ansLevel: options.ansLevel ?? 'disabled',
|
|
68
|
+
};
|
|
69
|
+
return this.enqueue(async () => {
|
|
70
|
+
const identity = this.ensureIdentity();
|
|
71
|
+
if (typeof identity === 'number') {
|
|
72
|
+
return identity;
|
|
73
|
+
}
|
|
74
|
+
const code = await NativeTiRtc.audioInputSetOptions(identity.objectId, normalized);
|
|
75
|
+
if (code === TIRTC_ERROR_OK) {
|
|
76
|
+
this.options = normalized;
|
|
77
|
+
}
|
|
78
|
+
return code;
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
attach(connection: TiRtcConn, streamId: number): Promise<number> {
|
|
83
|
+
const connIdentity = readNativeIdentity(connection);
|
|
84
|
+
if (!isUInt8(streamId)) {
|
|
85
|
+
return Promise.resolve(TIRTC_ERROR_INVALID_ARGUMENT);
|
|
86
|
+
}
|
|
87
|
+
if (connIdentity === null) {
|
|
88
|
+
return Promise.resolve(TIRTC_ERROR_INVALID_ARGUMENT);
|
|
89
|
+
}
|
|
90
|
+
return this.enqueue(async () => {
|
|
91
|
+
const identity = this.ensureIdentity();
|
|
92
|
+
if (typeof identity === 'number') {
|
|
93
|
+
return identity;
|
|
94
|
+
}
|
|
95
|
+
return NativeTiRtc.audioInputAttach(identity.objectId, connIdentity.objectId, streamId);
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
start(): Promise<number> {
|
|
100
|
+
return this.enqueue(async () => {
|
|
101
|
+
const identity = this.ensureIdentity();
|
|
102
|
+
if (typeof identity === 'number') {
|
|
103
|
+
return identity;
|
|
104
|
+
}
|
|
105
|
+
return NativeTiRtc.audioInputStart(identity.objectId);
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
stop(): Promise<number> {
|
|
110
|
+
return this.enqueue(async () => {
|
|
111
|
+
if (this.identity === null) {
|
|
112
|
+
return TIRTC_ERROR_OK;
|
|
113
|
+
}
|
|
114
|
+
return NativeTiRtc.audioInputStop(this.identity.objectId);
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
detach(connection: TiRtcConn): Promise<number> {
|
|
119
|
+
const connIdentity = readNativeIdentity(connection);
|
|
120
|
+
if (connIdentity === null) {
|
|
121
|
+
return Promise.resolve(TIRTC_ERROR_INVALID_ARGUMENT);
|
|
122
|
+
}
|
|
123
|
+
return this.enqueue(async () => {
|
|
124
|
+
if (this.identity === null) {
|
|
125
|
+
return TIRTC_ERROR_OK;
|
|
126
|
+
}
|
|
127
|
+
return NativeTiRtc.audioInputDetach(this.identity.objectId, connIdentity.objectId);
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
dispose(): Promise<number> {
|
|
132
|
+
if (this.disposed) {
|
|
133
|
+
return Promise.resolve(TIRTC_ERROR_OK);
|
|
134
|
+
}
|
|
135
|
+
return this.enqueue(async () => {
|
|
136
|
+
if (this.identity === null) {
|
|
137
|
+
this.disposed = true;
|
|
138
|
+
this.clearCallbacks();
|
|
139
|
+
this.currentState = 'stopped';
|
|
140
|
+
return TIRTC_ERROR_OK;
|
|
141
|
+
}
|
|
142
|
+
const identity = this.identity;
|
|
143
|
+
const code = await NativeTiRtc.audioInputDispose(identity.objectId);
|
|
144
|
+
if (code === TIRTC_ERROR_OK) {
|
|
145
|
+
this.disposed = true;
|
|
146
|
+
this.identity = null;
|
|
147
|
+
unregisterNativeEventHandler(identity);
|
|
148
|
+
clearNativeIdentity(this);
|
|
149
|
+
this.clearCallbacks();
|
|
150
|
+
this.currentState = 'stopped';
|
|
151
|
+
}
|
|
152
|
+
return code;
|
|
153
|
+
}, true);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
private enqueue(operation: () => Promise<number>, allowDisposed = false): Promise<number> {
|
|
157
|
+
const released = returnReleasedIfDisposed(this.disposed);
|
|
158
|
+
if (released !== null && !allowDisposed) {
|
|
159
|
+
return Promise.resolve(released);
|
|
160
|
+
}
|
|
161
|
+
const next = this.queue.then(async () => {
|
|
162
|
+
if (this.disposed && !allowDisposed) {
|
|
163
|
+
return TIRTC_HOST_ERROR_OBJECT_RELEASED;
|
|
164
|
+
}
|
|
165
|
+
return operation();
|
|
166
|
+
});
|
|
167
|
+
this.queue = next.catch(() => undefined);
|
|
168
|
+
return next;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
private ensureIdentity(): NativeIdentity | number {
|
|
172
|
+
const released = returnReleasedIfDisposed(this.disposed);
|
|
173
|
+
if (released !== null) {
|
|
174
|
+
return released;
|
|
175
|
+
}
|
|
176
|
+
if (this.identity !== null) {
|
|
177
|
+
return this.identity;
|
|
178
|
+
}
|
|
179
|
+
return this.createCode;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
private adoptIdentity(identity: NativeIdentity): void {
|
|
183
|
+
this.identity = identity;
|
|
184
|
+
setNativeIdentity(this, identity);
|
|
185
|
+
registerNativeEventHandler(identity, (event) => this.handleEvent(event));
|
|
186
|
+
void NativeTiRtc.audioInputSetOptions(identity.objectId, this.options);
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
private clearCallbacks(): void {
|
|
190
|
+
this.onStateChanged = null;
|
|
191
|
+
this.onError = null;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
private handleEvent(event: NativeTiRtcEvent): void {
|
|
195
|
+
if (this.disposed) {
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
if (event.type === 'audioInputStateChanged' && event.state !== undefined) {
|
|
199
|
+
this.currentState = event.state as TiRtcInputState;
|
|
200
|
+
this.onStateChanged?.(this.currentState);
|
|
201
|
+
} else if (event.type === 'audioInputError') {
|
|
202
|
+
this.onError?.(event.code ?? TIRTC_ERROR_INVALID_ARGUMENT, event.message ?? null);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
}
|