Skip to content

Flutter API Reference

This page describes the public Dart API of the Flutter plugin tirtc_av_kit for Android, iOS, macOS, and OpenHarmony / HarmonyOS NEXT client apps.

If you have not added the package, configured the native projects, or prepared the connection flow, start with Client Integration. Terms such as AppId, remote_id, token, and stream_id follow the glossary.

Object Overview

ObjectPurposeCleanup
TiRtcInitOptionsHolds SDK initialization optionsNo explicit cleanup
TiRtcInitializes and shuts down the SDK environment; formats error codesTiRtc.shutdown()
TiRtcConnConnects, disconnects, sends commands and stream messages, requests key frames, and controls manual media subscriptiondispose()
TiRtcAudioOutputOptionsHolds audio output optionsNo explicit cleanup
TiRtcAudioOutputPlays one remote audio stream and reads diagnostic snapshotsdispose()
TiRtcVideoOutputOptionsHolds video decoding optionsNo explicit cleanup
TiRtcVideoOutputPlays one remote video stream, creates the Flutter render widget, and reads diagnostic snapshotsdispose()
TiRtcLoggingWrites and uploads SDK logsNone

TiRtcInitOptions

FieldDescription
appIdYour AppId. Default is an empty string.
endpointCustom service endpoint. Leave it empty to use the SDK default.
consoleLogEnabledWhether to mirror SDK logs to the host console. Default is false.

TiRtc

Typical order: initialize() -> create connection and output objects -> dispose() those objects -> shutdown().

APIDescription
initialize(TiRtcInitOptions config): Future<int>Initializes the SDK environment. Returns 0 on success or an error code on failure. Create and use TiRtcConn, TiRtcAudioOutput, and TiRtcVideoOutput only after initialization succeeds.
shutdown(): intShuts down the SDK environment. Dispose every TiRtcConn, TiRtcAudioOutput, and TiRtcVideoOutput first; otherwise this returns an error code and does not force-release those objects.
errorToString(int code): StringConverts an error code to a stable error identifier string.
formatError(int code): StringFormats an error code for logs or UI, for example error XXX (1234).

TiRtcConn

All streamId parameters in this section use the public stream_id range 0..15.

States

StateMeaning
TiRtcConnState.idleThe connection object exists but has not started connecting.
TiRtcConnState.connectingThe connection request has been submitted.
TiRtcConnState.connectedThe connection is established. You can send messages and bind outputs.
TiRtcConnState.disconnectedThe connection is disconnected. The object still needs dispose().

Properties and Callbacks

MemberDescription
stateCurrent connection state
onStateChangedvoid Function(TiRtcConnState state, int errorCode)
onCommandvoid Function(int commandId, Uint8List data)
onStreamMessagevoid Function(int streamId, int timestampMs, Uint8List data)

Methods

APIDescription
TiRtcConn()Creates a connection object. Call it only after TiRtc.initialize(...) succeeds. It does not connect by itself.
connect({required String remoteId, required String token}): intStarts connecting to the target remote_id. Both parameters must be non-empty strings. A 0 return value only means the request was submitted; use onStateChanged for the final connection result.
disconnect(): intDisconnects the current connection without releasing the object. The same instance can connect again after success.
dispose(): voidReleases the connection object. Do not use the instance again after calling it.
sendCommand({required int commandId, required Uint8List data}): intSends an application command over the command channel.
sendStreamMessage({required int streamId, required int timestampMs, required Uint8List data}): intSends a stream message. Both sides should agree on the streamId and message meaning first.
subscribeVideo({required int streamId}): intRequests the remote side to start sending a video stream. It does not create local playback.
unsubscribeVideo({required int streamId}): intCancels a manual video subscription. It is not the same as TiRtcVideoOutput.detach().
subscribeAudio({required int streamId}): intRequests the remote side to start sending an audio stream. It does not create local playback.
unsubscribeAudio({required int streamId}): intCancels a manual audio subscription. It is not the same as TiRtcAudioOutput.detach().
requestKeyFrame({required int streamId}): intRequests a key frame for a remote video stream.

TiRtcAudioOutputOptions

FieldDescription
volumePercentLinear volume percentage. Default is 100.
agcLevelAutomatic gain control (AGC) level. Default is 0.
ansLevelAutomatic noise suppression (ANS) level. Default is 0.

TiRtcAudioOutput

APIDescription
TiRtcAudioOutput()Creates an audio output object. Call it only after TiRtc.initialize(...) succeeds.
attach({required TiRtcConn connection, required int streamId}): intBinds this output to one remote audio stream on the connection. If the remote side sends media only after subscription, also call TiRtcConn.subscribeAudio().
detach(): intRemoves the current audio binding without releasing the object. The same audio output object can be reused.
configure(TiRtcAudioOutputOptions options): intConfigures audio output options before attach(). Already-bound audio outputs do not support dynamic option updates.
dispose(): voidReleases the audio output. Do not use the instance again after calling it.
getDebugSnapshot(): ({int code, TiRtcAudioOutputDebugSnapshot? snapshot})Reads an audio diagnostic snapshot.

TiRtcVideoOutputOptions

Video decoding options for TiRtcVideoOutput.setOptions(...). Normal playback does not need this. Use it only when you need to request software or hardware decoding.

FieldDescription
decoderPreferenceVideo decoder preference. Default is 0. 0 means auto, 1 requests software decoding, and 2 requests hardware decoding.

decoderPreference is a request, not a guarantee. The actual decoder depends on device, OS, codec, and platform capability.

TiRtcVideoOutput

APIDescription
TiRtcVideoOutput()Creates a video output object. Call it only after TiRtc.initialize(...) succeeds.
setOptions(TiRtcVideoOutputOptions options): intSets video decoding options. Call before attach() when needed. Normal playback does not need this.
attach({required TiRtcConn connection, required int streamId}): intBinds this output to one remote video stream on the connection. If the remote side sends media only after subscription, also call TiRtcConn.subscribeVideo().
detach(): intRemoves the current video binding without releasing the object. The same video output object can be reused.
view(): WidgetReturns the Flutter render widget for this video output. One TiRtcVideoOutput supports only one mounted view() at a time. The widget stays as a placeholder before binding completes or when no frame is available.
dispose(): voidReleases the video output and related system resources. Do not use the instance again after calling it.
getDebugSnapshot(): ({int code, TiRtcVideoOutputDebugSnapshot? snapshot})Reads a video diagnostic snapshot.

Diagnostic Snapshot Types

Diagnostic snapshots read the SDK's currently known codec, resolution, and decoder information. They are query APIs. They do not change playback state and do not trigger onError.

TiRtcAudioOutputDebugSnapshot

FieldDescription
codecCurrent audio codec. 0 means the SDK has not obtained this information yet.

TiRtcVideoOutputDebugSnapshot

FieldDescription
codecCurrent video codec. 0 means the SDK has not obtained this information yet.
bitstreamFormatCurrent video bitstream format. 0 means the SDK has not obtained this information yet.
widthLast known video width. 0 means the SDK has not obtained this information yet.
heightLast known video height. 0 means the SDK has not obtained this information yet.
decoderPreferenceRequested decoder preference
resolvedDecoderBackendLocked actual decoder type. 0 means unknown, 1 means software decoding, and 2 means hardware decoding.

Common Misuse

  • Creating or using objects before await TiRtc.initialize(...).
  • Treating connect(...) == 0 as already connected.
  • Treating disconnect() or detach() as object release. Call dispose() when the object is no longer needed.
  • Calling configure(...) on an audio output after attach() and expecting dynamic option updates.
  • Treating TiRtcVideoOutputOptions.decoderPreference as required. Normal playback uses auto.
  • Treating decoderPreference as the actual decoder result. Use TiRtcVideoOutputDebugSnapshot.resolvedDecoderBackend when you need the actual backend.
  • Using playing as the video state name. The Flutter public state is TiRtcVideoOutputState.rendering.
  • Mounting multiple view() widgets from the same TiRtcVideoOutput at the same time.
  • Calling TiRtc.shutdown() while connection or output objects have not been disposed.

TiRTC