// Type definitions for titli-video-sdk (browser helper, titli-call.js; UMD).
// import TitliCall from 'titli-video-sdk'; (bundlers, esModuleInterop)
// const TitliCall = require('titli-video-sdk');
// -> global TitliCall
export = TitliCall;
export as namespace TitliCall;
declare const TitliCall: TitliCall.TitliCallApi;
declare namespace TitliCall {
interface TitliTokenInfo {
identity: string;
name: string;
canPublish: boolean;
canPublishData: boolean;
canPublishCamera: boolean;
room: string | null;
/** Unix seconds. */
expiresAt: number | null;
}
interface TitliLiveSender {
name: string;
role: 'host' | 'viewer' | 'partner' | string | null;
endUserId: string | null;
}
interface TitliLiveGift {
giftId: string;
name: string;
iconUrl: string | null;
animationUrl: string | null;
count: number;
}
type TitliLiveEvent =
| { type: 'chat'; id: string; at: string | number | null; from: TitliLiveSender; text: string }
| { type: 'gift'; id: string | null; at: string | number | null; from: TitliLiveSender; gift: TitliLiveGift }
| { type: 'host_away' }
| { type: 'host_back' }
| { type: 'viewers'; viewers: number }
| { type: 'ended' | 'kicked'; reason: string | null; endCode: string | null; userCode: string | null; userMessage: string | null };
interface TitliGift {
giftId: string;
name: string;
iconUrl: string | null;
animationUrl: string | null;
category: string | null;
/** YOUR price for one gift. */
price: number;
currency: string;
hidden: boolean;
}
interface TitliGiftCatalog {
enabled: boolean;
version: string | null;
currency: string | null;
maxCount: number;
gifts: TitliGift[];
hasList: boolean;
}
interface TitliGiftRequest {
gift: TitliGift;
giftId: string;
count: number;
clientRequestId: string;
expectedPrice: number;
/** JSON.stringify(request) gives { gift_id, count, client_request_id, expected_price }. */
toJSON?(): { gift_id: string; count: number; client_request_id: string; expected_price: number };
}
type TitliGiftErrorCode =
| 'insufficient_balance' | 'gifts_disabled' | 'gift_unavailable' | 'gift_price_changed' | 'gift_price_below_cost'
| 'gift_host_unavailable' | 'gift_idempotency_conflict' | 'gift_not_in_session' | 'rate_limited'
| 'partner_unavailable' | 'invalid_request' | 'unknown';
interface TitliGiftError extends Error {
code: TitliGiftErrorCode;
rawCode: string;
userMessage: string | null;
userMessageHi: string | null;
userCode: string | null;
status: number | null;
price: number | null;
legacyCode: string | null;
refunded: boolean;
request: TitliGiftRequest | null;
retryable: boolean;
/** The Hindi sentence for a language tag starting with "hi" (default: the page's language), else the English one. */
userMessageFor(language?: string): string | null;
}
type Off = () => void;
interface TitliGifts {
catalog: TitliGiftCatalog | null;
onSendGift: ((request: TitliGiftRequest) => Promise) | null;
needsReload: boolean;
lastRequest: TitliGiftRequest | null;
lastError: TitliGiftError | null;
pendingRequest: TitliGiftRequest | null;
ended: boolean;
readonly list: TitliGift[];
readonly enabled: boolean;
readonly version: string | null;
readonly currency: string | null;
readonly maxCount: number;
readonly canSend: boolean;
readonly sending: boolean;
setCatalog(json: unknown): void;
isStale(brief: { enabled?: boolean; version?: string | null } | null | undefined): boolean;
applyBrief(brief: { enabled?: boolean; version?: string | null } | null | undefined): boolean;
clearPending(): void;
setSendHandler(fn: ((request: TitliGiftRequest) => Promise) | null): void;
find(giftId: string): TitliGift | null;
send(gift: TitliGift | string, count?: number, opts?: { clientRequestId?: string }): Promise;
on(type: 'change', fn: () => void): Off;
on(type: 'sent', fn: (e: { request: TitliGiftRequest; result: unknown }) => void): Off;
on(type: 'error', fn: (e: TitliGiftError) => void): Off;
on(type: 'reloadNeeded', fn: (e: { code: string; giftId: string | null; price: number | null }) => void): Off;
off(type: string, fn: (...args: any[]) => void): void;
}
interface TitliDisconnect {
reason: 'left' | 'ended' | 'kicked' | 'server' | 'removed' | 'lost';
serverReason: string | null;
endCode: string | null;
userCode: string | null;
/** A neutral sentence you can show your user as is, when the server ended the session. */
userMessage: string | null;
}
interface TitliJoinOptions {
mode?: 'viewer' | 'call';
container?: Element | string;
onLiveEvent?: (e: TitliLiveEvent) => void;
giftCatalog?: unknown;
onGiftsReloadNeeded?: (e: { code: string; giftId: string | null; price: number | null }) => void;
endUserId?: string;
onSendGift?: (request: TitliGiftRequest) => Promise;
onDisconnected?: (e: TitliDisconnect) => void;
strings?: Partial string)>>;
keepEndMessage?: boolean;
/** The livekit-client module (default: the global LivekitClient). */
livekit?: unknown;
}
interface TitliSession {
readonly tokenInfo: TitliTokenInfo;
readonly isViewer: boolean;
/** The livekit-client Room. */
readonly room: any;
readonly gifts: TitliGifts;
readonly endUserId: string | null;
readonly state: {
connected: boolean;
ended: boolean;
viewers: number | null;
hostAway: boolean;
chat: Array>;
liveEnd: Extract | null;
host: { identity: string; name: string } | null;
};
leave(): Promise;
on(type: 'connected', fn: (e: { room: string }) => void): Off;
on(type: 'disconnected', fn: (e: TitliDisconnect) => void): Off;
on(type: 'liveEvent', fn: (e: TitliLiveEvent) => void): Off;
on(type: string, fn: (e: any) => void): Off;
off(type: string, fn: (...args: any[]) => void): void;
}
interface TitliCallApi {
readonly VERSION: string;
join(url: string, token: string, options?: TitliJoinOptions): Promise;
parseToken(token: string): TitliTokenInfo;
isViewerToken(token: string): boolean;
parseLiveEvent(data: string | Uint8Array): TitliLiveEvent | null;
TitliGifts: { new (): TitliGifts; prototype: TitliGifts };
TitliGiftError: {
new (code: string, message?: string, extra?: Record): TitliGiftError;
prototype: TitliGiftError;
from(thrown: unknown, request?: TitliGiftRequest): TitliGiftError;
};
parseGift(o: unknown, fallbackCurrency?: string): TitliGift | null;
parseGiftCatalog(json: unknown): TitliGiftCatalog | null;
giftErrorCode(v: unknown): TitliGiftErrorCode;
giftRequestBody(req: TitliGiftRequest): { gift_id: string; count: number; client_request_id: string; expected_price: number };
formatGiftPrice(price: number, currency?: string): string;
endUserOfIdentity(identity: string): string | null;
newClientRequestId(): string;
readonly LIVE_TOPIC: string;
readonly LIVE_HOST_IDENTITY: string;
readonly DEFAULT_STRINGS: Record string)>;
readonly GIFT_MAX_COUNT: number;
readonly GIFT_ERROR_CODES: TitliGiftErrorCode[];
}
}