tiktok-live-api 1.2.10 → 1.2.12
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/bin/demo.mjs +42 -53
- package/package.json +1 -1
package/bin/demo.mjs
CHANGED
|
@@ -15,9 +15,9 @@ const REACT_TEMPLATE = [
|
|
|
15
15
|
"",
|
|
16
16
|
"export default function TikTokLiveComponent() {",
|
|
17
17
|
" const [events, setEvents] = useState([]);",
|
|
18
|
-
" const [username, setUsername] = useState('
|
|
18
|
+
" const [username, setUsername] = useState('gbnews');",
|
|
19
19
|
" const [apiKey, setApiKey] = useState('demo_tiktokliveapi_public_2026');",
|
|
20
|
-
" const [inputUsername, setInputUsername] = useState('
|
|
20
|
+
" const [inputUsername, setInputUsername] = useState('gbnews');",
|
|
21
21
|
" const [connected, setConnected] = useState(false);",
|
|
22
22
|
" const clientRef = useRef(null);",
|
|
23
23
|
"",
|
|
@@ -59,7 +59,7 @@ const REACT_TEMPLATE = [
|
|
|
59
59
|
" <form onSubmit={handleConnect} style={{ display: 'flex', flexDirection: 'column', gap: '16px', marginBottom: '24px' }}>",
|
|
60
60
|
" <div>",
|
|
61
61
|
" <label style={{ display: 'block', fontSize: '0.875rem', fontWeight: 500, marginBottom: '6px' }}>TikTok Username</label>",
|
|
62
|
-
" <input type=\"text\" value={inputUsername} onChange={(e) => setInputUsername(e.target.value)} style={{ width: '100%', padding: '8px 12px', borderRadius: '6px', border: '1px solid #d1d5db', boxSizing: 'border-box' }} placeholder=\"e.g.
|
|
62
|
+
" <input type=\"text\" value={inputUsername} onChange={(e) => setInputUsername(e.target.value)} style={{ width: '100%', padding: '8px 12px', borderRadius: '6px', border: '1px solid #d1d5db', boxSizing: 'border-box' }} placeholder=\"e.g. gbnews\" />",
|
|
63
63
|
" </div>",
|
|
64
64
|
" <div>",
|
|
65
65
|
" <label style={{ display: 'block', fontSize: '0.875rem', fontWeight: 500, marginBottom: '6px' }}>API Key</label>",
|
|
@@ -95,7 +95,7 @@ const VUE_TEMPLATE = [
|
|
|
95
95
|
' <form @submit.prevent="handleConnect" style="display: flex; flex-direction: column; gap: 16px; margin-bottom: 24px">',
|
|
96
96
|
" <div>",
|
|
97
97
|
' <label style="display: block; font-size: 0.875rem; font-weight: 500; margin-bottom: 6px">TikTok Username</label>',
|
|
98
|
-
' <input type="text" v-model="inputUsername" style="width: 100%; padding: 8px 12px; border-radius: 6px; border: 1px solid #d1d5db; box-sizing: border-box" placeholder="e.g.
|
|
98
|
+
' <input type="text" v-model="inputUsername" style="width: 100%; padding: 8px 12px; border-radius: 6px; border: 1px solid #d1d5db; box-sizing: border-box" placeholder="e.g. gbnews" />',
|
|
99
99
|
" </div>",
|
|
100
100
|
" <div>",
|
|
101
101
|
' <label style="display: block; font-size: 0.875rem; font-weight: 500; margin-bottom: 6px">API Key</label>',
|
|
@@ -119,52 +119,52 @@ const VUE_TEMPLATE = [
|
|
|
119
119
|
"</template>",
|
|
120
120
|
"",
|
|
121
121
|
"<script setup>",
|
|
122
|
-
"import { ref,
|
|
122
|
+
"import { ref, onMounted, onUnmounted } from 'vue'",
|
|
123
123
|
"",
|
|
124
|
-
"const inputUsername = ref('
|
|
125
|
-
"const activeUsername = ref('
|
|
124
|
+
"const inputUsername = ref('gbnews')",
|
|
125
|
+
"const activeUsername = ref('gbnews')",
|
|
126
126
|
"const apiKey = ref('demo_tiktokliveapi_public_2026')",
|
|
127
|
+
"const connected = ref(false)",
|
|
127
128
|
"const events = ref([])",
|
|
129
|
+
"let ws = null",
|
|
128
130
|
"",
|
|
129
|
-
"
|
|
130
|
-
"try { if (typeof useTikTokLive !== 'undefined') hook = useTikTokLive; } catch (e) { }",
|
|
131
|
-
"const tiktok = hook ? hook(activeUsername, { apiKey, autoConnect: false }) : { connected: ref(false), allEvents: ref([]) }",
|
|
132
|
-
"const connected = tiktok.connected",
|
|
133
|
-
"",
|
|
134
|
-
"watch(() => tiktok.allEvents.value, (all) => {",
|
|
135
|
-
" if (all && all.length) {",
|
|
136
|
-
" const last = all[all.length - 1];",
|
|
137
|
-
" if (last.type === 'chat') addEvent(`💬 ${last.data.user.uniqueId}: ${last.data.comment}`)",
|
|
138
|
-
" if (last.type === 'gift') addEvent(`🎁 ${last.data.user.uniqueId} sent ${last.data.giftName}`)",
|
|
139
|
-
" if (last.type === 'like') addEvent(`❤️ ${last.data.user.uniqueId} liked`)",
|
|
140
|
-
" if (last.type === 'member') addEvent(`👋 ${last.data.user.uniqueId} joined`)",
|
|
141
|
-
" if (last.type === 'connected') addEvent('✅ Connected successfully!')",
|
|
142
|
-
" if (last.type === 'disconnected') addEvent('❌ Disconnected from stream.')",
|
|
143
|
-
" }",
|
|
144
|
-
"}, { deep: true })",
|
|
145
|
-
"",
|
|
146
|
-
"watch(() => tiktok.error ? tiktok.error.value : null, (e) => {",
|
|
147
|
-
" if(e) addEvent('⚠️ Error: ' + e)",
|
|
148
|
-
"})",
|
|
149
|
-
"",
|
|
150
|
-
"const addEvent = (str) => {",
|
|
131
|
+
"function addEvent(str) {",
|
|
151
132
|
" events.value.push(str)",
|
|
152
|
-
" if(events.value.length > 50) events.value.shift()",
|
|
133
|
+
" if (events.value.length > 50) events.value.shift()",
|
|
153
134
|
"}",
|
|
154
135
|
"",
|
|
155
|
-
"
|
|
156
|
-
" if (
|
|
136
|
+
"function connectStream() {",
|
|
137
|
+
" if (ws) { ws.close(); ws = null }",
|
|
157
138
|
" events.value = []",
|
|
139
|
+
" connected.value = false",
|
|
158
140
|
" activeUsername.value = inputUsername.value",
|
|
159
|
-
"
|
|
160
|
-
" if (
|
|
161
|
-
"
|
|
141
|
+
" const user = (activeUsername.value || '').replace(/^@/, '')",
|
|
142
|
+
" if (!user) return",
|
|
143
|
+
" const key = apiKey.value || ''",
|
|
144
|
+
" try {",
|
|
145
|
+
" ws = new WebSocket('wss://api.tik.tools?uniqueId=' + user + '&apiKey=' + key)",
|
|
146
|
+
" } catch (e) { addEvent('⚠️ Connection failed: ' + e.message); return }",
|
|
147
|
+
" ws.onopen = () => { connected.value = true; addEvent('✅ Connected to @' + user) }",
|
|
148
|
+
" ws.onclose = () => { connected.value = false; ws = null; addEvent('❌ Disconnected') }",
|
|
149
|
+
" ws.onerror = () => { addEvent('⚠️ WebSocket error') }",
|
|
150
|
+
" ws.onmessage = (evt) => {",
|
|
151
|
+
" try {",
|
|
152
|
+
" const msg = JSON.parse(evt.data)",
|
|
153
|
+
" const t = msg.event || ''",
|
|
154
|
+
" const d = msg.data || {}",
|
|
155
|
+
" const u = d.user ? d.user.uniqueId : ''",
|
|
156
|
+
" if (t === 'chat') addEvent('💬 ' + u + ': ' + d.comment)",
|
|
157
|
+
" else if (t === 'gift') addEvent('🎁 ' + u + ' sent ' + (d.giftName || 'a gift'))",
|
|
158
|
+
" else if (t === 'like') addEvent('❤️ ' + u + ' liked')",
|
|
159
|
+
" else if (t === 'member') addEvent('👋 ' + u + ' joined')",
|
|
160
|
+
" } catch (e) {}",
|
|
162
161
|
" }",
|
|
163
162
|
"}",
|
|
164
163
|
"",
|
|
165
|
-
"
|
|
166
|
-
"
|
|
167
|
-
"})",
|
|
164
|
+
"const handleConnect = () => { connectStream() }",
|
|
165
|
+
"",
|
|
166
|
+
"onMounted(() => { connectStream() })",
|
|
167
|
+
"onUnmounted(() => { if (ws) ws.close() })",
|
|
168
168
|
"</script>"
|
|
169
169
|
].join('\n') + "\n";
|
|
170
170
|
|
|
@@ -260,10 +260,6 @@ function runScaffold(choice, targetDir, pm) {
|
|
|
260
260
|
}
|
|
261
261
|
|
|
262
262
|
if (isNuxt) {
|
|
263
|
-
console.log("\\n " + B + "📦 Installing " + C.cyan + "tiktok-live-nuxt" + B + " Module..." + R + "\\n");
|
|
264
|
-
const nuxtInstallCmd = pm === 'npm' ? 'npm install tiktok-live-nuxt' : pm === 'yarn' ? 'yarn add tiktok-live-nuxt' : pm === 'pnpm' ? 'pnpm add tiktok-live-nuxt' : 'bun add tiktok-live-nuxt';
|
|
265
|
-
execSync(nuxtInstallCmd, { cwd: fullPath, stdio: 'inherit' });
|
|
266
|
-
|
|
267
263
|
const isNuxt4 = fs.existsSync(path.join(fullPath, 'app', 'app.vue')) || !fs.existsSync(path.join(fullPath, 'app.vue'));
|
|
268
264
|
const baseApp = isNuxt4 ? path.join(fullPath, 'app') : fullPath;
|
|
269
265
|
|
|
@@ -275,19 +271,12 @@ function runScaffold(choice, targetDir, pm) {
|
|
|
275
271
|
fs.writeFileSync(appVue, [
|
|
276
272
|
'<template>',
|
|
277
273
|
' <main style="min-height: 100vh; background: #f9fafb; padding-top: 40px;">',
|
|
278
|
-
' <
|
|
274
|
+
' <ClientOnly>',
|
|
275
|
+
' <TikTokLive />',
|
|
276
|
+
' </ClientOnly>',
|
|
279
277
|
' </main>',
|
|
280
278
|
'</template>'
|
|
281
279
|
].join('\n') + '\n');
|
|
282
|
-
|
|
283
|
-
const nuxtConfig = path.join(fullPath, 'nuxt.config.ts');
|
|
284
|
-
if (fs.existsSync(nuxtConfig)) {
|
|
285
|
-
let config = fs.readFileSync(nuxtConfig, 'utf8');
|
|
286
|
-
if (config.includes('defineNuxtConfig({')) {
|
|
287
|
-
config = config.replace('defineNuxtConfig({', "defineNuxtConfig({\n modules: ['tiktok-live-nuxt'],\n");
|
|
288
|
-
fs.writeFileSync(nuxtConfig, config);
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
280
|
} else {
|
|
292
281
|
console.log("\\n " + B + "📦 Installing " + C.cyan + "tiktok-live-api" + B + " SDK..." + R + "\\n");
|
|
293
282
|
execSync(installCmd, { cwd: fullPath, stdio: 'inherit' });
|
|
@@ -353,7 +342,7 @@ async function runDemo() {
|
|
|
353
342
|
const WS_BASE = 'wss://api.tik.tools';
|
|
354
343
|
const DEMO_KEY = 'demo_tiktokliveapi_public_2026';
|
|
355
344
|
const CHANNELS = [
|
|
356
|
-
'
|
|
345
|
+
'gbnews', 'cgtnofficial', 'france24_en',
|
|
357
346
|
'weathernewslive', 'gbnews', 'bbcnews',
|
|
358
347
|
'skynews', 'tv_asahi_news', 'abc7chicago', 'thairath_news',
|
|
359
348
|
];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tiktok-live-api",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.12",
|
|
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",
|