titli_video_sdk 0.2.0
titli_video_sdk: ^0.2.0 copied to clipboard
Titli Video SDK for Flutter. Metered 1:1 audio and video calls, Live Hosts, live stream viewing and gifts in your app.
Titli Video SDK for Flutter #
Metered audio and video calls, Live Hosts, Live Streams and gifts in your Flutter app. Android first; the package also
builds for web (the example runs in Chrome). iOS works through livekit_client but is not yet tested by us.
Two ways to use it:
- Quick mode (start here): only the publishable App Key from the console. No backend.
TitliVideo.init(appKey: ..., userId: ...), thenTitliVideo.startCall()/TitliVideo.joinCall(callId). - Secure mode (Production hardening): your backend holds the API key
secret and mints a token per participant; the app joins with
TitliCall.connect(url, token).
Billing happens on our servers from the media server's own join and leave events. Nothing the app reports changes what is billed.
Install #
flutter pub add titli_video_sdk
or in pubspec.yaml:
dependencies:
titli_video_sdk: ^0.2.0
The one dependency, livekit_client (2.13 or newer, below 3), comes from pub.dev too. Requires Flutter 3.19 / Dart
3.3 or newer. If your build cannot reach pub.dev, the same package is in the console under SDK downloads: add
that folder as a path dependency (titli_video_sdk: { path: vendor/titli_video_sdk }).
Android setup #
android/app/src/main/AndroidManifest.xml:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.BLUETOOTH" android:maxSdkVersion="30" />
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
minSdkVersionmust be 21 or higher (android/app/build.gradle).- Ask for camera and microphone permission at runtime before joining (for example with
permission_handler). The prebuilt screen does not ask for you. If the permission is missing,connectstill succeeds and the call runs with that device off (the reason is only printed to the debug log). - Java 17 / Kotlin as required by
livekit_client2.x.
iOS setup (not yet tested by us) #
ios/Runner/Info.plist needs NSMicrophoneUsageDescription and NSCameraUsageDescription (iOS ends the app if it
asks without them), and UIBackgroundModes → audio to keep the call's sound running in the background. For iPhone
apps we recommend the native iOS SDK or the React Native SDK, which we do test.
Quick mode: add your App Key, make a call in 5 minutes #
- In the console open Projects → Quick mode, switch it on, copy the App Key (
tak_…) and add your app to the key's allowlist: the Android package name (and, if you like, the signing certificate SHA-256), the iOS bundle ID, and for web the origin your page is served from (https://app.example.com, orhttp://localhost:8080while you develop). - Init once, after your own sign-in, with your app's id of the user:
import 'package:titli_video_sdk/titli_video_sdk.dart';
await TitliVideo.init(appKey: 'tak_…', userId: 'user-42', userName: 'Asha');
// DEV: TitliVideo.init(..., apiBase: 'https://dev-api-videosdk.titliapp.com')
- Start a call on one phone, join it on the other:
// Caller (role "user", the payer):
final call = await TitliVideo.startCall(type: TitliCallType.video);
sendToTheOtherPerson(call.callId!); // your own way: push, your chat, or Titli Chat call invites
// The other person:
final call = await TitliVideo.joinCall(callId); // role: TitliRole.user by default, or TitliRole.host
await Navigator.of(context).push(MaterialPageRoute(builder: (_) => TitliCallScreen(call: call, title: 'Asha')));
Ask for camera and microphone permission before startCall / joinCall (see Android setup). startCall and
joinCall return the same TitliCall as TitliCall.connect, plus its callId. TitliVideo.setUser(userId, userName)
switches the signed-in user.
Everything else from the app #
| Namespace | Methods |
|---|---|
TitliVideo.calls |
create, token, get, end, list (own calls), removeParticipant, muteParticipant (the creator only) |
TitliVideo.liveHosts |
hosts(q:), host(ref), directHosts, startCall(hostRef:, type:, listing:) (create + connect), create, get, end, list, sendGift(callId, giftId, count:) |
TitliVideo.liveStreams |
list, watch(ref) (join + connect as a viewer), join, token(ref), leave(ref), comments(ref), comment(ref, text), sendGift(ref, giftId, count:), report(ref, reason), gifts() |
TitliVideo.gifts |
list(), history(), get(id) |
TitliVideo.config() |
What the project allows: features, Quick-mode limits (max_call_seconds, user_minutes_left_today), products |
Methods that do not connect return the API's JSON answer as a Map<String, dynamic> (same fields as the matching
/v1 route in REST API reference, without the money fields that are only for your server). liveHosts.startCall and
liveStreams.watch return a connected TitliCall whose gift sheet works with no send handler: the SDK loads the gift
list and sends each gift with its own client_request_id. Leaving a Live Hosts call ends it; leaving a live closes the
viewing session.
final call = await TitliVideo.liveStreams.watch(streamRef);
Navigator.push(context, MaterialPageRoute(builder: (_) => TitliCallScreen(call: call)));
Errors in Quick mode #
Every Quick-mode method throws TitliVideoError (gift sends throw TitliGiftError, as in Secure mode). Show
userMessage to your user as is (userMessageFor('hi') for Hindi); log message; errorCode is stable.
errorCode |
userCode |
HTTP | When |
|---|---|---|---|
APP_KEY_INVALID |
AK-401 |
401 | The key is missing, wrong, rotated away or disabled |
QUICK_MODE_OFF |
QM-403 |
403 | Quick mode is switched off for the project, or paused |
APP_NOT_ALLOWED |
AB-403 |
403 | The package name / bundle ID / web origin / signing certificate is not on the key's allowlist |
QUICK_DAILY_CAP_REACHED |
QC-402 |
402 | The project's Quick-mode daily spend cap is reached |
END_USER_DAILY_LIMIT |
UM-429 |
429 | This user used today's minutes (also the end reason when a call is cut) |
FORBIDDEN |
FB-403 |
403 | Acting as another user, or on a call the user is not in |
RATE_LIMITED |
RL-429 |
429 | Too many requests from this network or device |
NETWORK_ERROR |
No answer (offline; on web also a blocked cross-origin request) | ||
NOT_INITIALIZED, INVALID_USER_ID |
Raised on the device: call init first; user ids are 1 to 128 of A-Z a-z 0-9 _ . : @ - |
The SDK repeats a 429 after Retry-After (up to 30 s) and a 5xx or a missing answer after 1 s, 2 s and 4 s. Any
other 4xx is never repeated.
What the SDK sends #
Every request carries X-Titli-App-Key, X-Titli-User, X-Titli-Platform (android, ios or web),
X-Titli-Device (a random id per install), X-Titli-SDK (flutter/0.2.0), and on Android and iOS X-Titli-App
(the package name / bundle ID). On Android it also sends X-Titli-App-Cert (SHA-256 of the signing certificate). On
web there is no X-Titli-App: the browser sends the page's Origin. Never an Authorization header. The device id is
kept in localStorage on web and in a small file in the app's private storage on Android and iOS (in memory when that
is not possible); pass deviceId: to init to use your own.
How safe is the App Key? #
The App Key is publishable, not a secret: it ships inside your app and anyone can read it. It can only reach the
/v1/client/* routes, every request acts as one user of your app, and the key is bound to your package name / bundle
ID / web origin. That binding is a deterrent, not a lock: a determined person can copy those values. What limits the
damage are the caps you set in the console (the Quick-mode daily spend cap, the per-user daily minutes and the
maximum call length) and the per-device rate limits. If you need strict control over who may call and how much, use
Secure mode below: your backend checks your own sign-in and mints each token.
Production hardening (optional): Secure mode #
How it fits together
- Your backend holds the project API key (
key_id+key_secret) from the Titli Video SDK console. - When a user starts a call, your backend calls the REST API:
POST /v1/callscreates the call, andPOST /v1/calls/{call_id}/tokensmints one token per participant.
- Your backend sends the
tokenandlivekit_urlto the app. - The app joins with
TitliCall.connect(...).
Never put the key secret in the app. Anyone who unpacks the APK can read it. A server-minted token also works after
TitliVideo.init: Quick mode and Secure mode can live in the same app.
Secure mode quickstart #
import 'package:permission_handler/permission_handler.dart';
import 'package:titli_video_sdk/titli_video_sdk.dart';
// Ask before joining. For an audio call, request only the microphone.
final granted = await [Permission.camera, Permission.microphone].request();
if (granted.values.any((s) => !s.isGranted)) return; // explain and stop
// `token` and `livekitUrl` come from YOUR backend (see above).
final call = await TitliCall.connect(
url: livekitUrl,
token: token,
video: true, // false for audio calls
);
await Navigator.of(context).push(MaterialPageRoute(
builder: (_) => TitliCallScreen(
call: call,
title: 'Asha',
onEnded: (reason) {
// reason == TitliCallEndReason.endedByServer when your backend ended the call,
// the account balance reached zero, or the call hit its time limit.
},
),
));
Build your own UI #
TitliCall exposes ValueNotifiers you can listen to:
| Property | Type | Meaning |
|---|---|---|
state |
TitliCallState |
connecting, connected, reconnecting, ended |
participants |
List<TitliParticipant> |
The other people in the call, with identity, name, isHost, microphoneEnabled, videoTrack |
microphoneEnabled, cameraEnabled |
bool |
This device's media |
localVideoTrack |
VideoTrack? |
Self view |
duration |
Duration |
Time since the other person joined. Display only |
endReason |
TitliCallEndReason? |
Set when the call ends |
Actions: toggleMicrophone(), setMicrophoneEnabled(bool), toggleCamera(), setCameraEnabled(bool), switchCamera(), hangUp(), dispose().
Render video with VideoTrackRenderer(track) (re-exported).
End reasons #
| Reason | When |
|---|---|
hungUp |
This device called hangUp() |
endedByServer |
Your backend called POST /v1/calls/{id}/end, the balance reached zero, the call reached its maximum duration, or an operator ended it |
removed |
Your backend removed this participant |
joinedElsewhere |
The same end_user_id joined from another device |
connectionLost |
The network dropped and did not recover |
failedToConnect |
The token was invalid or expired, or there was no network |
Audio calls #
Tokens for type: "audio" calls can publish only the microphone. Pass video: false to connect; the prebuilt screen then shows an avatar layout without camera buttons. The package does not read the call type from the token, so your backend should return type with the token and the app should pass video: type == 'video'. With video: false, setCameraEnabled(true) throws a StateError.
Errors and limits #
| What you see | Why | What to do |
|---|---|---|
connect throws |
The token is invalid or expired, or there is no network. The package does not check the expiry first; the exception is the underlying livekit_client one |
Catch it, ask your backend for a new token and try again. Tokens can be used to join for 10 minutes by default (ttl_seconds, 30 to 3600), so mint them right before joining |
| Joined, but the other side cannot hear or see this device | Camera or microphone permission is missing | Ask for the permissions before connect (see Quickstart) |
| Camera stays off in an audio call | Audio-call tokens cannot publish a camera | Pass video: false; create a "type": "video" call for video |
endReason is endedByServer |
Your backend ended the call, the balance reached zero, the maximum duration was reached, or an operator ended it | Close the screen. The exact reason is end_reason in the call.ended webhook and GET /v1/calls/{id}; this package has no serverReason |
endReason is connectionLost |
The network dropped and did not recover | Offer to call again; the call stays open for 30 s after everyone has left |
Compared with the native SDKs (SDK overview) this package is smaller: the camera is captured at 540p (there is
no quality setting and the token's max_video_resolution is not read), there are no event callbacks other than the
ValueNotifiers and live events, no loudspeaker/earpiece switch, and no incoming-call helpers.
Always call call.dispose() when your own call UI is gone (TitliCallScreen does it for you unless you pass
disposeCallOnClose: false).
Example #
example/ runs in Quick mode by default and has a Secure mode tab (a token from your backend URL, or pasted).
It builds for Android (run flutter create --platforms=android . inside it once, then add the manifest permissions
above) and for web:
cd example
flutter run -d chrome --web-port 8080 \
--dart-define=TITLI_APP_KEY=tak_... \
--dart-define=TITLI_USER_ID=user-42 \
--dart-define=TITLI_API_BASE=https://dev-api-videosdk.titliapp.com
# second window / device: the same plus --dart-define=TITLI_CALL_ID=<the id the first one shows>
With an App Key and a user id it starts at once: it joins TITLI_CALL_ID when given, else starts a call and shows
Call ID: <id>. Optional: TITLI_USER_NAME, TITLI_AUDIO=true (audio call). Without them it shows a form. On web
the query string overrides each value, so one build serves both sides: open /?user_id=user-43&call_id=<id> in the
second window (also app_key, api_base, user_name, audio=1). For web, add the page's origin (here
http://localhost:8080) to the App Key's allowlist.
API reference #
The REST API, webhooks and signed receipts are documented in REST API reference.
Live Hosts #
The same join works for Live Hosts calls (your users calling Titli hosts): your server calls
POST /v1/live-hosts/calls and returns livekit_url and token; join with TitliCall.connect(url: livekitUrl, token: token, video: true).
No SDK change is needed. See Live Hosts docs. To let users send gifts in the call, see
Gifts. In Quick mode use TitliVideo.liveHosts.startCall(...) instead: no server at all.
Gifts #
Your users can send gifts to a Titli host during a Live Hosts call or while watching a live stream. In Quick mode
(TitliVideo.liveHosts.startCall, TitliVideo.liveStreams.watch) the gift sheet works on its own: nothing below is
needed. In Secure mode the app never holds the API key, so gifts go through your backend: it lists the gifts and sends them; the app shows the list and
asks your backend to send. Full reference: Gifts docs.
1. Your backend (Node 20+) #
const API = 'https://api-videosdk.titliapp.com';
const AUTH = 'Basic ' + Buffer.from(`${process.env.TITLI_KEY_ID}:${process.env.TITLI_KEY_SECRET}`).toString('base64');
const titli = async (method, path, body) => {
const r = await fetch(API + path, { method, headers: { Authorization: AUTH, 'Content-Type': 'application/json' }, body: body && JSON.stringify(body) });
return { status: r.status, body: await r.json().catch(() => ({})) };
};
// The gift list for the app. Keep only what your user needs: never send cost or you_keep to the app.
app.get('/gifts', async (req, res) => {
const { body } = await titli('GET', '/v1/gifts');
res.json({ enabled: body.enabled, version: body.version, currency: body.currency, max_count: body.max_count,
gifts: (body.gifts || []).map(({ gift_id, name, icon_url, animation_url, category, price, currency, hidden }) =>
({ gift_id, name, icon_url, animation_url, category, price, currency, hidden })) });
});
// Send a gift in a Live Hosts call. For a live stream: POST /v1/live-streams/:stream_ref/gifts with end_user_id added.
// Refusals before anything was debited. gift_idempotency_conflict is NOT one of them: that ID belongs to an earlier
// gift, which stands. Never refund on it.
const REFUSED = new Set(['gifts_disabled', 'gift_unavailable', 'gift_price_changed', 'gift_host_unavailable',
'gift_not_in_session', 'insufficient_balance', 'invalid_request']);
app.post('/calls/:callId/gifts', async (req, res) => {
const { gift_id, count = 1, client_request_id } = req.body;
// 1. Check the call is this user's. Take the price from YOUR current gift list (not from the app), charge YOUR
// user that amount in your own wallet and send it as expected_price.
const price = ((await myGiftList()).gifts || []).find((g) => g.gift_id === gift_id)?.price;
if (price == null) return res.status(400).json({ error: { code: 'gift_unavailable' } });
if (!Number.isInteger(count) || count < 1) return res.status(400).json({ error: { code: 'invalid_request' } });
// The charge is keyed by client_request_id and remembers what it was for (call, gift, count). A repeat of the
// same gift charges nothing more. The same ID for another gift, count or call is refused HERE, before anything
// is charged or sent: chargeMyUser answers false, and nothing is refunded (the earlier gift stands).
const what = `${req.params.callId}/${gift_id}/${count}`;
if (!(await chargeMyUser(req.user, price * count, { id: client_request_id, what }))) {
return res.status(409).json({ error: { code: 'gift_idempotency_conflict' } });
}
// 2. Ask us, passing the app's client_request_id through unchanged:
let r;
try {
r = await titli('POST', `/v1/live-hosts/calls/${req.params.callId}/gifts`, { gift_id, count, client_request_id, expected_price: price });
} catch {
// No answer (timeout, network): the outcome is unknown. KEEP the payment; the app repeats with the same ID.
return res.status(504).json({ error: { code: 'unknown' } });
}
// 201 sent, 200 the same send again, 202 still pending: keep the payment (gift.sent or gift.failed follows a 202).
if (r.status < 400) return res.status(r.status).json({ id: r.body.id, status: r.body.status });
// 3. An error. Give your user the money back ONLY when the answer says "refunded": true, or it is a refusal
// before any debit (a 4xx with one of the codes above). On 429, a 5xx without "refunded": true or no answer
// the gift may still be delivered: keep the payment and repeat the request with the SAME client_request_id.
const e = r.body.error || {};
const refunded = e.refunded === true || r.body.refunded === true;
if (refunded || (r.status < 500 && r.status !== 429 && REFUSED.has(e.code))) await refundMyUser(req.user, client_request_id);
const { code, user_message, user_message_hi, user_code, price: new_price, legacy_code } = e;
res.status(r.status).json({ error: { code, user_message, user_message_hi, user_code, price: new_price, legacy_code, refunded } }); // only these go to the app
});
// Webhooks: gift.sent confirms a gift (also one that was pending); gift.failed says a pending gift was refused.
app.post('/titli/webhook', async (req, res) => { // verify the Titli-Signature header first ([REST API reference](https://videosdk.titliapp.com/docs/rest-api))
const { event, data } = req.body;
if (event === 'gift.sent') await markGiftSent(data.gift.client_request_id);
if (event === 'gift.failed' && data.refunded) await refundMyUser(null, data.gift.client_request_id); // { gift, refunded: true }
res.sendStatus(200);
});
When to give your user the money back:
| Answer | Your user's payment |
|---|---|
201, 200 |
Keep it: the gift was sent. |
202 ("status": "pending") |
Keep it. gift.sent follows when the gift is confirmed, gift.failed ({ gift, refunded: true }) when it is refused: refund your user then. There is no time limit after which a pending gift is refunded by itself. |
An error with "refunded": true |
Refund. The answer is final. |
A 4xx with gifts_disabled, gift_unavailable, gift_price_changed, gift_host_unavailable, gift_not_in_session, insufficient_balance or invalid_request |
Refund: it was refused before anything was debited. |
409 gift_idempotency_conflict |
Do not refund: that client_request_id belongs to an earlier gift, and that gift stands. Refuse it on your backend before you charge, as the code above does. |
429, a 5xx without "refunded": true, a timeout or no answer |
Keep it and repeat the request with the same client_request_id (after Retry-After on a 429), or wait for gift.sent / gift.failed. The gift may have been delivered. |
2. The app #
final call = await TitliCall.connect(
url: livekitUrl,
token: token,
giftCatalog: await myBackend.getJson('/gifts'), // the relayed list (Map, JSON string or TitliGiftCatalog)
onSendGift: (req) async {
final res = await myBackend.post('/calls/$callId/gifts', req.toJson()); // gift_id, count, client_request_id, expected_price
if (res.statusCode >= 400) throw TitliGiftError.fromJson(res.body, status: res.statusCode);
return res.body;
},
onLiveEvent: (e) {
if (e is TitliLiveGiftEvent) playAnimation(e.gift.animationUrl); // the gift was sent
},
);
Hand back to the app what your backend answered, error fields included: the SDK reads code, legacy_code,
user_message, user_message_hi, user_code, price and refunded.
TitliCallScreen(call: call) then shows a gift button and a gift sheet (icon, name, your price, a count, Send) in
calls and in lives. They appear only when the list has enabled: true, at least one gift, and onSendGift is set;
otherwise nothing is shown. You can also pass giftCatalog, onSendGift and giftStrings: TitliGiftStrings(...) to
the screen. The sheet closes by itself when the call or live ends, before onEnded is called, so a
Navigator.pop in onEnded closes the call screen.
The call-create and stream-join answers carry gifts: { enabled, version }: have your backend pass it on and give
it to call.gifts.applyBrief(brief). It sets enabled, keeps the list you hold, and returns true (and sets
needsReload) when version differs from the one you hold: fetch the list again then. call.gifts.isStale(brief)
only compares. setCatalog with that short object does the same as applyBrief; it never empties the list.
After a send from the sheet was refused with gift_price_changed or gift_unavailable, the screen calls
onGiftsReloadNeeded: (error) { … } if you gave one: fetch the list again and call call.gifts.setCatalog(...).
For a changed price the sheet already shows the new price (error.price), and the next Send carries it.
With your own UI, use call.gifts (a ChangeNotifier):
call.gifts.setCatalog(json); // later updates; null clears
if (call.gifts.canSend) showMyGiftButton(); // enabled && onSendGift != null
try {
await call.gifts.send(call.gifts.gifts.first, count: 3);
} on TitliGiftError catch (e) {
// userMessageFor: the Hindi sentence when your app runs in Hindi, else the English one
showMessage(e.userMessageFor(Localizations.localeOf(context).languageCode) ?? 'This gift could not be sent. Please try again.');
if (e.code == TitliGiftErrorCode.giftPriceChanged) reloadGifts(); // also: call.gifts.needsReload
}
sendmakes a newclient_request_id(UUID) for every gift. While the outcome of a send is not known, sending the same gift and count again reuses the id, so it is never charged twice: after a failure without a final answer (no network, a timeout,rate_limited, a 5xx orpartner_unavailablewithoutrefunded:e.retryable), and after a result with"status": "pending"(your handler returns the map or JSON string your backend answered). The open send iscall.gifts.pendingRequest; callcall.gifts.clearPending()when your backend told the app how it ended. In a 1:1 call the SDK clears it when thegiftevent of that gift arrives.- An error with
e.refunded == trueis final (e.retryableis false): the next send is a new gift with a new id. - After the call or live has ended,
sendthrowsgiftNotInSessionwithout calling your handler, andcanSendis false. TitliGiftErrorCode:insufficientBalance,giftsDisabled,giftUnavailable,giftPriceChanged,giftHostUnavailable,giftIdempotencyConflict,giftNotInSession,rateLimited,partnerUnavailable(serviceUnavailableis the same value under its older name),invalidRequest,unknown.e.userMessageis a neutral sentence you can show as is,e.userMessageHiis the same sentence in Hindi, ande.userMessageFor(languageCode)picks between them (the gift sheet uses your app's locale);e.legacyCodeiserror.legacy_codewhen the answer had one.call.gifts.maxCountis the most gifts in one send:max_countof the list, 99 when the list has none.- Hidden gifts are never listed.
call.gifts.find(giftId)looks up any gift;gift.priceLabelgives₹150,$1.62or$0.010811(USD: up to 6 decimals when the price needs them, never fewer than 2). - In a 1:1 call the
giftlive event arrives for each gift your user sent (also when a pending send is confirmed later); in a live it arrives for everyone's gifts. The prebuilt screen shows a short toast.
Viewer mode (Live Streamers Pool) #
Watch a Titli host's live stream inside your app. The host's video and audio are relayed into a room ls_<id> as the participant ls_host. A viewer publishes nothing: no camera or microphone prompt, no local preview. The prebuilt screen shows her video full-screen with a small Titli watermark, the latest chat lines, gift toasts, a host-away banner, the viewer count, a leave button and an end message.
1. Get a viewer token on your server #
Your backend (never the app) asks for a viewer token for one of your users:
curl -u "$TITLI_KEY_ID:$TITLI_KEY_SECRET" -X POST \
https://api-videosdk.titliapp.com/v1/live-streams/<stream_ref>/join \
-H 'Content-Type: application/json' \
-d '{"end_user_id":"user_1001","name":"Ravi"}'
# -> {"viewer_id":"…","token":"eyJ…","livekit_url":"wss://…","room":"ls_…","expires_at":"…"}
stream_ref comes from GET /v1/live-streams. Send livekit_url and token to the app. The token is
subscribe-only (LiveKit grant canPublish:false, canPublishData:false, canSubscribe:true); the SDK sees that
and joins in viewer mode. Billing runs per second on our servers while the viewer is in the room and the host is on
air. Renew with POST /v1/live-streams/:ref/token before expires_at; call …/leave when the user closes the live.
Comments and gifts go through your server too (…/comments, …/gifts, see Gifts); they come back to every viewer as live events.
2. Join as a viewer #
final call = await TitliCall.connect(
url: livekitUrl,
token: viewerToken, // viewer mode is detected from the token
mode: TitliCallMode.viewer, // optional
onLiveEvent: (e) {
if (e is TitliLiveGiftEvent) debugPrint('${e.from.name} sent ${e.gift.count} x ${e.gift.name}');
},
);
await Navigator.of(context).push(MaterialPageRoute(
builder: (_) => TitliCallScreen(call: call, onLiveEvent: (e) => debugPrint(e.type)),
));
No runtime permission is needed for a viewer. Also available: call.liveEvents (a broadcast Stream<TitliLiveEvent>),
and ValueNotifiers liveHost, liveViewers, liveHostAway, liveChat, liveEnd; call.isViewer;
isTitliViewerToken(token); TitliLiveEvent.parse(bytes). Events are a sealed class: TitliLiveChatEvent,
TitliLiveGiftEvent, TitliLiveHostAwayEvent, TitliLiveHostBackEvent, TitliLiveViewersEvent,
TitliLiveEndedEvent, TitliLiveKickedEvent. Texts: TitliCallScreen(liveStrings: TitliLiveStrings(...)).
Live events #
LiveKit data messages on topic titli.live, JSON {type, …}. Unknown types and malformed messages are ignored.
| type | fields | the prebuilt screen |
|---|---|---|
chat |
id, at, from:{name, role}, text (role = host, viewer or partner) |
shows the last 5 lines |
gift |
from:{name, role, endUserId}, gift:{giftId, name, iconUrl, animationUrl, count} |
toast "name sent N x Gift" |
host_away / host_back |
none | shows / clears the "host stepped away" banner |
viewers |
viewers (count) |
viewer count in the top bar |
ended |
reason (host_ended, admin_terminated, …) |
end message, then leaves after 3 s |
kicked |
reason |
"removed" message, then leaves after 3 s |
Call mode is unchanged: a normal call token behaves exactly as before.
Links #
- Website and docs: https://videosdk.titliapp.com
- Console (API keys): https://console-videosdk.titliapp.com
- Samples: https://github.com/titli-video-sdk
- Issues: https://github.com/titli-video-sdk/titli-video-sdk-flutter/issues
- Contact: hello@titliapp.com