Spaces:
Paused
Paused
Update index.js
Browse files
index.js
CHANGED
|
@@ -1,23 +1,44 @@
|
|
| 1 |
const express = require('express');
|
| 2 |
-
const {
|
| 3 |
|
| 4 |
const app = express();
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
// ق
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
});
|
| 19 |
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
console.log(`Sign server running on port ${PORT}`);
|
| 23 |
});
|
|
|
|
| 1 |
const express = require('express');
|
| 2 |
+
const { WebcastPushConnection } = require('tiktok-live-connector');
|
| 3 |
|
| 4 |
const app = express();
|
| 5 |
+
const port = process.env.PORT || 7860;
|
| 6 |
+
|
| 7 |
+
// قائمة لتخزين آخر 20 تعليق
|
| 8 |
+
let comments = [];
|
| 9 |
+
const MAX_COMMENTS = 20;
|
| 10 |
+
|
| 11 |
+
// الاتصال بتيك توك (استخدم اسم المستخدم الذي تريده)
|
| 12 |
+
const username = process.env.TIKTOK_USERNAME || 'osei_iraq';
|
| 13 |
+
// مفتاح Euler Stream API (ضع مفتاحك هنا)
|
| 14 |
+
const SIGN_API_KEY = 'euler_NmE1NWUwY2E3MjUxNDM3MDk5MzliMDBkMjdjMWVlMWMzODdkMjdkOWQ5OGFmYTI0ODliYWM4';
|
| 15 |
+
|
| 16 |
+
let tiktokConnection = new WebcastPushConnection(username, {
|
| 17 |
+
signApiKey: SIGN_API_KEY
|
| 18 |
+
});
|
| 19 |
+
|
| 20 |
+
tiktokConnection.connect().then(state => {
|
| 21 |
+
console.log(`✅ متصل بـ ${username} (Room ${state.roomId})`);
|
| 22 |
+
|
| 23 |
+
tiktokConnection.on('chat', data => {
|
| 24 |
+
const comment = `${data.uniqueId}: ${data.comment}`;
|
| 25 |
+
console.log(comment);
|
| 26 |
+
comments.push(comment);
|
| 27 |
+
if (comments.length > MAX_COMMENTS) {
|
| 28 |
+
comments.shift();
|
| 29 |
+
}
|
| 30 |
+
});
|
| 31 |
+
|
| 32 |
+
}).catch(err => {
|
| 33 |
+
console.error('❌ فشل الاتصال:', err.message);
|
| 34 |
+
});
|
| 35 |
+
|
| 36 |
+
// نقطة نهاية لإرجاع التعليقات كنص
|
| 37 |
+
app.get('/comments', (req, res) => {
|
| 38 |
+
res.type('text/plain; charset=utf-8');
|
| 39 |
+
res.send(comments.join('\n'));
|
| 40 |
});
|
| 41 |
|
| 42 |
+
app.listen(port, () => {
|
| 43 |
+
console.log(`🚀 خادم التعليقات يعمل على المنفذ ${port}`);
|
|
|
|
| 44 |
});
|