tiktok-live-api 1.2.2 โ†’ 1.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +12 -1
  3. package/bin/demo.mjs +368 -0
  4. package/package.json +5 -1
package/LICENSE CHANGED
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2024 TikTool
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ MIT License
2
+
3
+ Copyright (c) 2024 TikTool
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,5 +1,5 @@
1
1
  <p align="center">
2
- <img src="https://raw.githubusercontent.com/tiktool/tiktok-live-api/main/banner.png" alt="tiktok-live-api" width="100%" />
2
+ <img src="banner.png" alt="tiktok-live-api" width="100%" />
3
3
  </p>
4
4
 
5
5
  # tiktok-live-api
@@ -18,6 +18,17 @@
18
18
 
19
19
  > This package is **not affiliated with or endorsed by TikTok**. It connects to the [TikTool Live](https://tik.tools) managed API service โ€” 99.9% uptime, no reverse engineering, no maintenance required. Also available for [Python](https://pypi.org/project/tiktok-live-api/) and [any language via WebSocket](https://tik.tools/docs).
20
20
 
21
+ ## ๐Ÿš€ One-Command Quick Start
22
+
23
+ Instantly connect to a live TikTok stream and print real-time events to your terminal. No signup, no install:
24
+
25
+ ```bash
26
+ npx tiktok-live-api
27
+ ```
28
+ *Or connect to a specific stream:* `npx tiktok-live-api @username`
29
+
30
+ ---
31
+
21
32
  ## Install
22
33
 
23
34
  ```bash
package/bin/demo.mjs ADDED
@@ -0,0 +1,368 @@
1
+ #!/usr/bin/env node
2
+
3
+ import WebSocket from 'ws';
4
+ import readline from 'readline';
5
+ import { execSync } from 'child_process';
6
+ import fs from 'fs';
7
+ import path from 'path';
8
+
9
+ // โ”€โ”€ Boilerplate Components โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
10
+
11
+ const REACT_TEMPLATE = [
12
+ '"use client";',
13
+ "import React, { useEffect, useState } from 'react';",
14
+ "import { TikTokLive } from 'tiktok-live-api';",
15
+ "",
16
+ "export default function TikTokLiveComponent() {",
17
+ " const [events, setEvents] = useState([]);",
18
+ " const [username, setUsername] = useState('aljazeeraenglish');",
19
+ " const [connected, setConnected] = useState(false);",
20
+ " ",
21
+ " useEffect(() => {",
22
+ " const client = new TikTokLive(username, { apiKey: 'demo_tiktokliveapi_public_2026' });",
23
+ " ",
24
+ ' client.on(\'chat\', (e) => setEvents(prev => [...prev.slice(-20), "๐Ÿ’ฌ " + e.user.uniqueId + ": " + e.comment]));',
25
+ ' client.on(\'gift\', (e) => setEvents(prev => [...prev.slice(-20), "๐ŸŽ " + e.user.uniqueId + " sent " + e.giftName]));',
26
+ " client.on('connected', () => setConnected(true));",
27
+ " client.on('disconnected', () => setConnected(false));",
28
+ " ",
29
+ " client.connect();",
30
+ " return () => client.disconnect();",
31
+ " }, [username]);",
32
+ "",
33
+ " return (",
34
+ " <div style={{ fontFamily: 'sans-serif', maxWidth: 400, margin: '40px auto', border: '1px solid #e5e7eb', padding: '24px', borderRadius: '12px', boxShadow: '0 10px 15px -3px rgba(0, 0, 0, 0.1)' }}>",
35
+ " <h2 style={{ margin: '0 0 16px 0', fontSize: '1.25rem', fontWeight: 600 }}>TikTok Live SDK Test</h2>",
36
+ " <div style={{ marginBottom: '16px', display: 'flex', alignItems: 'center', gap: '8px' }}>",
37
+ " <div style={{ width: 10, height: 10, borderRadius: '50%', background: connected ? '#10b981' : '#ef4444' }}></div>",
38
+ " <span style={{ fontSize: '0.875rem', color: '#374151' }}>{connected ? 'Connected to @' + username : 'Disconnected'}</span>",
39
+ " </div>",
40
+ " <div style={{ height: 320, overflowY: 'auto', background: '#f9fafb', padding: '12px', borderRadius: '8px', border: '1px solid #e5e7eb', fontSize: '0.875rem' }}>",
41
+ " {events.map((e, i) => <div key={i} style={{ padding: '6px 0', borderBottom: '1px solid #f3f4f6' }}>{e}</div>)}",
42
+ " {events.length === 0 && <div style={{ color: '#9ca3af', textAlign: 'center', marginTop: 120 }}>Waiting for events...</div>}",
43
+ " </div>",
44
+ " </div>",
45
+ " );",
46
+ "}"
47
+ ].join('\n') + "\n";
48
+
49
+ const VUE_TEMPLATE = [
50
+ "<template>",
51
+ ' <div style="font-family: sans-serif; max-width: 400px; margin: 40px auto; border: 1px solid #e5e7eb; padding: 24px; border-radius: 12px; box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1)">',
52
+ ' <h2 style="margin: 0 0 16px 0; font-size: 1.25rem; font-weight: 600">TikTok Live SDK Test</h2>',
53
+ ' <div style="margin-bottom: 16px; display: flex; align-items: center; gap: 8px">',
54
+ " <div :style=\"{ width: '10px', height: '10px', borderRadius: '50%', background: connected ? '#10b981' : '#ef4444' }\"></div>",
55
+ " <span style=\"font-size: 0.875rem; color: '#374151'\">{{ connected ? 'Connected to @' + username : 'Disconnected' }}</span>",
56
+ " </div>",
57
+ ' <div style="height: 320px; overflow-y: auto; background: #f9fafb; padding: 12px; border-radius: 8px; border: 1px solid #e5e7eb; font-size: 0.875rem">',
58
+ ' <div v-for="(e, i) in events" :key="i" style="padding: 6px 0; border-bottom: 1px solid #f3f4f6">',
59
+ " {{ e }}",
60
+ " </div>",
61
+ ' <div v-if="events.length === 0" style="color: #9ca3af; text-align: center; margin-top: 120px">Waiting for events...</div>',
62
+ " </div>",
63
+ " </div>",
64
+ "</template>",
65
+ "",
66
+ "<script setup>",
67
+ "import { ref, onMounted, onUnmounted } from 'vue'",
68
+ "import { TikTokLive } from 'tiktok-live-api'",
69
+ "",
70
+ "const username = ref('aljazeeraenglish')",
71
+ "const connected = ref(false)",
72
+ "const events = ref([])",
73
+ "let client = null",
74
+ "",
75
+ "onMounted(() => {",
76
+ " client = new TikTokLive(username.value, { apiKey: 'demo_tiktokliveapi_public_2026' })",
77
+ " ",
78
+ " client.on('chat', (e) => {",
79
+ ' events.value.push("๐Ÿ’ฌ " + e.user.uniqueId + ": " + e.comment)',
80
+ " if (events.value.length > 20) events.value.shift()",
81
+ " })",
82
+ " ",
83
+ " client.on('gift', (e) => {",
84
+ ' events.value.push("๐ŸŽ " + e.user.uniqueId + " sent " + e.giftName)',
85
+ " if (events.value.length > 20) events.value.shift()",
86
+ " })",
87
+ "",
88
+ " client.on('connected', () => connected.value = true)",
89
+ " client.on('disconnected', () => connected.value = false)",
90
+ " ",
91
+ " client.connect()",
92
+ "})",
93
+ "",
94
+ "onUnmounted(() => {",
95
+ " if (client) client.disconnect()",
96
+ "})",
97
+ "</script>"
98
+ ].join('\n') + "\n";
99
+
100
+ const E = String.fromCharCode(27);
101
+ const R = E + "[0m";
102
+ const B = E + "[1m";
103
+ const D = E + "[2m";
104
+ const C = {
105
+ cyan: E + "[38;5;80m", green: E + "[38;5;114m", yellow: E + "[38;5;222m",
106
+ mag: E + "[38;5;176m", blue: E + "[38;5;111m", red: E + "[38;5;203m",
107
+ gray: E + "[38;5;242m", white: E + "[38;5;252m", pink: E + "[38;5;218m",
108
+ };
109
+
110
+ // โ”€โ”€ Interactive Prompt โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
111
+
112
+ const args = process.argv.slice(2);
113
+ const isInteractive = args.length === 0;
114
+
115
+ if (!isInteractive) {
116
+ runDemo();
117
+ } else {
118
+ const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
119
+
120
+ console.log("\n " + B + "tiktok-live-api" + R + "\n Unofficial TikTok LIVE SDK by TikTool\n");
121
+ console.log(" What would you like to do?");
122
+ console.log(" 1) " + C.cyan + "Watch Live Terminal Demo" + R + " (Default)");
123
+ console.log(" 2) " + C.green + "Scaffold a Nuxt 3 (Vue) App" + R);
124
+ console.log(" 3) " + C.blue + "Scaffold a Next.js (React) App" + R);
125
+ console.log(" 4) " + C.yellow + "Scaffold a Vite (React) App" + R + "\n");
126
+
127
+ const timeoutId = setTimeout(() => {
128
+ console.log(D + "\r No input received. Auto-starting Terminal Demo..." + R + "\n");
129
+ rl.close();
130
+ runDemo();
131
+ }, 10000);
132
+
133
+ rl.question(" Choose [1-4]: ", (answer) => {
134
+ clearTimeout(timeoutId);
135
+ handleMenu(answer.trim() || '1');
136
+ });
137
+
138
+ function handleMenu(choice) {
139
+ if (choice === '1') {
140
+ rl.close();
141
+ return runDemo();
142
+ }
143
+
144
+ if (!['2', '3', '4'].includes(choice)) {
145
+ console.log(" " + C.red + "Invalid choice." + R);
146
+ rl.close();
147
+ process.exit(1);
148
+ }
149
+
150
+ rl.question("\n Target directory (e.g. ./my-app) [./tiktok-live-project]: ", (dir) => {
151
+ dir = dir.trim() || './tiktok-live-project';
152
+ rl.close();
153
+ runScaffold(choice, dir);
154
+ });
155
+ }
156
+ }
157
+
158
+ // โ”€โ”€ Scaffolding Logic โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
159
+
160
+ function runScaffold(choice, targetDir) {
161
+ const isNuxt = choice === '2';
162
+ const isNext = choice === '3';
163
+ const isVite = choice === '4';
164
+ const fullPath = path.resolve(process.cwd(), targetDir);
165
+
166
+ console.log("\n " + B + "๐Ÿš€ Scaffolding project into " + targetDir + "..." + R + "\n");
167
+
168
+ try {
169
+ if (isNuxt) {
170
+ execSync('npx --yes nuxi@latest init "' + targetDir + '" --packageManager npm', { stdio: 'inherit' });
171
+ } else if (isNext) {
172
+ execSync('npx --yes create-next-app@latest "' + targetDir + '" --js --eslint --tailwind --app --src-dir --import-alias "@/*" --use-npm', { stdio: 'inherit' });
173
+ } else if (isVite) {
174
+ execSync('npm create vite@latest "' + targetDir + '" -- --template react', { stdio: 'inherit' });
175
+ }
176
+
177
+ console.log("\n " + B + "๐Ÿ“ฆ Installing " + C.cyan + "tiktok-live-api" + B + " SDK..." + R + "\n");
178
+ execSync('npm install tiktok-live-api', { cwd: fullPath, stdio: 'inherit' });
179
+
180
+ if (isNuxt) {
181
+ const compDir = path.join(fullPath, 'components');
182
+ if (!fs.existsSync(compDir)) fs.mkdirSync(compDir, { recursive: true });
183
+ fs.writeFileSync(path.join(compDir, 'TikTokLive.vue'), VUE_TEMPLATE);
184
+
185
+ const appVue = path.join(fullPath, 'app.vue');
186
+ if (fs.existsSync(appVue)) {
187
+ fs.writeFileSync(appVue, [
188
+ '<template>',
189
+ ' <div style="min-height: 100vh; background: #fdfdfd; padding-top: 40px;">',
190
+ ' <TikTokLive />',
191
+ ' </div>',
192
+ '</template>'
193
+ ].join('\n') + '\n');
194
+ }
195
+ } else if (isNext) {
196
+ const compDir = path.join(fullPath, 'src', 'components');
197
+ if (!fs.existsSync(compDir)) fs.mkdirSync(compDir, { recursive: true });
198
+ fs.writeFileSync(path.join(compDir, 'TikTokLive.jsx'), REACT_TEMPLATE);
199
+
200
+ const pageJs = path.join(fullPath, 'src', 'app', 'page.js');
201
+ if (fs.existsSync(pageJs)) {
202
+ fs.writeFileSync(pageJs, [
203
+ "import TikTokLive from '@/components/TikTokLive';",
204
+ "",
205
+ "export default function Home() {",
206
+ " return (",
207
+ ' <main className="min-h-screen bg-neutral-50 pt-10">',
208
+ " <TikTokLive />",
209
+ " </main>",
210
+ " );",
211
+ "}"
212
+ ].join('\n') + '\n');
213
+ }
214
+ } else if (isVite) {
215
+ const compDir = path.join(fullPath, 'src', 'components');
216
+ if (!fs.existsSync(compDir)) fs.mkdirSync(compDir, { recursive: true });
217
+ fs.writeFileSync(path.join(compDir, 'TikTokLive.jsx'), REACT_TEMPLATE);
218
+
219
+ const appJsx = path.join(fullPath, 'src', 'App.jsx');
220
+ if (fs.existsSync(appJsx)) {
221
+ fs.writeFileSync(appJsx, [
222
+ "import TikTokLive from './components/TikTokLive';",
223
+ "",
224
+ "export default function App() {",
225
+ " return (",
226
+ " <div style={{ minHeight: '100vh', background: '#fdfdfd', paddingTop: '40px' }}>",
227
+ " <TikTokLive />",
228
+ " </div>",
229
+ " );",
230
+ "}"
231
+ ].join('\n') + '\n');
232
+ }
233
+ }
234
+
235
+ console.log("\n " + C.green + "โœ” Project successfully scaffolded!" + R + "\n");
236
+ console.log(" " + B + "Next steps:" + R);
237
+ console.log(" cd " + targetDir);
238
+ console.log(" npm run dev\n");
239
+
240
+ } catch (err) {
241
+ console.error("\n " + C.red + "Error during scaffolding:" + R, err.message);
242
+ process.exit(1);
243
+ }
244
+ }
245
+
246
+ // โ”€โ”€ Terminal Demo Logic โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
247
+
248
+ async function runDemo() {
249
+ const WS_BASE = 'wss://api.tik.tools';
250
+ const DEMO_KEY = 'demo_tiktokliveapi_public_2026';
251
+ const CHANNELS = [
252
+ 'aljazeeraenglish', 'cgtnofficial', 'france24_en',
253
+ 'weathernewslive', 'gbnews', 'bbcnews',
254
+ 'skynews', 'tv_asahi_news', 'abc7chicago', 'thairath_news',
255
+ ];
256
+
257
+ const TAG = {
258
+ chat: C.cyan + "chat" + R,
259
+ gift: C.yellow + "gift" + R,
260
+ like: C.mag + "like" + R,
261
+ member: C.green + "join" + R,
262
+ follow: C.green + "follow" + R,
263
+ viewer: C.blue + "viewers" + R,
264
+ share: C.white + "share" + R,
265
+ };
266
+
267
+ let target = '';
268
+ let apiKey = DEMO_KEY;
269
+ for (let i = 0; i < args.length; i++) {
270
+ const a = args[i];
271
+ if (a === '--key' || a === '-k') { apiKey = args[++i] || DEMO_KEY; }
272
+ else if (a === '--help' || a === '-h') { help(); process.exit(0); }
273
+ else if (!a.startsWith('-')) { target = a.replace(/^@/, ''); }
274
+ }
275
+
276
+ function help() {
277
+ console.log("\n " + B + "tiktok-live-api" + R + " " + D + "Real-time TikTok Live SDK" + R);
278
+ console.log("\n " + B + "Usage" + R);
279
+ console.log(" " + C.cyan + "npx tiktok-live-api" + R + " " + D + "interactive menu (demo or scaffold)" + R);
280
+ console.log(" " + C.cyan + "npx tiktok-live-api" + R + " " + C.white + "@username" + R + " " + D + "connect to a specific user" + R);
281
+ console.log(" " + C.cyan + "npx tiktok-live-api" + R + " " + C.gray + "--key KEY" + R + " " + D + "use your own API key" + R);
282
+ console.log("\n " + D + "Unofficial API by TikTool ยท https://tik.tools" + R + "\n");
283
+ }
284
+
285
+ function probe(uid, ms = 8000) {
286
+ return new Promise(resolve => {
287
+ const ws = new WebSocket(WS_BASE + "?uniqueId=" + uid + "&apiKey=" + apiKey);
288
+ const t = setTimeout(() => { ws.close(); resolve(null); }, ms);
289
+ ws.on('message', () => { clearTimeout(t); resolve(ws); });
290
+ ws.on('error', () => { clearTimeout(t); resolve(null); });
291
+ ws.on('close', () => { clearTimeout(t); });
292
+ });
293
+ }
294
+
295
+ function ts() {
296
+ const d = new Date();
297
+ return C.gray + String(d.getHours()).padStart(2, '0') + ":" + String(d.getMinutes()).padStart(2, '0') + ":" + String(d.getSeconds()).padStart(2, '0') + R;
298
+ }
299
+
300
+ function fmt(event, data) {
301
+ const tag = TAG[event] || (C.gray + event.padEnd(7) + R);
302
+ const u = data.user?.uniqueId || '';
303
+ const pad = tag.length < 20 ? ' ' : ' ';
304
+
305
+ switch (event) {
306
+ case 'chat': return ts() + " " + tag + pad + " " + B + u + R + " " + (data.comment || '');
307
+ case 'gift': return ts() + " " + tag + pad + " " + B + u + R + " " + C.yellow + (data.giftName || 'gift') + R + " x" + (data.repeatCount || 1) + " " + D + "(" + (data.diamondCount || 0) + "๐Ÿ’Ž)" + R;
308
+ case 'like': return ts() + " " + tag + pad + " " + B + u + R + " " + D + "total " + (data.totalLikeCount || 0).toLocaleString() + R;
309
+ case 'member': return ts() + " " + tag + pad + " " + C.green + u + R;
310
+ case 'follow': return ts() + " " + tag + " " + C.green + u + R;
311
+ case 'roomUserSeq':
312
+ case 'viewer': return ts() + " " + TAG.viewer + " " + B + (data.viewerCount || 0).toLocaleString() + R;
313
+ case 'share': return ts() + " " + tag + " " + u;
314
+ default: return null;
315
+ }
316
+ }
317
+
318
+ console.log("\n " + B + "tiktok-live-api" + R + " " + D + "ยท" + R + " " + D + "Real-time TikTok Live events" + R);
319
+ console.log(" " + D + "Unofficial API by TikTool ยท https://tik.tools" + R + "\n");
320
+
321
+ let ws = null, who = '';
322
+
323
+ if (target) {
324
+ process.stdout.write(" " + D + "connecting to" + R + " " + B + "@" + target + R + " " + D + "..." + R);
325
+ ws = await probe(target);
326
+ if (ws) { who = target; console.log(" " + C.green + "โ—" + R); }
327
+ else { console.log(" " + C.red + "โœ—" + R + "\n\n " + C.red + "Stream not found." + R + " Make sure " + B + "@" + target + R + " is live.\n"); process.exit(1); }
328
+ } else {
329
+ console.log(" " + D + "scanning for live streams..." + R + "\n");
330
+ for (const uid of CHANNELS) {
331
+ process.stdout.write(" " + C.gray + "@" + uid + R);
332
+ ws = await probe(uid);
333
+ if (ws) { who = uid; console.log(" " + C.green + "โ— live" + R); break; }
334
+ else { console.log(" " + D + "โ€”" + R); }
335
+ }
336
+ if (!ws) {
337
+ console.log("\n " + C.red + "No live streams found." + R + " Try: " + C.cyan + "npx tiktok-live-api @username" + R + "\n");
338
+ console.log(" " + D + "Get your own API key at" + R + " " + C.cyan + "https://tik.tools" + R + "\n");
339
+ process.exit(1);
340
+ }
341
+ }
342
+
343
+ console.log("\n " + C.green + "โ—" + R + " " + B + "@" + who + R + " " + D + "โ€” streaming events. Ctrl+C to stop." + R);
344
+ console.log(" " + D + "โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€" + R + "\n");
345
+
346
+ let count = 0;
347
+ ws.on('message', raw => {
348
+ try {
349
+ const m = JSON.parse(raw.toString());
350
+ const line = fmt(m.event || 'unknown', m.data || m);
351
+ if (line) { count++; console.log(" " + line); }
352
+ } catch { }
353
+ });
354
+
355
+ ws.on('close', () => {
356
+ console.log("\n " + D + "disconnected โ€” " + B + count + R + D + " events received" + R);
357
+ console.log(" " + D + "Get unlimited access:" + R + " " + C.cyan + "https://tik.tools" + R + "\n");
358
+ process.exit(0);
359
+ });
360
+
361
+ ws.on('error', e => console.error(" " + C.red + "error" + R + " " + e.message));
362
+ process.on('SIGINT', () => {
363
+ console.log("\n\n " + D + "stopped โ€” " + B + count + R + D + " events received" + R);
364
+ console.log(" " + D + "Get unlimited access:" + R + " " + C.cyan + "https://tik.tools" + R + "\n");
365
+ ws.close();
366
+ process.exit(0);
367
+ });
368
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tiktok-live-api",
3
- "version": "1.2.2",
3
+ "version": "1.2.4",
4
4
  "description": "Unofficial TikTok LIVE API Client โ€” Real-time chat, gifts, viewers, battles, and AI live captions from any TikTok livestream. Managed WebSocket API with 99.9% uptime.",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -12,8 +12,12 @@
12
12
  "require": "./dist/index.js"
13
13
  }
14
14
  },
15
+ "bin": {
16
+ "tiktok-live-api": "./bin/demo.mjs"
17
+ },
15
18
  "files": [
16
19
  "dist",
20
+ "bin",
17
21
  "README.md",
18
22
  "LICENSE"
19
23
  ],