tiktok-live-api 1.0.0 ā 1.0.2
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.
- package/README.md +73 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -54,6 +54,78 @@ client.connect();
|
|
|
54
54
|
|
|
55
55
|
That's it. **No complex setup, no protobuf, no reverse engineering, no breakages when TikTok updates.**
|
|
56
56
|
|
|
57
|
+
---
|
|
58
|
+
|
|
59
|
+
## š Try It Now ā 5-Minute Live Demo
|
|
60
|
+
|
|
61
|
+
Copy-paste this into a file and run it. Connects to a live TikTok stream, prints every event for 5 minutes, then exits. Works on the free Sandbox tier.
|
|
62
|
+
|
|
63
|
+
**Save as `demo.mjs` and run with `node demo.mjs`:**
|
|
64
|
+
|
|
65
|
+
```javascript
|
|
66
|
+
// demo.mjs ā TikTok LIVE in 5 minutes
|
|
67
|
+
// npm install tiktok-live-api
|
|
68
|
+
import { TikTokLive } from 'tiktok-live-api';
|
|
69
|
+
|
|
70
|
+
const API_KEY = 'YOUR_API_KEY'; // Get free key ā https://tik.tools
|
|
71
|
+
const LIVE_USERNAME = 'tv_asahi_news'; // Any live TikTok username
|
|
72
|
+
|
|
73
|
+
const client = new TikTokLive(LIVE_USERNAME, { apiKey: API_KEY });
|
|
74
|
+
let events = 0;
|
|
75
|
+
|
|
76
|
+
client.on('chat', e => { events++; console.log(`š¬ ${e.user.uniqueId}: ${e.comment}`); });
|
|
77
|
+
client.on('gift', e => { events++; console.log(`š ${e.user.uniqueId} sent ${e.giftName} (${e.diamondCount}š)`); });
|
|
78
|
+
client.on('like', e => { events++; console.log(`ā¤ļø ${e.user.uniqueId} liked Ć ${e.likeCount}`); });
|
|
79
|
+
client.on('member', e => { events++; console.log(`š ${e.user.uniqueId} joined`); });
|
|
80
|
+
client.on('follow', e => { events++; console.log(`ā ${e.user.uniqueId} followed`); });
|
|
81
|
+
client.on('roomUserSeq', e => { events++; console.log(`š Viewers: ${e.viewerCount}`); });
|
|
82
|
+
|
|
83
|
+
client.on('connected', () => console.log(`\nā
Connected to @${LIVE_USERNAME} ā listening for 5 min...\n`));
|
|
84
|
+
client.on('disconnected', () => console.log(`\nš Done! Received ${events} events.\n`));
|
|
85
|
+
|
|
86
|
+
client.connect();
|
|
87
|
+
setTimeout(() => { client.disconnect(); }, 300_000);
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
<details>
|
|
91
|
+
<summary><strong>š Pure WebSocket version (no SDK, any language)</strong></summary>
|
|
92
|
+
|
|
93
|
+
```javascript
|
|
94
|
+
// ws-demo.mjs ā Pure WebSocket, zero SDK
|
|
95
|
+
// npm install ws
|
|
96
|
+
import WebSocket from 'ws';
|
|
97
|
+
|
|
98
|
+
const API_KEY = 'YOUR_API_KEY';
|
|
99
|
+
const LIVE_USERNAME = 'tv_asahi_news';
|
|
100
|
+
|
|
101
|
+
const ws = new WebSocket(`wss://api.tik.tools?uniqueId=${LIVE_USERNAME}&apiKey=${API_KEY}`);
|
|
102
|
+
let events = 0;
|
|
103
|
+
|
|
104
|
+
ws.on('open', () => console.log(`\nā
Connected to @${LIVE_USERNAME} ā listening for 5 min...\n`));
|
|
105
|
+
ws.on('message', (raw) => {
|
|
106
|
+
const msg = JSON.parse(raw);
|
|
107
|
+
events++;
|
|
108
|
+
const d = msg.data || {};
|
|
109
|
+
const user = d.user?.uniqueId || '';
|
|
110
|
+
switch (msg.event) {
|
|
111
|
+
case 'chat': console.log(`š¬ ${user}: ${d.comment}`); break;
|
|
112
|
+
case 'gift': console.log(`š ${user} sent ${d.giftName} (${d.diamondCount}š)`); break;
|
|
113
|
+
case 'like': console.log(`ā¤ļø ${user} liked Ć ${d.likeCount}`); break;
|
|
114
|
+
case 'member': console.log(`š ${user} joined`); break;
|
|
115
|
+
case 'roomUserSeq': console.log(`š Viewers: ${d.viewerCount}`); break;
|
|
116
|
+
case 'roomInfo': console.log(`š” Room: ${msg.roomId}`); break;
|
|
117
|
+
default: console.log(`š¦ ${msg.event}`); break;
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
ws.on('close', () => console.log(`\nš Done! Received ${events} events.\n`));
|
|
121
|
+
|
|
122
|
+
setTimeout(() => ws.close(), 300_000);
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
</details>
|
|
126
|
+
|
|
127
|
+
---
|
|
128
|
+
|
|
57
129
|
## JavaScript (CommonJS)
|
|
58
130
|
|
|
59
131
|
```javascript
|
|
@@ -267,7 +339,7 @@ client.on('gift', (event: GiftEvent) => {
|
|
|
267
339
|
|
|
268
340
|
| Tier | Requests/Day | WebSocket Connections | Price |
|
|
269
341
|
|------|-------------|----------------------|-------|
|
|
270
|
-
| Sandbox | 50 | 1 (
|
|
342
|
+
| Sandbox | 50 | 1 (5 min) | Free |
|
|
271
343
|
| Basic | 10,000 | 3 (8h) | $7/week |
|
|
272
344
|
| Pro | 75,000 | 50 (8h) | $15/week |
|
|
273
345
|
| Ultra | 300,000 | 500 (8h) | $45/week |
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tiktok-live-api",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
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",
|