tirtc-react-native 2.3.0 → 2.4.0-alpha.3

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 (77) hide show
  1. package/README.md +23 -7
  2. package/TiRtcReactNative.podspec +1 -1
  3. package/android/build.gradle +1 -1
  4. package/android/src/main/AndroidManifest.xml +2 -1
  5. package/android/src/main/java/com/tange/ai/tirtc/reactnative/TiRtcModule.kt +585 -28
  6. package/android/src/main/java/com/tange/ai/tirtc/reactnative/TiRtcReactNativeCleanup.kt +115 -0
  7. package/android/src/main/java/com/tange/ai/tirtc/reactnative/TiRtcReactNativeEventBinder.kt +35 -8
  8. package/android/src/main/java/com/tange/ai/tirtc/reactnative/TiRtcReactNativeEventSink.kt +20 -0
  9. package/android/src/main/java/com/tange/ai/tirtc/reactnative/TiRtcReactNativeMaps.kt +62 -0
  10. package/android/src/main/java/com/tange/ai/tirtc/reactnative/TiRtcReactNativeModuleSupport.kt +6 -6
  11. package/android/src/main/java/com/tange/ai/tirtc/reactnative/TiRtcReactNativeRegistry.kt +27 -0
  12. package/android/src/main/java/com/tange/ai/tirtc/reactnative/TiRtcReactNativeStoreSupport.kt +64 -0
  13. package/android/src/main/java/com/tange/ai/tirtc/reactnative/TiRtcVideoOutputViewManager.kt +17 -2
  14. package/ios/TiRtcReactNative+Conn.mm +173 -2
  15. package/ios/TiRtcReactNative+Input.mm +18 -4
  16. package/ios/TiRtcReactNative+Output.mm +41 -4
  17. package/ios/TiRtcReactNative+Private.h +4 -0
  18. package/ios/TiRtcReactNative+Store.mm +496 -0
  19. package/ios/TiRtcReactNative.h +2 -1
  20. package/ios/TiRtcReactNative.mm +109 -1
  21. package/ios/TiRtcReactNativeEventBinder.h +8 -0
  22. package/ios/TiRtcReactNativeEventBinder.mm +104 -0
  23. package/ios/TiRtcReactNativeEventSink.h +4 -0
  24. package/ios/TiRtcReactNativeEventSink.mm +20 -0
  25. package/ios/TiRtcReactNativeRegistry.h +5 -0
  26. package/ios/TiRtcReactNativeRegistry.mm +43 -0
  27. package/ios/TiRtcVideoOutputView.mm +11 -0
  28. package/lib/module/audio_input.js +33 -17
  29. package/lib/module/audio_input.js.map +1 -1
  30. package/lib/module/audio_output.js +27 -10
  31. package/lib/module/audio_output.js.map +1 -1
  32. package/lib/module/conn.js +31 -7
  33. package/lib/module/conn.js.map +1 -1
  34. package/lib/module/errors.js +4 -3
  35. package/lib/module/errors.js.map +1 -1
  36. package/lib/module/index.js +2 -0
  37. package/lib/module/index.js.map +1 -1
  38. package/lib/module/logging.js +9 -1
  39. package/lib/module/logging.js.map +1 -1
  40. package/lib/module/logging_internal.js +27 -0
  41. package/lib/module/logging_internal.js.map +1 -0
  42. package/lib/module/recording.js +210 -0
  43. package/lib/module/recording.js.map +1 -0
  44. package/lib/module/runtime.js +13 -5
  45. package/lib/module/runtime.js.map +1 -1
  46. package/lib/module/specs/NativeTiRtc.js.map +1 -1
  47. package/lib/module/store.js +698 -0
  48. package/lib/module/store.js.map +1 -0
  49. package/lib/module/video_input.js +40 -22
  50. package/lib/module/video_input.js.map +1 -1
  51. package/lib/module/video_output.js +51 -10
  52. package/lib/module/video_output.js.map +1 -1
  53. package/lib/typescript/audio_input.d.ts +1 -0
  54. package/lib/typescript/conn.d.ts +2 -0
  55. package/lib/typescript/errors.d.ts +3 -2
  56. package/lib/typescript/index.d.ts +4 -0
  57. package/lib/typescript/logging_internal.d.ts +2 -0
  58. package/lib/typescript/recording.d.ts +53 -0
  59. package/lib/typescript/runtime.d.ts +2 -0
  60. package/lib/typescript/specs/NativeTiRtc.d.ts +88 -0
  61. package/lib/typescript/store.d.ts +202 -0
  62. package/lib/typescript/video_input.d.ts +1 -0
  63. package/lib/typescript/video_output.d.ts +3 -0
  64. package/package.json +1 -1
  65. package/src/audio_input.ts +85 -59
  66. package/src/audio_output.ts +30 -17
  67. package/src/conn.ts +46 -28
  68. package/src/errors.ts +4 -3
  69. package/src/index.ts +54 -0
  70. package/src/logging.ts +7 -1
  71. package/src/logging_internal.ts +23 -0
  72. package/src/recording.ts +271 -0
  73. package/src/runtime.ts +14 -5
  74. package/src/specs/NativeTiRtc.ts +123 -0
  75. package/src/store.ts +760 -0
  76. package/src/video_input.ts +97 -62
  77. package/src/video_output.ts +54 -16
@@ -43,6 +43,29 @@ export type NativeVideoInputOptions = Readonly<{
43
43
  bitrateKbps: number;
44
44
  cameraFacing: 'front' | 'back';
45
45
  }>;
46
+ export type NativeRecordingOptions = Readonly<{
47
+ videoStreamId: number;
48
+ audioStreamId: number | null;
49
+ }>;
50
+ export type NativeRecordingStartResult = Readonly<{
51
+ code: number;
52
+ taskId: NativeObjectId | null;
53
+ }>;
54
+ export type NativeMp4Result = Readonly<{
55
+ code: number;
56
+ fileId: NativeObjectId | null;
57
+ filePath: string | null;
58
+ durationMs: number | null;
59
+ }>;
60
+ export type NativeSnapshotResult = Readonly<{
61
+ code: number;
62
+ fileId: NativeObjectId | null;
63
+ filePath: string | null;
64
+ }>;
65
+ export type NativeGalleryResult = Readonly<{
66
+ code: number;
67
+ uri: string | null;
68
+ }>;
46
69
  export type NativeStateResult = Readonly<{
47
70
  code: number;
48
71
  state: string | null;
@@ -60,6 +83,31 @@ export type NativeLoggingUploadResult = Readonly<{
60
83
  code: number;
61
84
  logId: string | null;
62
85
  }>;
86
+ export type NativeStoreRecordingRange = Readonly<{
87
+ startTimeMs: number;
88
+ endTimeMs: number;
89
+ }>;
90
+ export type NativeStoreRecordingRangesResult = Readonly<{
91
+ code: number;
92
+ recordings: ReadonlyArray<NativeStoreRecordingRange>;
93
+ }>;
94
+ export type NativeStoreRecordingDay = Readonly<{
95
+ date: string;
96
+ hasRecording: boolean;
97
+ }>;
98
+ export type NativeStoreRecordingDaysResult = Readonly<{
99
+ code: number;
100
+ days: ReadonlyArray<NativeStoreRecordingDay>;
101
+ }>;
102
+ export type NativeStoreReplayInfo = Readonly<{
103
+ code: number;
104
+ speed: number;
105
+ currentTimeMs: number | null;
106
+ }>;
107
+ export type NativeStoreTaskStartResult = Readonly<{
108
+ code: number;
109
+ taskId: NativeObjectId | null;
110
+ }>;
63
111
  export type NativeTiRtcEvent = Readonly<{
64
112
  type: string;
65
113
  objectId: NativeObjectId;
@@ -168,6 +216,40 @@ interface Spec extends TurboModule {
168
216
  errorToString(code: number): string;
169
217
  writeLog(level: number, tag: string, message: string): void;
170
218
  uploadLogs(): Promise<NativeLoggingUploadResult>;
219
+ storeInitialize(options: NativeInitOptions): Promise<number>;
220
+ storeShutdown(): number;
221
+ storeCreate(token: string): NativeCreateResult;
222
+ storeUpdateToken(id: NativeObjectId, token: string): number;
223
+ storeListRecordings(id: NativeObjectId, startTimeMs: number, endTimeMs: number): Promise<NativeStoreRecordingRangesResult>;
224
+ storeListRecordingDays(id: NativeObjectId, startDate: string, endDate: string, timeZoneId: string): Promise<NativeStoreRecordingDaysResult>;
225
+ storeCreateReplay(id: NativeObjectId): NativeCreateResult;
226
+ storeExportRecording(id: NativeObjectId, startTimeMs: number, endTimeMs: number, videoChannelId: number, audioChannelId: number | null): NativeStoreTaskStartResult;
227
+ storeExportProgress(id: NativeObjectId): number;
228
+ storeExportResult(id: NativeObjectId): Promise<NativeMp4Result>;
229
+ storeExportStop(id: NativeObjectId): number;
230
+ storeDispose(id: NativeObjectId): number;
231
+ storeReplayGetInfo(id: NativeObjectId): NativeStoreReplayInfo;
232
+ storeReplayPlay(id: NativeObjectId, startTimeMs: number, endTimeMs: number, initialTimeMs: number | null): number;
233
+ storeReplayPause(id: NativeObjectId): number;
234
+ storeReplayResume(id: NativeObjectId): number;
235
+ storeReplaySeek(id: NativeObjectId, timeMs: number): number;
236
+ storeReplaySetSpeed(id: NativeObjectId, speed: number): number;
237
+ storeReplayStartRecording(id: NativeObjectId, videoChannelId: number, audioChannelId: number | null): NativeStoreTaskStartResult;
238
+ storeRecordingTaskStop(id: NativeObjectId): Promise<NativeMp4Result>;
239
+ storeReplayStop(id: NativeObjectId): number;
240
+ storeReplayDispose(id: NativeObjectId): number;
241
+ storeCreateAudioOutput(): NativeCreateResult;
242
+ storeAudioOutputGetState(id: NativeObjectId): NativeStateResult;
243
+ storeAudioOutputSetVolume(id: NativeObjectId, volumePercent: number): number;
244
+ storeAudioOutputAttach(outputId: NativeObjectId, replayId: NativeObjectId, channelId: number): number;
245
+ storeAudioOutputDetach(outputId: NativeObjectId): number;
246
+ storeAudioOutputDispose(id: NativeObjectId): number;
247
+ storeCreateVideoOutput(): NativeCreateResult;
248
+ storeVideoOutputGetState(id: NativeObjectId): NativeStateResult;
249
+ storeVideoOutputAttach(outputId: NativeObjectId, replayId: NativeObjectId, channelId: number): number;
250
+ storeVideoOutputDetach(outputId: NativeObjectId): number;
251
+ storeVideoOutputTakeSnapshot(id: NativeObjectId): Promise<NativeSnapshotResult>;
252
+ storeVideoOutputDispose(id: NativeObjectId): number;
171
253
  createConn(): NativeCreateResult;
172
254
  connGetState(id: NativeObjectId): NativeStateResult;
173
255
  connConnect(id: NativeObjectId, remoteId: string, token: string): number;
@@ -179,6 +261,11 @@ interface Spec extends TurboModule {
179
261
  connSubscribeAudio(id: NativeObjectId, streamId: number): number;
180
262
  connUnsubscribeAudio(id: NativeObjectId, streamId: number): number;
181
263
  connRequestKeyFrame(id: NativeObjectId, streamId: number): number;
264
+ connStartRecording(id: NativeObjectId, options: NativeRecordingOptions): NativeRecordingStartResult;
265
+ recordingTaskStop(id: NativeObjectId): Promise<NativeMp4Result>;
266
+ mediaFileMoveToGallery(id: NativeObjectId, fileName: string | null): Promise<NativeGalleryResult>;
267
+ mediaFileDelete(id: NativeObjectId): Promise<number>;
268
+ mediaFileRelease(id: NativeObjectId): void;
182
269
  connGetMetricsSnapshot(id: NativeObjectId): NativeConnMetricsResult;
183
270
  connDispose(id: NativeObjectId): number;
184
271
  createAudioOutput(): NativeCreateResult;
@@ -200,6 +287,7 @@ interface Spec extends TurboModule {
200
287
  videoOutputGetMetricsSnapshot(id: NativeObjectId): NativeVideoOutputMetricsResult;
201
288
  videoOutputResetMetricsSession(id: NativeObjectId): number;
202
289
  videoOutputGetDebugSnapshot(id: NativeObjectId): NativeVideoOutputDebugSnapshotResult;
290
+ videoOutputTakeSnapshot(id: NativeObjectId): Promise<NativeSnapshotResult>;
203
291
  videoOutputDispose(id: NativeObjectId): number;
204
292
  createAudioInput(): NativeCreateResult;
205
293
  audioInputGetState(id: NativeObjectId): NativeStateResult;
@@ -0,0 +1,202 @@
1
+ import * as React from 'react';
2
+ import { type ViewProps } from 'react-native';
3
+ import { NativeTiRtc, type NativeTiRtcEvent } from './native';
4
+ import { type NativeIdentity } from './native_object_id';
5
+ import { type Resp, type TiRtcGalleryAsset } from './recording';
6
+ export declare const TISTORE_ERROR_OK: 0;
7
+ export declare const TISTORE_ERROR_INVALID_ARGUMENT: 6000;
8
+ export declare const TISTORE_ERROR_NOT_INITIALIZED: 6001;
9
+ export declare const TISTORE_ERROR_TOKEN_EXPIRED: 6014;
10
+ export declare const TISTORE_ERROR_ALREADY_INITIALIZED: 6022;
11
+ export declare const TISTORE_ERROR_PERMISSION_DENIED: 6024;
12
+ export declare const TISTORE_ERROR_IN_USE: 6026;
13
+ export declare const TISTORE_ERROR_NOT_STARTED: 6027;
14
+ export declare const TISTORE_ERROR_NOT_BOUND: 6029;
15
+ export declare const TISTORE_ERROR_NOT_CONFIGURED: 6030;
16
+ export declare const TISTORE_ERROR_RESOURCE_EXHAUSTED: 6043;
17
+ export declare const TISTORE_ERROR_FILE_WRITE_FAILED: 6046;
18
+ export declare const TISTORE_ERROR_UNSUPPORTED_FORMAT: 6113;
19
+ export declare const TISTORE_ERROR_IO_FAILED: 6114;
20
+ export declare const TISTORE_ERROR_CANCELLED: 6115;
21
+ export declare const TISTORE_ERROR_RANGE_TOO_LARGE: 6117;
22
+ export declare const TISTORE_ERROR_NO_FRAME: 6118;
23
+ export declare const TISTORE_ERROR_NO_RECORDABLE_MEDIA: 6119;
24
+ export declare const TISTORE_ERROR_RECORDING_OVERRUN: 6120;
25
+ export declare const TISTORE_ERROR_RECORDING_UNREADABLE: 6122;
26
+ export declare const TISTORE_ERROR_STORE_UNAVAILABLE: 6123;
27
+ export declare const TISTORE_ERROR_STOPPED: 6124;
28
+ export type TiStoreRecordingRange = Readonly<{
29
+ startTimeMs: number;
30
+ endTimeMs: number;
31
+ }>;
32
+ export type TiStoreRecordingRangesResult = Readonly<{
33
+ code: number;
34
+ recordings: ReadonlyArray<TiStoreRecordingRange>;
35
+ }>;
36
+ export type TiStoreRecordingDay = Readonly<{
37
+ date: string;
38
+ hasRecording: boolean;
39
+ }>;
40
+ export type TiStoreRecordingDaysResult = Readonly<{
41
+ code: number;
42
+ days: ReadonlyArray<TiStoreRecordingDay>;
43
+ }>;
44
+ export declare const TiStoreReplaySpeed: {
45
+ readonly x1: "x1";
46
+ readonly x2: "x2";
47
+ readonly x4: "x4";
48
+ readonly x8: "x8";
49
+ };
50
+ export type TiStoreReplaySpeed = (typeof TiStoreReplaySpeed)[keyof typeof TiStoreReplaySpeed];
51
+ export declare const TiStoreAudioOutputState: {
52
+ readonly idle: "idle";
53
+ readonly buffering: "buffering";
54
+ readonly playing: "playing";
55
+ readonly failed: "failed";
56
+ readonly paused: "paused";
57
+ readonly completed: "completed";
58
+ };
59
+ export type TiStoreAudioOutputState = (typeof TiStoreAudioOutputState)[keyof typeof TiStoreAudioOutputState];
60
+ export declare const TiStoreVideoOutputState: {
61
+ readonly idle: "idle";
62
+ readonly buffering: "buffering";
63
+ readonly rendering: "rendering";
64
+ readonly failed: "failed";
65
+ readonly paused: "paused";
66
+ readonly completed: "completed";
67
+ };
68
+ export type TiStoreVideoOutputState = (typeof TiStoreVideoOutputState)[keyof typeof TiStoreVideoOutputState];
69
+ export type TiStoreStartRecordingOptions = Readonly<{
70
+ videoChannelId: number;
71
+ audioChannelId?: number;
72
+ }>;
73
+ export type TiStoreExportOptions = Readonly<{
74
+ startTimeMs: number;
75
+ endTimeMs: number;
76
+ videoChannelId: number;
77
+ audioChannelId?: number;
78
+ }>;
79
+ export type TiStoreGalleryAsset = TiRtcGalleryAsset;
80
+ export interface TiStoreRecordingFile {
81
+ readonly path: string;
82
+ readonly durationMs: number;
83
+ moveToGallery(fileName?: string): Promise<Resp<TiStoreGalleryAsset>>;
84
+ delete(): Promise<number>;
85
+ }
86
+ export interface TiStoreSnapshotFile {
87
+ readonly path: string;
88
+ moveToGallery(fileName?: string): Promise<Resp<TiStoreGalleryAsset>>;
89
+ delete(): Promise<number>;
90
+ }
91
+ export declare class TiStore {
92
+ private token;
93
+ private identity;
94
+ private disposed;
95
+ onTokenExpired: (() => void) | null;
96
+ constructor(token: string);
97
+ static init(options: Readonly<{
98
+ appId: string;
99
+ endpoint?: string;
100
+ consoleLogEnabled?: boolean;
101
+ }>): Promise<number>;
102
+ static shutdown(): number;
103
+ static errorToString(code: number): string;
104
+ updateToken(token: string): number;
105
+ listRecordings(startTimeMs: number, endTimeMs: number): Promise<TiStoreRecordingRangesResult>;
106
+ listRecordingDays(startDate: string, endDate: string, timeZoneId?: string): Promise<TiStoreRecordingDaysResult>;
107
+ createReplay(): TiStoreReplay;
108
+ exportRecording(options: TiStoreExportOptions, onProgress?: (progress: number) => void): Resp<TiStoreExportTask>;
109
+ dispose(): number;
110
+ private ensureIdentity;
111
+ }
112
+ export declare class TiStoreReplay {
113
+ private readonly store;
114
+ private identity;
115
+ private disposed;
116
+ private currentSpeed;
117
+ private currentTime;
118
+ onTimeChanged: ((timeMs: number) => void) | null;
119
+ onError: ((code: number) => void) | null;
120
+ onCompleted: (() => void) | null;
121
+ constructor(store: TiStore);
122
+ get speed(): TiStoreReplaySpeed;
123
+ get currentTimeMs(): number | null;
124
+ play(startTimeMs: number, endTimeMs: number, initialTimeMs?: number): number;
125
+ pause(): number;
126
+ resume(): number;
127
+ seek(timeMs: number): number;
128
+ setSpeed(speed: TiStoreReplaySpeed): number;
129
+ startRecording(options: TiStoreStartRecordingOptions): Resp<TiStoreRecordingTask>;
130
+ stop(): number;
131
+ dispose(): number;
132
+ private command;
133
+ private ensureIdentity;
134
+ private handleEvent;
135
+ }
136
+ declare abstract class StoreOutputBase {
137
+ protected identity: NativeIdentity | null;
138
+ protected disposed: boolean;
139
+ protected bound: boolean;
140
+ protected abstract create(): ReturnType<typeof NativeTiRtc.storeCreateAudioOutput>;
141
+ protected ensureIdentity(): NativeIdentity | number;
142
+ protected abstract handleEvent(event: NativeTiRtcEvent): void;
143
+ protected releaseIdentity(): void;
144
+ }
145
+ export declare class TiStoreAudioOutput extends StoreOutputBase {
146
+ private currentState;
147
+ onStateChanged: ((state: TiStoreAudioOutputState) => void) | null;
148
+ onError: ((code: number) => void) | null;
149
+ protected create(): Readonly<{
150
+ code: number;
151
+ objectId: import("./specs/NativeTiRtc").NativeObjectId;
152
+ generation: number;
153
+ message: string | null;
154
+ }>;
155
+ get state(): TiStoreAudioOutputState;
156
+ attach(replay: TiStoreReplay, channelId: number): number;
157
+ setVolume(volumePercent: number): number;
158
+ detach(): number;
159
+ dispose(): number;
160
+ protected handleEvent(event: NativeTiRtcEvent): void;
161
+ }
162
+ export type TiStoreVideoOutputViewProps = ViewProps & Readonly<{
163
+ output: TiStoreVideoOutput;
164
+ resizeMode?: 'contain' | 'cover' | 'stretch';
165
+ }>;
166
+ export declare class TiStoreVideoOutput extends StoreOutputBase {
167
+ private currentState;
168
+ onStateChanged: ((state: TiStoreVideoOutputState) => void) | null;
169
+ onError: ((code: number) => void) | null;
170
+ protected create(): Readonly<{
171
+ code: number;
172
+ objectId: import("./specs/NativeTiRtc").NativeObjectId;
173
+ generation: number;
174
+ message: string | null;
175
+ }>;
176
+ get state(): TiStoreVideoOutputState;
177
+ view(props?: Omit<TiStoreVideoOutputViewProps, 'output'>): React.ReactElement;
178
+ attach(replay: TiStoreReplay, channelId: number): number;
179
+ takeSnapshot(): Promise<Resp<TiStoreSnapshotFile>>;
180
+ detach(): number;
181
+ dispose(): number;
182
+ protected handleEvent(event: NativeTiRtcEvent): void;
183
+ }
184
+ export declare function TiStoreVideoOutputView(props: TiStoreVideoOutputViewProps): React.ReactElement;
185
+ export declare class TiStoreRecordingTask {
186
+ private readonly taskId;
187
+ private readonly owner;
188
+ private stopPromise;
189
+ constructor(taskId: number, owner: TiStoreReplay);
190
+ stop(): Promise<Resp<TiStoreRecordingFile>>;
191
+ }
192
+ export declare class TiStoreExportTask {
193
+ private readonly taskId;
194
+ private readonly owner;
195
+ private readonly onProgress?;
196
+ private resultPromise;
197
+ constructor(taskId: number, owner: TiStore, onProgress?: ((progress: number) => void) | undefined);
198
+ get progress(): number;
199
+ get result(): Promise<Resp<TiStoreRecordingFile>>;
200
+ stop(): Promise<Resp<TiStoreRecordingFile>>;
201
+ }
202
+ export {};
@@ -33,6 +33,7 @@ export declare class TiRtcVideoInput {
33
33
  preview(props?: VideoInputPreviewPropsWithoutOwner): React.ReactElement;
34
34
  dispose(): Promise<number>;
35
35
  private enqueue;
36
+ private logged;
36
37
  private ensureIdentity;
37
38
  private adoptIdentity;
38
39
  private refreshActualConfig;
@@ -1,5 +1,6 @@
1
1
  import * as React from 'react';
2
2
  import { TiRtcConn } from './conn';
3
+ import { type Resp, type TiRtcSnapshotFile } from './recording';
3
4
  import type { TiRtcOnVideoOutputError, TiRtcOnVideoOutputRenderSizeChanged, TiRtcOnVideoOutputStateChanged, TiRtcSize, TiRtcVideoOutputDebugSnapshotResult, TiRtcVideoOutputMetricsResult, TiRtcVideoOutputOptions, TiRtcVideoOutputState, TiRtcVideoOutputViewProps } from './types';
4
5
  type VideoOutputViewPropsWithoutOwner = Omit<TiRtcVideoOutputViewProps, 'output'>;
5
6
  export declare class TiRtcVideoOutput {
@@ -8,10 +9,12 @@ export declare class TiRtcVideoOutput {
8
9
  private createCode;
9
10
  private currentState;
10
11
  private currentRenderSize;
12
+ private snapshotInFlight;
11
13
  private options;
12
14
  onStateChanged: TiRtcOnVideoOutputStateChanged | null;
13
15
  onRenderSizeChanged: TiRtcOnVideoOutputRenderSizeChanged | null;
14
16
  onError: TiRtcOnVideoOutputError | null;
17
+ takeSnapshot(): Promise<Resp<TiRtcSnapshotFile>>;
15
18
  constructor();
16
19
  get state(): TiRtcVideoOutputState;
17
20
  get renderSize(): TiRtcSize | null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tirtc-react-native",
3
- "version": "2.3.0",
3
+ "version": "2.4.0-alpha.3",
4
4
  "description": "TiRTC React Native SDK",
5
5
  "homepage": "https://tange.ai/",
6
6
  "repository": {
@@ -2,21 +2,17 @@ import {
2
2
  isPlainObject,
3
3
  isUInt8,
4
4
  normalizeCreateResult,
5
- returnReleasedIfDisposed,
5
+ returnNotInitializedIfDisposed,
6
6
  TIRTC_ERROR_INVALID_ARGUMENT,
7
7
  TIRTC_ERROR_OK,
8
- TIRTC_HOST_ERROR_OBJECT_RELEASED,
8
+ TIRTC_ERROR_NOT_INITIALIZED,
9
9
  } from './errors';
10
10
  import {registerNativeEventHandler, unregisterNativeEventHandler} from './events';
11
11
  import {clearNativeIdentity, readNativeIdentity, setNativeIdentity, type NativeIdentity} from './native_object_id';
12
12
  import {NativeTiRtc, type NativeTiRtcEvent} from './native';
13
+ import {logRtcOutcome, logRtcState} from './logging_internal';
13
14
  import {TiRtcConn} from './conn';
14
- import type {
15
- TiRtcAudioInputOptions,
16
- TiRtcInputState,
17
- TiRtcOnInputError,
18
- TiRtcOnInputStateChanged,
19
- } from './types';
15
+ import type {TiRtcAudioInputOptions, TiRtcInputState, TiRtcOnInputError, TiRtcOnInputStateChanged} from './types';
20
16
 
21
17
  export class TiRtcAudioInput {
22
18
  private identity: NativeIdentity | null = null;
@@ -40,8 +36,12 @@ export class TiRtcAudioInput {
40
36
  const result = normalizeCreateResult(NativeTiRtc.createAudioInput());
41
37
  this.createCode = result.code;
42
38
  if (result.code === TIRTC_ERROR_OK) {
43
- this.adoptIdentity({objectId: result.objectId, generation: result.generation});
39
+ this.adoptIdentity({
40
+ objectId: result.objectId,
41
+ generation: result.generation,
42
+ });
44
43
  }
44
+ logRtcOutcome('audio_input_create', result.code);
45
45
  }
46
46
 
47
47
  get state(): TiRtcInputState {
@@ -87,32 +87,41 @@ export class TiRtcAudioInput {
87
87
  if (connIdentity === null) {
88
88
  return Promise.resolve(TIRTC_ERROR_INVALID_ARGUMENT);
89
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
- });
90
+ return this.logged(
91
+ 'audio_input_attach',
92
+ this.enqueue(async () => {
93
+ const identity = this.ensureIdentity();
94
+ if (typeof identity === 'number') {
95
+ return identity;
96
+ }
97
+ return NativeTiRtc.audioInputAttach(identity.objectId, connIdentity.objectId, streamId);
98
+ }),
99
+ );
97
100
  }
98
101
 
99
102
  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
- });
103
+ return this.logged(
104
+ 'audio_input_start',
105
+ this.enqueue(async () => {
106
+ const identity = this.ensureIdentity();
107
+ if (typeof identity === 'number') {
108
+ return identity;
109
+ }
110
+ return NativeTiRtc.audioInputStart(identity.objectId);
111
+ }),
112
+ );
107
113
  }
108
114
 
109
115
  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
+ return this.logged(
117
+ 'audio_input_stop',
118
+ this.enqueue(async () => {
119
+ if (this.identity === null) {
120
+ return TIRTC_ERROR_OK;
121
+ }
122
+ return NativeTiRtc.audioInputStop(this.identity.objectId);
123
+ }),
124
+ );
116
125
  }
117
126
 
118
127
  detach(connection: TiRtcConn): Promise<number> {
@@ -120,47 +129,53 @@ export class TiRtcAudioInput {
120
129
  if (connIdentity === null) {
121
130
  return Promise.resolve(TIRTC_ERROR_INVALID_ARGUMENT);
122
131
  }
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
- });
132
+ return this.logged(
133
+ 'audio_input_detach',
134
+ this.enqueue(async () => {
135
+ if (this.identity === null) {
136
+ return TIRTC_ERROR_OK;
137
+ }
138
+ return NativeTiRtc.audioInputDetach(this.identity.objectId, connIdentity.objectId);
139
+ }),
140
+ );
129
141
  }
130
142
 
131
143
  dispose(): Promise<number> {
132
144
  if (this.disposed) {
133
145
  return Promise.resolve(TIRTC_ERROR_OK);
134
146
  }
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);
147
+ return this.logged(
148
+ 'audio_input_dispose',
149
+ this.enqueue(async () => {
150
+ if (this.identity === null) {
151
+ this.disposed = true;
152
+ this.clearCallbacks();
153
+ this.currentState = 'stopped';
154
+ return TIRTC_ERROR_OK;
155
+ }
156
+ const identity = this.identity;
157
+ const code = await NativeTiRtc.audioInputDispose(identity.objectId);
158
+ if (code === TIRTC_ERROR_OK) {
159
+ this.disposed = true;
160
+ this.identity = null;
161
+ unregisterNativeEventHandler(identity);
162
+ clearNativeIdentity(this);
163
+ this.clearCallbacks();
164
+ this.currentState = 'stopped';
165
+ }
166
+ return code;
167
+ }, true),
168
+ );
154
169
  }
155
170
 
156
171
  private enqueue(operation: () => Promise<number>, allowDisposed = false): Promise<number> {
157
- const released = returnReleasedIfDisposed(this.disposed);
172
+ const released = returnNotInitializedIfDisposed(this.disposed);
158
173
  if (released !== null && !allowDisposed) {
159
174
  return Promise.resolve(released);
160
175
  }
161
176
  const next = this.queue.then(async () => {
162
177
  if (this.disposed && !allowDisposed) {
163
- return TIRTC_HOST_ERROR_OBJECT_RELEASED;
178
+ return TIRTC_ERROR_NOT_INITIALIZED;
164
179
  }
165
180
  return operation();
166
181
  });
@@ -168,8 +183,15 @@ export class TiRtcAudioInput {
168
183
  return next;
169
184
  }
170
185
 
186
+ private logged(operation: string, result: Promise<number>): Promise<number> {
187
+ return result.then((code) => {
188
+ logRtcOutcome(operation, code);
189
+ return code;
190
+ });
191
+ }
192
+
171
193
  private ensureIdentity(): NativeIdentity | number {
172
- const released = returnReleasedIfDisposed(this.disposed);
194
+ const released = returnNotInitializedIfDisposed(this.disposed);
173
195
  if (released !== null) {
174
196
  return released;
175
197
  }
@@ -196,10 +218,14 @@ export class TiRtcAudioInput {
196
218
  return;
197
219
  }
198
220
  if (event.type === 'audioInputStateChanged' && event.state !== undefined) {
199
- this.currentState = event.state as TiRtcInputState;
221
+ const nextState = event.state as TiRtcInputState;
222
+ if (this.currentState !== nextState) logRtcState('audio_input_state', nextState);
223
+ this.currentState = nextState;
200
224
  this.onStateChanged?.(this.currentState);
201
225
  } else if (event.type === 'audioInputError') {
202
- this.onError?.(event.code ?? TIRTC_ERROR_INVALID_ARGUMENT, event.message ?? null);
226
+ const code = event.code ?? TIRTC_ERROR_INVALID_ARGUMENT;
227
+ logRtcOutcome('audio_input', code);
228
+ this.onError?.(code, event.message ?? null);
203
229
  }
204
230
  }
205
231
  }