@iobroker/socket-classes 1.4.3 → 1.4.4

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 CHANGED
@@ -978,6 +978,9 @@ Read all instances of the given adapter, or all instances of all adapters if ada
978
978
  -->
979
979
 
980
980
  ## Changelog
981
+ ### 1.4.4 (2023-10-11)
982
+ * (bluefox) Caught errors by subscribe/unsubscribe
983
+
981
984
  ### 1.4.3 (2023-10-07)
982
985
  * (foxriver76) do not await the subscribes anymore
983
986
 
@@ -317,28 +317,19 @@ class SocketCommands {
317
317
  if (this.subscribes[type][key] === undefined) {
318
318
  this.subscribes[type][key] = 1;
319
319
  if (type === 'stateChange') {
320
- try {
321
- this.adapter.subscribeForeignStatesAsync(pattern, options);
322
- } catch (e) {
323
- this.adapter.log.error(`Cannot subscribe "${pattern}": ${e.message}`);
324
- }
320
+ this.adapter.subscribeForeignStatesAsync(pattern, options)
321
+ .catch(e => this.adapter.log.error(`Cannot subscribe "${pattern}": ${e.message}`));
325
322
  } else if (type === 'objectChange') {
326
- try {
327
- this.adapter.subscribeForeignObjectsAsync(pattern, options);
328
- } catch (e) {
329
- this.adapter.log.error(`Cannot subscribe "${pattern}": ${e.message}`);
330
- }
323
+ this.adapter.subscribeForeignObjectsAsync(pattern, options)
324
+ .catch(e => this.adapter.log.error(`Cannot subscribe "${pattern}": ${e.message}`));
331
325
  } else if (type === 'log') {
332
326
  if (!this.logEnabled && this.adapter.requireLog) {
333
327
  this.logEnabled = true;
334
328
  this.adapter.requireLog(true, options);
335
329
  }
336
330
  } else if (type === 'fileChange' && this.adapter.subscribeForeignFiles) {
337
- try {
338
- this.adapter.subscribeForeignFiles(pattern, patternFile, options);
339
- } catch (e) {
340
- this.adapter.log.error(`Cannot subscribe "${pattern}": ${e.message}`);
341
- }
331
+ this.adapter.subscribeForeignFiles(pattern, patternFile, options)
332
+ .catch(e => this.adapter.log.error(`Cannot subscribe "${pattern}": ${e.message}`));
342
333
  }
343
334
  } else {
344
335
  this.subscribes[type][key]++;
@@ -377,28 +368,19 @@ class SocketCommands {
377
368
  this.subscribes[type][key]--;
378
369
  if (this.subscribes[type][key] <= 0) {
379
370
  if (type === 'stateChange') {
380
- try {
381
- this.adapter.unsubscribeForeignStatesAsync(pattern, options);
382
- } catch (e) {
383
- this.adapter.log.error(`Cannot unsubscribe "${pattern}": ${e.message}`);
384
- }
371
+ this.adapter.unsubscribeForeignStatesAsync(pattern, options)
372
+ .catch(e => this.adapter.log.error(`Cannot unsubscribe "${pattern}": ${e.message}`));
385
373
  } else if (type === 'objectChange') {
386
- try {
387
- this.adapter.unsubscribeForeignObjectsAsync(pattern, options);
388
- } catch (e) {
389
- this.adapter.log.error(`Cannot unsubscribe "${pattern}": ${e.message}`);
390
- }
374
+ this.adapter.unsubscribeForeignObjectsAsync(pattern, options)
375
+ .catch(e => this.adapter.log.error(`Cannot unsubscribe "${pattern}": ${e.message}`));
391
376
  } else if (type === 'log') {
392
377
  if (this.logEnabled && this.adapter.requireLog) {
393
378
  this.logEnabled = false;
394
379
  this.adapter.requireLog(false, options);
395
380
  }
396
381
  } else if (type === 'fileChange' && this.adapter.unsubscribeForeignFiles) {
397
- try {
398
- this.adapter.unsubscribeForeignFiles(pattern, patternFile, options);
399
- } catch (e) {
400
- this.adapter.log.error(`Cannot unsubscribe "${pattern}": ${e.message}`);
401
- }
382
+ this.adapter.unsubscribeForeignFiles(pattern, patternFile, options)
383
+ .catch(e => this.adapter.log.error(`Cannot unsubscribe "${pattern}": ${e.message}`));
402
384
  }
403
385
  delete this.subscribes[type][pattern];
404
386
  }
@@ -415,28 +397,19 @@ class SocketCommands {
415
397
  this.subscribes[type][key]--;
416
398
  if (this.subscribes[type][key] <= 0) {
417
399
  if (type === 'stateChange') {
418
- try {
419
- this.adapter.unsubscribeForeignStatesAsync(pattern, options);
420
- } catch (e) {
421
- this.adapter.log.error(`Cannot unsubscribe "${pattern}": ${e.message}`);
422
- }
400
+ this.adapter.unsubscribeForeignStatesAsync(pattern, options)
401
+ .catch(e => this.adapter.log.error(`Cannot unsubscribe "${pattern}": ${e.message}`));
423
402
  } else if (type === 'objectChange') {
424
- try {
425
- this.adapter.unsubscribeForeignObjectsAsync(pattern, options);
426
- } catch (e) {
427
- this.adapter.log.error(`Cannot unsubscribe "${pattern}": ${e.message}`);
428
- }
403
+ this.adapter.unsubscribeForeignObjectsAsync(pattern, options)
404
+ .catch(e => this.adapter.log.error(`Cannot unsubscribe "${pattern}": ${e.message}`));
429
405
  } else if (type === 'log') {
430
406
  if (this.adapter.requireLog && this.logEnabled) {
431
407
  this.logEnabled = false;
432
408
  this.adapter.requireLog(false, options);
433
409
  }
434
410
  } else if (type === 'fileChange' && this.adapter.unsubscribeForeignFiles) {
435
- try {
436
- this.adapter.unsubscribeForeignFiles(pattern, patternFile, options);
437
- } catch (e) {
438
- this.adapter.log.error(`Cannot unsubscribe "${pattern}": ${e.message}`);
439
- }
411
+ this.adapter.unsubscribeForeignFiles(pattern, patternFile, options)
412
+ .catch(e => this.adapter.log.error(`Cannot unsubscribe "${pattern}": ${e.message}`));
440
413
  }
441
414
  delete this.subscribes[type][key];
442
415
  }
@@ -444,17 +417,11 @@ class SocketCommands {
444
417
  } else {
445
418
  for (const pattern of Object.keys(this.subscribes[type])) {
446
419
  if (type === 'stateChange') {
447
- try {
448
- this.adapter.unsubscribeForeignStatesAsync(pattern, options);
449
- } catch (e) {
450
- this.adapter.log.error(`Cannot unsubscribe "${pattern}": ${e.message}`);
451
- }
420
+ this.adapter.unsubscribeForeignStatesAsync(pattern, options)
421
+ .catch(e => this.adapter.log.error(`Cannot unsubscribe "${pattern}": ${e.message}`));
452
422
  } else if (type === 'objectChange') {
453
- try {
454
- this.adapter.unsubscribeForeignObjectsAsync(pattern, options);
455
- } catch (e) {
456
- this.adapter.log.error(`Cannot unsubscribe "${pattern}": ${e.message}`);
457
- }
423
+ this.adapter.unsubscribeForeignObjectsAsync(pattern, options)
424
+ .catch(e => this.adapter.log.error(`Cannot unsubscribe "${pattern}": ${e.message}`));
458
425
  } else if (type === 'log') {
459
426
  // console.log((socket._name || socket.id) + ' requireLog false');
460
427
  if (this.adapter.requireLog && this.logEnabled) {
@@ -463,11 +430,8 @@ class SocketCommands {
463
430
  }
464
431
  } else if (type === 'fileChange' && this.adapter.unsubscribeForeignFiles) {
465
432
  const [id, fileName] = pattern.split('####');
466
- try {
467
- this.adapter.unsubscribeForeignFiles(id, fileName, options);
468
- } catch (e) {
469
- this.adapter.log.error(`Cannot unsubscribe "${pattern}": ${e.message}`);
470
- }
433
+ this.adapter.unsubscribeForeignFiles(id, fileName, options)
434
+ .catch(e => this.adapter.log.error(`Cannot unsubscribe "${pattern}": ${e.message}`));
471
435
  }
472
436
  }
473
437
 
@@ -496,17 +460,11 @@ class SocketCommands {
496
460
  if (this.subscribes[type][pattern] === undefined) {
497
461
  this.subscribes[type][pattern] = 1;
498
462
  if (type === 'stateChange') {
499
- try {
500
- this.adapter.subscribeForeignStatesAsync(pattern, options);
501
- } catch (e) {
502
- this.adapter.log.error(`Cannot subscribe "${pattern}": ${e.message}`);
503
- }
463
+ this.adapter.subscribeForeignStatesAsync(pattern, options)
464
+ .catch(e => this.adapter.log.error(`Cannot subscribe "${pattern}": ${e.message}`));
504
465
  } else if (type === 'objectChange') {
505
- try {
506
- this.adapter.subscribeForeignObjectsAsync(pattern, options);
507
- } catch (e) {
508
- this.adapter.log.error(`Cannot subscribe "${pattern}": ${e.message}`);
509
- }
466
+ this.adapter.subscribeForeignObjectsAsync(pattern, options)
467
+ .catch(e => this.adapter.log.error(`Cannot subscribe "${pattern}": ${e.message}`));
510
468
  } else if (type === 'log') {
511
469
  if (this.adapter.requireLog && !this.logEnabled) {
512
470
  this.logEnabled = true;
@@ -514,11 +472,8 @@ class SocketCommands {
514
472
  }
515
473
  } else if (type === 'fileChange' && this.adapter.subscribeForeignFiles) {
516
474
  const [id, fileName] = pattern.split('####');
517
- try {
518
- this.adapter.subscribeForeignFiles(id, fileName, options);
519
- } catch (e) {
520
- this.adapter.log.error(`Cannot subscribe "${pattern}": ${e.message}`);
521
- }
475
+ this.adapter.subscribeForeignFiles(id, fileName, options)
476
+ .catch(e => this.adapter.log.error(`Cannot subscribe "${pattern}": ${e.message}`));
522
477
  }
523
478
  } else {
524
479
  this.subscribes[type][pattern]++;
@@ -550,17 +505,11 @@ class SocketCommands {
550
505
  this.subscribes[type][pattern]--;
551
506
  if (this.subscribes[type][pattern] <= 0) {
552
507
  if (type === 'stateChange') {
553
- try {
554
- this.adapter.unsubscribeForeignStatesAsync(pattern, options);
555
- } catch (e) {
556
- this.adapter.log.error(`Cannot unsubscribe "${pattern}": ${e.message}`);
557
- }
508
+ this.adapter.unsubscribeForeignStatesAsync(pattern, options)
509
+ .catch(e => this.adapter.log.error(`Cannot unsubscribe "${pattern}": ${e.message}`));
558
510
  } else if (type === 'objectChange') {
559
- try {
560
- this.adapter.unsubscribeForeignObjectsAsync(pattern, options);
561
- } catch (e) {
562
- this.adapter.log.error(`Cannot unsubscribe "${pattern}": ${e.message}`);
563
- }
511
+ this.adapter.unsubscribeForeignObjectsAsync(pattern, options)
512
+ .catch(e => this.adapter.log.error(`Cannot unsubscribe "${pattern}": ${e.message}`));
564
513
  } else if (type === 'log') {
565
514
  if (this.adapter.requireLog && !this.logEnabled) {
566
515
  this.logEnabled = true;
@@ -568,11 +517,8 @@ class SocketCommands {
568
517
  }
569
518
  } else if (type === 'fileChange' && this.adapter.unsubscribeForeignFiles) {
570
519
  const [id, fileName] = pattern.split('####');
571
- try {
572
- this.adapter.unsubscribeForeignFiles(id, fileName, options);
573
- } catch (e) {
574
- this.adapter.log.error(`Cannot unsubscribe "${pattern}": ${e.message}`);
575
- }
520
+ this.adapter.unsubscribeForeignFiles(id, fileName, options)
521
+ .catch(e => this.adapter.log.error(`Cannot unsubscribe "${pattern}": ${e.message}`));
576
522
  }
577
523
  delete this.subscribes[type][pattern];
578
524
  }
@@ -326,13 +326,17 @@ class SocketCommandsAdmin extends SocketCommands {
326
326
  this.eventsThreshold.timeActivated = 0;
327
327
  this.adapter.log.info('Subscribe to all states again');
328
328
 
329
- setTimeout(() => {
329
+ setTimeout(async () => {
330
330
  this.onThresholdChanged && this.onThresholdChanged(false);
331
- this.adapter.unsubscribeForeignStates('system.adapter.*');
331
+ try {
332
+ await this.adapter.unsubscribeForeignStatesAsync('system.adapter.*');
333
+ } catch (e) {
334
+ this.adapter.log.error(`Cannot unsubscribe "system.adapter.*": ${e.message}`);
335
+ }
332
336
 
333
337
  for (const pattern of Object.keys(this.subscribes.stateChange)) {
334
338
  try {
335
- this.adapter.subscribeForeignStatesAsync(pattern);
339
+ await this.adapter.subscribeForeignStatesAsync(pattern);
336
340
  } catch (e) {
337
341
  this.adapter.log.error(`Cannot subscribe "${pattern}": ${e.message}`);
338
342
  }
@@ -345,7 +349,7 @@ class SocketCommandsAdmin extends SocketCommands {
345
349
  if (!this.eventsThreshold.active) {
346
350
  this.eventsThreshold.active = true;
347
351
 
348
- setTimeout(() => {
352
+ setTimeout(async () => {
349
353
  this.adapter.log.info(
350
354
  `Unsubscribe from all states, except system's, because over ${this.eventsThreshold.repeatSeconds} seconds the number of events is over ${this.eventsThreshold.value} (in last second ${this.eventsThreshold.count})`
351
355
  );
@@ -355,13 +359,17 @@ class SocketCommandsAdmin extends SocketCommands {
355
359
 
356
360
  for (const pattern of Object.keys(this.subscribes.stateChange)) {
357
361
  try {
358
- this.adapter.unsubscribeForeignStatesAsync(pattern);
362
+ await this.adapter.unsubscribeForeignStatesAsync(pattern);
359
363
  } catch (e) {
360
364
  this.adapter.log.error(`Cannot unsubscribe "${pattern}": ${e.message}`);
361
365
  }
362
366
  }
363
367
 
364
- this.adapter.subscribeForeignStates('system.adapter.*');
368
+ try {
369
+ await this.adapter.subscribeForeignStatesAsync('system.adapter.*');
370
+ } catch (e) {
371
+ this.adapter.log.error(`Cannot subscribe "system.adapter.*": ${e.message}`);
372
+ }
365
373
  }, 100);
366
374
  }
367
375
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@iobroker/socket-classes",
3
- "version": "1.4.3",
3
+ "version": "1.4.4",
4
4
  "description": "ioBroker server-side web sockets",
5
5
  "author": {
6
6
  "name": "bluefox",