tirtc-react-native
v2.4.2
Published
TiRTC React Native SDK
Maintainers
Readme
TiRTC React Native SDK
tirtc-react-native is the TiRTC and Ti Cloud Storage React Native New Architecture package for Android and iOS.
npm install tirtc-react-nativeThe package ships ESM JavaScript, TypeScript declarations, Codegen specs, Android native wrapper code and iOS native wrapper code. RTC and CloudStorage use the same native Runtime delivery but keep separate initialization and resource lifecycles. The package requires React Native >=0.80.0, Android com.tange.ai:tirtc:2.4.2, and iOS TiRTC 2.4.2 with iOS minimum 15.1.
The iOS package supports arm64 devices and Apple Silicon iOS Simulator. Simulator validation covers build, launch, connection, downlink audio, and downlink video; capture and iOS behavioral qualification remain real-device gates.
Version 2.4.2 is the stable React Native release aligned with the TiRTC 2.4.2 Android and Darwin SDKs.
Imports
import {
TiRtc,
TiRtcConn,
TiRtcAudioInput,
TiRtcVideoInput,
TiRtcAudioOutput,
TiRtcVideoOutput,
TiRtcVideoOutputView,
TiRtcVideoInputPreview,
TiRtcAudioCodec,
TiRtcVideoCodec,
} from 'tirtc-react-native';
import * as TiRtc from 'tirtc-react-native';The root export is the public API. Deep imports are not supported.
Semantic Values
String values are exported as stable as const objects and matching TypeScript union types:
TiRtcOutputBufferStrategy, TiRtcConnState, TiRtcInputState, TiRtcAudioCodec, TiRtcAudioSampleRate, TiRtcAudioChannelCount, TiRtcAudioAecMode, TiRtcAudioAgcLevel, TiRtcAudioAnsLevel, TiRtcVideoCodec, TiRtcVideoEncoderCodec, TiRtcVideoFrameRate, TiRtcCameraFacing, TiRtcVideoDecoderPreference, TiRtcVideoDecoderBackend, TiRtcVideoBitstreamFormat, TiRtcAudioOutputState, TiRtcVideoOutputState.
Use the exported values instead of hard-coded strings in app code.
Permissions
Applications own runtime permissions and platform entitlement setup before starting capture or output:
- Android: camera, microphone, network and foreground execution policy required by the host app.
- iOS: camera and microphone usage descriptions, user permission prompts and background behavior required by the host app.
The SDK reports platform failures through numeric TiRTC return codes and callbacks; it does not request permissions on the app's behalf.
Minimal Client
import React from 'react';
import {TiRtc, TiRtcConn, TiRtcVideoOutput, TiRtcVideoOutputView} from 'tirtc-react-native';
await TiRtc.init({appId, endpoint});
const conn = new TiRtcConn();
const videoOutput = new TiRtcVideoOutput();
videoOutput.attach(conn, streamId);
conn.onStateChanged = (state, errorCode) => {
if (errorCode !== 0) {
console.warn(TiRtc.formatError(errorCode));
}
};
conn.connect(remoteDeviceId, token);
export function RemoteVideo() {
return <TiRtcVideoOutputView output={videoOutput} resizeMode="contain" />;
}TiRtc.initialize(...) remains available as a deprecated forwarding alias to TiRtc.init(...).
Dispose in reverse ownership order:
videoOutput.detach();
videoOutput.dispose();
conn.disconnect();
conn.dispose();
TiRtc.shutdown();Client Voice Talkback
import {TiRtcAudioCodec, TiRtcAudioInput} from 'tirtc-react-native';
const audioInput = new TiRtcAudioInput();
await audioInput.setOptions({
codec: TiRtcAudioCodec.g711a,
});
await audioInput.attach(conn, talkbackStreamId);
await audioInput.start();
await audioInput.stop();
await audioInput.detach(conn);
await audioInput.dispose();Client Video Uplink Primitives
TiRtcVideoInput, TiRtcVideoInputPreview and the video input option values are exported for client-side video uplink integration.
import {TiRtcVideoInput, TiRtcVideoInputPreview} from 'tirtc-react-native';
const videoInput = new TiRtcVideoInput();
export function LocalPreview() {
return <TiRtcVideoInputPreview input={videoInput} resizeMode="contain" />;
}Saving Temporary Media
RTC recordings, RTC snapshots, CloudStorage recordings, and CloudStorage snapshots return temporary cache file objects. Publish one to the Android or iOS system media library with an optional final filename:
const result = await file.moveToGallery(
'客厅角落摄像头-2026-08-20-14-30-05-123.mp4',
);The package does not declare or request gallery permissions. The application must prepare Android or iOS authorization before calling this method. Omit the filename to use an epoch-millisecond name; a missing .mp4 or .jpg extension is appended automatically. Invalid names resolve with code 6000 without invoking the native module or deleting the cache source. A successful move deletes the source and returns an opaque content:// or ph:// URI; a failed move keeps the source available for retry.
Errors And Lifecycle
Public methods return numeric TiRTC codes instead of throwing for SDK failures. 0 means success. Use TiRtc.errorToString(code) or TiRtc.formatError(code) for display and logs.
Constructors create native owner identities, so outputs and inputs can attach to a TiRtcConn before connect(...). dispose() releases the native object only after the underlying stop/destroy call returns success. Calling dispose() again after success is valid and returns success; methods called after a successful dispose return the not-initialized code. Input/output/view ownership is tracked by native object id plus generation so stale callbacks or recycled ids do not attach to a newer object.
Release
Version 2.4.2 is the current stable React Native package for TiRTC and Ti Cloud Storage. It supports React Native New Architecture apps on Android and iOS and pins Android com.tange.ai:tirtc:2.4.2 and iOS TiRTC 2.4.2.
License
This npm package is licensed as BSD-3-Clause. The BSD-3-Clause license covers the React Native wrapper/source distributed in this package. Native TiRTC runtime binaries consumed by the Android and iOS dependencies are governed by their own distributed terms.
Package Validation
npm run lint
npm test
npm run typecheck
npm run build
npm run codegen:checkThe external application sample is published under react-native/ in
tirtc-api-samples. The owner-local projection and recovery entry is:
./scripts/publish_api_samples.sh --version 2.4.2Use --no-push for a complete local projection/build rehearsal without writing
the public repository.
