waengine 1.1.0 → 1.5.0
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 +60 -38
- package/package.json +7 -2
- package/src/client.js +335 -32
- package/src/device-manager.js +35 -10
- package/src/easy-bot.js +206 -9
- package/src/index.js +4 -0
- package/src/message.js +19 -0
- package/src/multi-client.js +63 -6
- package/src/qr.js +433 -81
package/src/device-manager.js
CHANGED
|
@@ -117,18 +117,43 @@ export class DeviceManager {
|
|
|
117
117
|
}
|
|
118
118
|
|
|
119
119
|
async connectAll() {
|
|
120
|
-
console.log(`🚀
|
|
120
|
+
console.log(`🚀 Sequenzielle Verbindung aller ${this.devices.size} Devices...`);
|
|
121
|
+
console.log("📱 QR-Codes werden nacheinander angezeigt!");
|
|
121
122
|
|
|
122
|
-
const
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
123
|
+
const deviceIds = Array.from(this.devices.keys());
|
|
124
|
+
const results = [];
|
|
125
|
+
let connected = 0;
|
|
126
|
+
|
|
127
|
+
for (let i = 0; i < deviceIds.length; i++) {
|
|
128
|
+
const deviceId = deviceIds[i];
|
|
129
|
+
|
|
130
|
+
try {
|
|
131
|
+
console.log(`\n📱 Device ${i + 1}/${deviceIds.length}: '${deviceId}'`);
|
|
132
|
+
console.log("⏳ Scanne den QR-Code für dieses Device...");
|
|
133
|
+
|
|
134
|
+
await this.connectDevice(deviceId);
|
|
135
|
+
connected++;
|
|
136
|
+
results.push({ deviceId, status: 'connected' });
|
|
137
|
+
|
|
138
|
+
console.log(`✅ Device '${deviceId}' verbunden! Weiter zum nächsten...`);
|
|
139
|
+
|
|
140
|
+
// Kurze Pause zwischen Devices
|
|
141
|
+
if (i < deviceIds.length - 1) {
|
|
142
|
+
console.log("⏸️ 3 Sekunden Pause...");
|
|
143
|
+
await new Promise(resolve => setTimeout(resolve, 3000));
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
} catch (error) {
|
|
147
|
+
console.error(`❌ Device '${deviceId}' fehlgeschlagen:`, error.message);
|
|
148
|
+
results.push({ deviceId, status: 'failed', error: error.message });
|
|
149
|
+
|
|
150
|
+
// Weiter mit nächstem Device
|
|
151
|
+
console.log("➡️ Weiter mit nächstem Device...");
|
|
152
|
+
await new Promise(resolve => setTimeout(resolve, 2000));
|
|
153
|
+
}
|
|
154
|
+
}
|
|
131
155
|
|
|
156
|
+
console.log(`\n🎉 Alle Devices verarbeitet!`);
|
|
132
157
|
console.log(`✅ ${connected}/${this.devices.size} Devices erfolgreich verbunden`);
|
|
133
158
|
|
|
134
159
|
if (connected === 0) {
|
package/src/easy-bot.js
CHANGED
|
@@ -28,6 +28,22 @@ export class EasyBot {
|
|
|
28
28
|
bot.client = new WhatsAppClient({
|
|
29
29
|
authDir: "./auth",
|
|
30
30
|
logLevel: "silent",
|
|
31
|
+
|
|
32
|
+
// CLEAN QR DEFAULTS - NEU!
|
|
33
|
+
printQR: false, // Browser QR bevorzugt
|
|
34
|
+
qrSpamPrevention: true, // Anti-Spam aktiviert
|
|
35
|
+
qrDisplayInterval: 30000, // 30s zwischen Terminal QR
|
|
36
|
+
qrMaxDisplays: 3, // Max 3 Terminal QR
|
|
37
|
+
clearTerminalOnQR: true, // Terminal bei QR leeren
|
|
38
|
+
|
|
39
|
+
// ROBUSTE CONNECTION DEFAULTS - NEU!
|
|
40
|
+
maxReconnectAttempts: 100, // Viele Versuche für 24/7
|
|
41
|
+
reconnectInterval: 2000, // Schnellere Wiederverbindung
|
|
42
|
+
exponentialBackoff: true,
|
|
43
|
+
maxBackoffDelay: 30000, // Max 30 Sekunden
|
|
44
|
+
heartbeatInterval: 20000, // 20 Sekunden Heartbeat
|
|
45
|
+
connectionTimeout: 180000, // 3 Minuten Timeout
|
|
46
|
+
keepAlive: true,
|
|
31
47
|
...options
|
|
32
48
|
});
|
|
33
49
|
return bot;
|
|
@@ -39,6 +55,14 @@ export class EasyBot {
|
|
|
39
55
|
bot.multiClient = new MultiWhatsAppClient({
|
|
40
56
|
maxDevices: deviceCount,
|
|
41
57
|
loadBalancing: 'round-robin',
|
|
58
|
+
// ROBUSTE CONNECTION DEFAULTS - NEU!
|
|
59
|
+
maxReconnectAttempts: 100,
|
|
60
|
+
reconnectInterval: 2000,
|
|
61
|
+
exponentialBackoff: true,
|
|
62
|
+
maxBackoffDelay: 30000,
|
|
63
|
+
heartbeatInterval: 20000,
|
|
64
|
+
connectionTimeout: 180000,
|
|
65
|
+
keepAlive: true,
|
|
42
66
|
...options
|
|
43
67
|
});
|
|
44
68
|
return bot;
|
|
@@ -48,6 +72,17 @@ export class EasyBot {
|
|
|
48
72
|
return EasyBot.create().enableDefaults();
|
|
49
73
|
}
|
|
50
74
|
|
|
75
|
+
// ROBUSTE CONNECTION FACTORY - NEU!
|
|
76
|
+
static createRobust(options = {}) {
|
|
77
|
+
return EasyBot.create({
|
|
78
|
+
maxReconnectAttempts: 200, // Noch mehr Versuche
|
|
79
|
+
reconnectInterval: 1000, // Sehr schnelle Wiederverbindung
|
|
80
|
+
heartbeatInterval: 15000, // 15 Sekunden Heartbeat
|
|
81
|
+
connectionTimeout: 300000, // 5 Minuten Timeout
|
|
82
|
+
...options
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
|
|
51
86
|
// ===== SIMPLE RULES =====
|
|
52
87
|
|
|
53
88
|
when(trigger) {
|
|
@@ -289,6 +324,54 @@ export class EasyBot {
|
|
|
289
324
|
return this;
|
|
290
325
|
}
|
|
291
326
|
|
|
327
|
+
// Ignore API für EasyBot - DEINE NEUE FUNKTION!
|
|
328
|
+
ignoreOfflineMessages(enabled = true) {
|
|
329
|
+
if (this.client) {
|
|
330
|
+
this.client.ignore.message.offline(enabled);
|
|
331
|
+
} else if (this.multiClient) {
|
|
332
|
+
// Für Multi-Client später implementieren
|
|
333
|
+
console.log("⚠️ Offline Message Ignore für Multi-Client noch nicht verfügbar");
|
|
334
|
+
}
|
|
335
|
+
return this;
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
// ROBUSTE CONNECTION API - NEU!
|
|
339
|
+
enableRobustConnection(enabled = true) {
|
|
340
|
+
if (this.client) {
|
|
341
|
+
// Robuste Einstellungen aktivieren
|
|
342
|
+
this.client.options.maxReconnectAttempts = enabled ? 200 : 50;
|
|
343
|
+
this.client.options.reconnectInterval = enabled ? 1000 : 3000;
|
|
344
|
+
this.client.options.heartbeatInterval = enabled ? 15000 : 30000;
|
|
345
|
+
this.client.options.connectionTimeout = enabled ? 300000 : 120000;
|
|
346
|
+
console.log(`💪 Robuste Verbindung ${enabled ? 'AKTIVIERT' : 'DEAKTIVIERT'}`);
|
|
347
|
+
}
|
|
348
|
+
return this;
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
setReconnectAttempts(attempts) {
|
|
352
|
+
if (this.client) {
|
|
353
|
+
this.client.options.maxReconnectAttempts = attempts;
|
|
354
|
+
console.log(`🔄 Max Wiederverbindungsversuche: ${attempts}`);
|
|
355
|
+
}
|
|
356
|
+
return this;
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
setHeartbeatInterval(interval) {
|
|
360
|
+
if (this.client) {
|
|
361
|
+
this.client.options.heartbeatInterval = interval;
|
|
362
|
+
console.log(`💓 Heartbeat Interval: ${interval / 1000}s`);
|
|
363
|
+
}
|
|
364
|
+
return this;
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
enableUltraRobust() {
|
|
368
|
+
return this
|
|
369
|
+
.enableRobustConnection(true)
|
|
370
|
+
.setReconnectAttempts(500) // Sehr viele Versuche
|
|
371
|
+
.setHeartbeatInterval(10000) // 10 Sekunden Heartbeat
|
|
372
|
+
.enableAutoRestart(true, 2000); // 2 Sekunden Restart-Delay
|
|
373
|
+
}
|
|
374
|
+
|
|
292
375
|
// ===== MULTI-DEVICE SETUP =====
|
|
293
376
|
|
|
294
377
|
async addDevice(deviceId, options = {}) {
|
|
@@ -455,21 +538,29 @@ export class EasyBot {
|
|
|
455
538
|
}
|
|
456
539
|
}
|
|
457
540
|
|
|
458
|
-
async sendReply(msg, text) {
|
|
541
|
+
async sendReply(msg, text, mentions = []) {
|
|
459
542
|
try {
|
|
460
543
|
if (this.isMultiDevice) {
|
|
461
544
|
const client = this.multiClient.getNextDevice();
|
|
462
545
|
if (client && client.socket) {
|
|
463
|
-
|
|
546
|
+
const messageObj = { text: String(text) };
|
|
547
|
+
if (mentions.length > 0) {
|
|
548
|
+
messageObj.mentions = mentions;
|
|
549
|
+
}
|
|
550
|
+
await client.socket.sendMessage(msg.from, messageObj);
|
|
464
551
|
} else {
|
|
465
552
|
throw new Error('Kein verfügbarer Multi-Device Client');
|
|
466
553
|
}
|
|
467
554
|
} else {
|
|
468
555
|
if (msg.reply && typeof msg.reply === 'function') {
|
|
469
|
-
await msg.reply(String(text));
|
|
556
|
+
await msg.reply(String(text), mentions);
|
|
470
557
|
} else {
|
|
471
558
|
// Fallback: Direct client call
|
|
472
|
-
|
|
559
|
+
const messageObj = { text: String(text) };
|
|
560
|
+
if (mentions.length > 0) {
|
|
561
|
+
messageObj.mentions = mentions;
|
|
562
|
+
}
|
|
563
|
+
await this.client.socket.sendMessage(msg.from, messageObj);
|
|
473
564
|
}
|
|
474
565
|
}
|
|
475
566
|
} catch (error) {
|
|
@@ -477,7 +568,11 @@ export class EasyBot {
|
|
|
477
568
|
// Fallback attempt
|
|
478
569
|
try {
|
|
479
570
|
if (this.client && this.client.socket) {
|
|
480
|
-
|
|
571
|
+
const messageObj = { text: String(text) };
|
|
572
|
+
if (mentions.length > 0) {
|
|
573
|
+
messageObj.mentions = mentions;
|
|
574
|
+
}
|
|
575
|
+
await this.client.socket.sendMessage(msg.from, messageObj);
|
|
481
576
|
}
|
|
482
577
|
} catch (fallbackError) {
|
|
483
578
|
console.error("❌ Auch Fallback fehlgeschlagen:", fallbackError.message);
|
|
@@ -771,6 +866,22 @@ class EasyRule {
|
|
|
771
866
|
return this;
|
|
772
867
|
}
|
|
773
868
|
|
|
869
|
+
// Neue Mention + Typing Kombinationen
|
|
870
|
+
slowTypeWithMention(text) {
|
|
871
|
+
this.actions.push({ type: 'slowTypeWithMention', value: text });
|
|
872
|
+
return this;
|
|
873
|
+
}
|
|
874
|
+
|
|
875
|
+
quickTypeWithMention(text) {
|
|
876
|
+
this.actions.push({ type: 'quickTypeWithMention', value: text });
|
|
877
|
+
return this;
|
|
878
|
+
}
|
|
879
|
+
|
|
880
|
+
normalTypeWithMention(text) {
|
|
881
|
+
this.actions.push({ type: 'normalTypeWithMention', value: text });
|
|
882
|
+
return this;
|
|
883
|
+
}
|
|
884
|
+
|
|
774
885
|
// Delete actions
|
|
775
886
|
deleteMessage() {
|
|
776
887
|
this.actions.push({ type: 'delete' });
|
|
@@ -1046,13 +1157,99 @@ class EasyRule {
|
|
|
1046
1157
|
break;
|
|
1047
1158
|
|
|
1048
1159
|
case 'mentionSender':
|
|
1049
|
-
// Implementierung für mentionSender
|
|
1050
|
-
|
|
1160
|
+
// Verbesserte Implementierung für mentionSender
|
|
1161
|
+
try {
|
|
1162
|
+
if (msg.replyWithMention && typeof msg.replyWithMention === 'function') {
|
|
1163
|
+
await msg.replyWithMention(action.value, msg.getSender());
|
|
1164
|
+
} else {
|
|
1165
|
+
// Fallback
|
|
1166
|
+
const senderName = msg.getSender().split('@')[0];
|
|
1167
|
+
const mentionText = action.value.replace('@user', `@${senderName}`);
|
|
1168
|
+
await this.bot.sendReply(msg, mentionText, [msg.getSender()]);
|
|
1169
|
+
}
|
|
1170
|
+
} catch (error) {
|
|
1171
|
+
console.error('❌ Fehler bei mentionSender:', error.message);
|
|
1172
|
+
await this.bot.sendReply(msg, action.value);
|
|
1173
|
+
}
|
|
1051
1174
|
break;
|
|
1052
1175
|
|
|
1053
1176
|
case 'mentionAll':
|
|
1054
|
-
// Implementierung für mentionAll
|
|
1055
|
-
|
|
1177
|
+
// Verbesserte Implementierung für mentionAll
|
|
1178
|
+
try {
|
|
1179
|
+
if (msg.mentionAll && typeof msg.mentionAll === 'function') {
|
|
1180
|
+
await msg.mentionAll(action.value);
|
|
1181
|
+
} else {
|
|
1182
|
+
await this.bot.sendReply(msg, action.value);
|
|
1183
|
+
}
|
|
1184
|
+
} catch (error) {
|
|
1185
|
+
console.error('❌ Fehler bei mentionAll:', error.message);
|
|
1186
|
+
await this.bot.sendReply(msg, action.value);
|
|
1187
|
+
}
|
|
1188
|
+
break;
|
|
1189
|
+
|
|
1190
|
+
case 'mentionUser':
|
|
1191
|
+
// Implementierung für mentionUser
|
|
1192
|
+
try {
|
|
1193
|
+
if (msg.replyWithMention && typeof msg.replyWithMention === 'function') {
|
|
1194
|
+
await msg.replyWithMention(action.value.text, action.value.userJid);
|
|
1195
|
+
} else {
|
|
1196
|
+
await this.bot.sendReply(msg, action.value.text);
|
|
1197
|
+
}
|
|
1198
|
+
} catch (error) {
|
|
1199
|
+
console.error('❌ Fehler bei mentionUser:', error.message);
|
|
1200
|
+
await this.bot.sendReply(msg, action.value.text);
|
|
1201
|
+
}
|
|
1202
|
+
break;
|
|
1203
|
+
|
|
1204
|
+
case 'slowTypeWithMention':
|
|
1205
|
+
// Neue Funktion: Slow Type mit Mention
|
|
1206
|
+
try {
|
|
1207
|
+
if (msg.slowTypeWithMention && typeof msg.slowTypeWithMention === 'function') {
|
|
1208
|
+
await msg.slowTypeWithMention(action.value, msg.getSender());
|
|
1209
|
+
} else {
|
|
1210
|
+
// Fallback
|
|
1211
|
+
const senderName = msg.getSender().split('@')[0];
|
|
1212
|
+
const mentionText = action.value.replace('@user', `@${senderName}`);
|
|
1213
|
+
await this.bot.typeMessage(msg, 4000);
|
|
1214
|
+
await this.bot.sendReply(msg, mentionText, [msg.getSender()]);
|
|
1215
|
+
}
|
|
1216
|
+
} catch (error) {
|
|
1217
|
+
console.error('❌ Fehler bei slowTypeWithMention:', error.message);
|
|
1218
|
+
}
|
|
1219
|
+
break;
|
|
1220
|
+
|
|
1221
|
+
case 'quickTypeWithMention':
|
|
1222
|
+
// Neue Funktion: Quick Type mit Mention
|
|
1223
|
+
try {
|
|
1224
|
+
if (msg.quickTypeWithMention && typeof msg.quickTypeWithMention === 'function') {
|
|
1225
|
+
await msg.quickTypeWithMention(action.value, msg.getSender());
|
|
1226
|
+
} else {
|
|
1227
|
+
// Fallback
|
|
1228
|
+
const senderName = msg.getSender().split('@')[0];
|
|
1229
|
+
const mentionText = action.value.replace('@user', `@${senderName}`);
|
|
1230
|
+
await this.bot.typeMessage(msg, 1000);
|
|
1231
|
+
await this.bot.sendReply(msg, mentionText, [msg.getSender()]);
|
|
1232
|
+
}
|
|
1233
|
+
} catch (error) {
|
|
1234
|
+
console.error('❌ Fehler bei quickTypeWithMention:', error.message);
|
|
1235
|
+
}
|
|
1236
|
+
break;
|
|
1237
|
+
|
|
1238
|
+
case 'normalTypeWithMention':
|
|
1239
|
+
// Neue Funktion: Normal Type mit Mention
|
|
1240
|
+
try {
|
|
1241
|
+
if (msg.normalTypeWithMention && typeof msg.normalTypeWithMention === 'function') {
|
|
1242
|
+
await msg.normalTypeWithMention(action.value, msg.getSender());
|
|
1243
|
+
} else {
|
|
1244
|
+
// Fallback
|
|
1245
|
+
const senderName = msg.getSender().split('@')[0];
|
|
1246
|
+
const mentionText = action.value.replace('@user', `@${senderName}`);
|
|
1247
|
+
await this.bot.typeMessage(msg, 2000);
|
|
1248
|
+
await this.bot.sendReply(msg, mentionText, [msg.getSender()]);
|
|
1249
|
+
}
|
|
1250
|
+
} catch (error) {
|
|
1251
|
+
console.error('❌ Fehler bei normalTypeWithMention:', error.message);
|
|
1252
|
+
}
|
|
1056
1253
|
break;
|
|
1057
1254
|
|
|
1058
1255
|
case 'mentionUser':
|
package/src/index.js
CHANGED
|
@@ -11,3 +11,7 @@ export { PluginManager } from "./plugin-manager-fixed.js";
|
|
|
11
11
|
export { EasyBot, createBot, createMultiBot, quickBot, bot, multiBot } from "./easy-bot.js";
|
|
12
12
|
export { generateQRCode } from "./qr.js";
|
|
13
13
|
export { Message } from "./message.js";
|
|
14
|
+
|
|
15
|
+
// NEUE ROBUSTE FACTORY METHODS - NEU!
|
|
16
|
+
export const createRobustBot = () => EasyBot.createRobust();
|
|
17
|
+
export const createUltraRobustBot = () => EasyBot.createRobust().enableUltraRobust();
|
package/src/message.js
CHANGED
|
@@ -301,6 +301,25 @@ export class Message {
|
|
|
301
301
|
return await this.reply(mentionText, allMembers);
|
|
302
302
|
}
|
|
303
303
|
|
|
304
|
+
// Mention mit Typing - Neue Funktion für bessere UX
|
|
305
|
+
async slowTypeWithMention(text, userJid) {
|
|
306
|
+
const senderName = userJid.split('@')[0];
|
|
307
|
+
const mentionText = text.replace('@user', `@${senderName}`);
|
|
308
|
+
return await this.slowType(mentionText, [userJid]);
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
async quickTypeWithMention(text, userJid) {
|
|
312
|
+
const senderName = userJid.split('@')[0];
|
|
313
|
+
const mentionText = text.replace('@user', `@${senderName}`);
|
|
314
|
+
return await this.quickType(mentionText, [userJid]);
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
async normalTypeWithMention(text, userJid) {
|
|
318
|
+
const senderName = userJid.split('@')[0];
|
|
319
|
+
const mentionText = text.replace('@user', `@${senderName}`);
|
|
320
|
+
return await this.normalType(mentionText, [userJid]);
|
|
321
|
+
}
|
|
322
|
+
|
|
304
323
|
// ===== PERMISSION SYSTEM =====
|
|
305
324
|
|
|
306
325
|
async isAdmin() {
|
package/src/multi-client.js
CHANGED
|
@@ -7,6 +7,15 @@ export class MultiWhatsAppClient {
|
|
|
7
7
|
maxDevices: options.maxDevices || 3,
|
|
8
8
|
loadBalancing: options.loadBalancing || 'round-robin',
|
|
9
9
|
syncEvents: options.syncEvents !== false,
|
|
10
|
+
|
|
11
|
+
// ROBUSTE CONNECTION DEFAULTS - NEU!
|
|
12
|
+
maxReconnectAttempts: options.maxReconnectAttempts || 100,
|
|
13
|
+
reconnectInterval: options.reconnectInterval || 2000,
|
|
14
|
+
exponentialBackoff: options.exponentialBackoff !== false,
|
|
15
|
+
maxBackoffDelay: options.maxBackoffDelay || 30000,
|
|
16
|
+
heartbeatInterval: options.heartbeatInterval || 20000,
|
|
17
|
+
connectionTimeout: options.connectionTimeout || 180000,
|
|
18
|
+
keepAlive: options.keepAlive !== false,
|
|
10
19
|
...options
|
|
11
20
|
});
|
|
12
21
|
|
|
@@ -17,7 +26,7 @@ export class MultiWhatsAppClient {
|
|
|
17
26
|
// Device Manager Events weiterleiten
|
|
18
27
|
this.setupDeviceManagerEvents();
|
|
19
28
|
|
|
20
|
-
console.log("🚀 MultiWhatsAppClient initialisiert");
|
|
29
|
+
console.log("🚀 MultiWhatsAppClient mit robusten Verbindungen initialisiert");
|
|
21
30
|
}
|
|
22
31
|
|
|
23
32
|
// ===== DEVICE MANAGEMENT =====
|
|
@@ -46,13 +55,61 @@ export class MultiWhatsAppClient {
|
|
|
46
55
|
|
|
47
56
|
async connect(deviceIds = null) {
|
|
48
57
|
if (deviceIds) {
|
|
49
|
-
// Spezifische Devices verbinden
|
|
50
|
-
|
|
51
|
-
return await Promise.allSettled(promises);
|
|
58
|
+
// Spezifische Devices sequenziell verbinden
|
|
59
|
+
return await this.connectDevicesSequentially(deviceIds);
|
|
52
60
|
} else {
|
|
53
|
-
// Alle Devices verbinden
|
|
54
|
-
|
|
61
|
+
// Alle Devices sequenziell verbinden
|
|
62
|
+
const allDeviceIds = Array.from(this.deviceManager.devices.keys());
|
|
63
|
+
return await this.connectDevicesSequentially(allDeviceIds);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// NEUE SEQUENZIELLE VERBINDUNG - Ein QR nach dem anderen!
|
|
68
|
+
async connectDevicesSequentially(deviceIds) {
|
|
69
|
+
console.log(`🔄 Sequenzielle Verbindung von ${deviceIds.length} Devices...`);
|
|
70
|
+
console.log("📱 QR-Codes werden nacheinander angezeigt - scanne einen nach dem anderen!");
|
|
71
|
+
|
|
72
|
+
const results = [];
|
|
73
|
+
let connectedCount = 0;
|
|
74
|
+
|
|
75
|
+
for (let i = 0; i < deviceIds.length; i++) {
|
|
76
|
+
const deviceId = deviceIds[i];
|
|
77
|
+
|
|
78
|
+
try {
|
|
79
|
+
console.log(`\n📱 Device ${i + 1}/${deviceIds.length}: '${deviceId}'`);
|
|
80
|
+
console.log("⏳ Warte auf QR-Scan für dieses Device...");
|
|
81
|
+
|
|
82
|
+
// Verbinde ein Device und warte bis es fertig ist
|
|
83
|
+
const client = await this.deviceManager.connectDevice(deviceId);
|
|
84
|
+
|
|
85
|
+
console.log(`✅ Device '${deviceId}' erfolgreich verbunden!`);
|
|
86
|
+
connectedCount++;
|
|
87
|
+
results.push({ deviceId, status: 'connected', client });
|
|
88
|
+
|
|
89
|
+
// Kurze Pause zwischen Devices
|
|
90
|
+
if (i < deviceIds.length - 1) {
|
|
91
|
+
console.log("⏸️ Kurze Pause vor nächstem Device...");
|
|
92
|
+
await new Promise(resolve => setTimeout(resolve, 2000));
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
} catch (error) {
|
|
96
|
+
console.error(`❌ Device '${deviceId}' Verbindung fehlgeschlagen:`, error.message);
|
|
97
|
+
results.push({ deviceId, status: 'failed', error: error.message });
|
|
98
|
+
|
|
99
|
+
// Frage ob weiter machen
|
|
100
|
+
console.log("❓ Soll mit dem nächsten Device fortgefahren werden? (Automatisch ja in 5s)");
|
|
101
|
+
await new Promise(resolve => setTimeout(resolve, 5000));
|
|
102
|
+
}
|
|
55
103
|
}
|
|
104
|
+
|
|
105
|
+
console.log(`\n🎉 Sequenzielle Verbindung abgeschlossen!`);
|
|
106
|
+
console.log(`✅ ${connectedCount}/${deviceIds.length} Devices erfolgreich verbunden`);
|
|
107
|
+
|
|
108
|
+
if (connectedCount === 0) {
|
|
109
|
+
throw new Error("❌ Keine Devices konnten verbunden werden!");
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
return results;
|
|
56
113
|
}
|
|
57
114
|
|
|
58
115
|
async disconnect(deviceIds = null) {
|