tiktok-live-api 1.2.7 → 1.2.10
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 +60 -46
- package/package.json +1 -1
package/bin/demo.mjs
CHANGED
|
@@ -119,62 +119,51 @@ const VUE_TEMPLATE = [
|
|
|
119
119
|
"</template>",
|
|
120
120
|
"",
|
|
121
121
|
"<script setup>",
|
|
122
|
-
"import { ref,
|
|
123
|
-
"import { TikTokLive } from 'tiktok-live-api'",
|
|
122
|
+
"import { ref, watch, onMounted } from 'vue'",
|
|
124
123
|
"",
|
|
125
124
|
"const inputUsername = ref('aljazeeraenglish')",
|
|
126
125
|
"const activeUsername = ref('aljazeeraenglish')",
|
|
127
126
|
"const apiKey = ref('demo_tiktokliveapi_public_2026')",
|
|
128
|
-
"const connected = ref(false)",
|
|
129
127
|
"const events = ref([])",
|
|
130
|
-
"let client = null",
|
|
131
128
|
"",
|
|
132
|
-
"
|
|
133
|
-
"
|
|
134
|
-
"
|
|
135
|
-
"
|
|
136
|
-
" activeUsername.value = inputUsername.value",
|
|
137
|
-
" ",
|
|
138
|
-
" if (!activeUsername.value) return",
|
|
139
|
-
" ",
|
|
140
|
-
" client = new TikTokLive(activeUsername.value, { apiKey: apiKey.value })",
|
|
141
|
-
" ",
|
|
142
|
-
" client.on('chat', (e) => {",
|
|
143
|
-
' events.value.push("💬 " + e.user.uniqueId + ": " + e.comment)',
|
|
144
|
-
" if (events.value.length > 40) events.value.shift()",
|
|
145
|
-
" })",
|
|
146
|
-
" ",
|
|
147
|
-
" client.on('gift', (e) => {",
|
|
148
|
-
' events.value.push("🎁 " + e.user.uniqueId + " sent " + e.giftName)',
|
|
149
|
-
" if (events.value.length > 40) events.value.shift()",
|
|
150
|
-
" })",
|
|
129
|
+
"let hook = null;",
|
|
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",
|
|
151
133
|
"",
|
|
152
|
-
"
|
|
153
|
-
|
|
154
|
-
"
|
|
155
|
-
"
|
|
156
|
-
"
|
|
157
|
-
"
|
|
158
|
-
|
|
159
|
-
" if (
|
|
160
|
-
"
|
|
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 })",
|
|
161
145
|
"",
|
|
162
|
-
"
|
|
163
|
-
"
|
|
164
|
-
"
|
|
165
|
-
"
|
|
146
|
+
"watch(() => tiktok.error ? tiktok.error.value : null, (e) => {",
|
|
147
|
+
" if(e) addEvent('⚠️ Error: ' + e)",
|
|
148
|
+
"})",
|
|
149
|
+
"",
|
|
150
|
+
"const addEvent = (str) => {",
|
|
151
|
+
" events.value.push(str)",
|
|
152
|
+
" if(events.value.length > 50) events.value.shift()",
|
|
166
153
|
"}",
|
|
167
154
|
"",
|
|
168
155
|
"const handleConnect = () => {",
|
|
169
|
-
"
|
|
156
|
+
" if (tiktok.disconnect) tiktok.disconnect()",
|
|
157
|
+
" events.value = []",
|
|
158
|
+
" activeUsername.value = inputUsername.value",
|
|
159
|
+
" if (!activeUsername.value) return",
|
|
160
|
+
" if (tiktok.connect) {",
|
|
161
|
+
" tiktok.connect().catch(e => addEvent('⚠️ Failed: ' + e.message))",
|
|
162
|
+
" }",
|
|
170
163
|
"}",
|
|
171
164
|
"",
|
|
172
165
|
"onMounted(() => {",
|
|
173
|
-
"
|
|
174
|
-
"})",
|
|
175
|
-
"",
|
|
176
|
-
"onUnmounted(() => {",
|
|
177
|
-
" if (client) client.disconnect()",
|
|
166
|
+
" handleConnect()",
|
|
178
167
|
"})",
|
|
179
168
|
"</script>"
|
|
180
169
|
].join('\n') + "\n";
|
|
@@ -262,7 +251,7 @@ function runScaffold(choice, targetDir, pm) {
|
|
|
262
251
|
|
|
263
252
|
try {
|
|
264
253
|
if (isNuxt) {
|
|
265
|
-
execSync(npxCmd + '
|
|
254
|
+
execSync(npxCmd + ' nuxi@latest init "' + targetDir + '" --packageManager ' + pm, { stdio: 'inherit' });
|
|
266
255
|
} else if (isNext) {
|
|
267
256
|
execSync(npxCmd + ' create-next-app@latest "' + targetDir + '" --js --eslint --tailwind --app --src-dir --import-alias "@/*" --use-' + pm, { stdio: 'inherit' });
|
|
268
257
|
} else if (isVite) {
|
|
@@ -271,9 +260,34 @@ function runScaffold(choice, targetDir, pm) {
|
|
|
271
260
|
}
|
|
272
261
|
|
|
273
262
|
if (isNuxt) {
|
|
274
|
-
console.log("\\n " + B + "📦 Installing
|
|
275
|
-
const
|
|
276
|
-
execSync(
|
|
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
|
+
const isNuxt4 = fs.existsSync(path.join(fullPath, 'app', 'app.vue')) || !fs.existsSync(path.join(fullPath, 'app.vue'));
|
|
268
|
+
const baseApp = isNuxt4 ? path.join(fullPath, 'app') : fullPath;
|
|
269
|
+
|
|
270
|
+
const compDir = path.join(baseApp, 'components');
|
|
271
|
+
if (!fs.existsSync(compDir)) fs.mkdirSync(compDir, { recursive: true });
|
|
272
|
+
fs.writeFileSync(path.join(compDir, 'TikTokLive.vue'), VUE_TEMPLATE);
|
|
273
|
+
|
|
274
|
+
const appVue = path.join(baseApp, 'app.vue');
|
|
275
|
+
fs.writeFileSync(appVue, [
|
|
276
|
+
'<template>',
|
|
277
|
+
' <main style="min-height: 100vh; background: #f9fafb; padding-top: 40px;">',
|
|
278
|
+
' <TikTokLive />',
|
|
279
|
+
' </main>',
|
|
280
|
+
'</template>'
|
|
281
|
+
].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
|
+
}
|
|
277
291
|
} else {
|
|
278
292
|
console.log("\\n " + B + "📦 Installing " + C.cyan + "tiktok-live-api" + B + " SDK..." + R + "\\n");
|
|
279
293
|
execSync(installCmd, { cwd: fullPath, stdio: 'inherit' });
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tiktok-live-api",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.10",
|
|
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",
|