Skip to content

API reference

Reference for the tiktok-live-printer npm package: TikTokPrinterClient, PrinterEngine, transports, print items, media and event helpers.

new TikTokPrinterClient({
uniqueId: string; // creator handle, with or without @
apiKey?: string; // Euler Stream API key (required in practice)
jwtKey?: string; // alternative to apiKey
printer: PrinterEngine;
voice?: VoiceEngine; // defaults to the OS speech tool
sound?: SoundEngine; // defaults to the OS player
wsUrl?: string; // override the WebSocket host
})
MemberDescription
connect(): Promise<void>Opens the WebSocket; resolves on open, rejects if it closes first
disconnect(): voidCloses the socket
queue(...items): Promise<void>Prints the items as one job
text(), image(), voice(), sound()One-item shortcuts
handleFrame(raw: string): voidFeeds a raw JSON frame, useful for tests
printerThe engine passed in
urlThe WebSocket URL that will be used

PrinterEngine.usb(opts), .spooler(opts), .network(opts), .console(opts) or new PrinterEngine(transport, opts). Options: width: 384 | 576, imageGamma: number.

MemberDescription
encode(items): Uint8ArrayESC/POS bytes for a job
print(items): Promise<void>Encodes and writes one job
close(): Promise<void>Releases the transport
width, columns, imageGammaEffective settings

ConsoleTransport, MemoryTransport (keeps chunks in memory for tests), NetworkTransport(host, port), UsbTransport({ vendorId?, productId? }), SpoolerTransport({ queue? }). Discovery: listUsbPrinters(), listSpoolerQueues().

Text(content, style), Image(image, width?), Line(), Feed(lines), Cut(), Voice(text), Sound(path). Types: PrintItem, TextStyle, RgbaImage.

fetchImage(url, { timeoutMs? }), pickImageUrl(image), avatarUrl(user), giftImageUrl(gift), lighten(image, gamma).

isGiftComplete(msg), giftTotal(msg), giftDiamonds(msg), isJoin(msg), socialKind(msg). Types: WebcastEventMap, WebcastEventName, ClientEvents.

VoiceEngine.speak(text) and SoundEngine.play(path) shell out to the OS and resolve when the tool exits; a missing tool is ignored.