tirtc-av-react-native
v2.2.0
Published
TiRTC AV React Native SDK
Maintainers
Readme
TiRTC AV React Native SDK
tirtc-av-react-native is the TiRTC AV React Native New Architecture package for Android and iOS.
npm install tirtc-av-react-nativeThe package ships ESM JavaScript, TypeScript declarations, Codegen specs, Android native wrapper code and iOS native wrapper code. It requires React Native >=0.80.0, Android com.tange.ai:tirtc-av:2.2.8, and iOS TiRTC_AV 2.2.8 with iOS minimum 15.1.
Version 2.2.0 is a stable React Native release focused on client media output, client voice talkback and client video uplink primitives.
Imports
import {
TiRtc,
TiRtcConn,
TiRtcAudioInput,
TiRtcVideoInput,
TiRtcAudioOutput,
TiRtcVideoOutput,
TiRtcVideoOutputView,
TiRtcVideoInputPreview,
TiRtcAudioCodec,
TiRtcVideoCodec,
} from 'tirtc-av-react-native';
import * as TiRtcAv from 'tirtc-av-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, TiRtcVideoFrameRate, TiRtcCameraFacing, TiRtcVideoEncoderPreference, 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-av-react-native';
await TiRtc.initialize({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" />;
}Dispose in reverse ownership order:
videoOutput.detach();
videoOutput.dispose();
conn.disconnect();
conn.dispose();
TiRtc.shutdown();Client Voice Talkback
import {TiRtcAudioCodec, TiRtcAudioInput} from 'tirtc-av-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-av-react-native';
const videoInput = new TiRtcVideoInput();
export function LocalPreview() {
return <TiRtcVideoInputPreview input={videoInput} resizeMode="contain" />;
}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 object released 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.2.0 is the stable React Native package for TiRTC AV client media output and talkback. It supports React Native New Architecture apps on Android and iOS and ships with Android com.tange.ai:tirtc-av:2.2.8 and iOS TiRTC_AV 2.2.8.
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:check