@iobroker/socket-classes 1.3.3 → 1.4.1
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 +6 -0
- package/lib/socketAdmin.js +1 -1
- package/lib/socketCommands.js +101 -35
- package/lib/socketCommandsAdmin.js +16 -21
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -978,6 +978,12 @@ 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.1 (2023-09-12)
|
|
982
|
+
* (foxriver76) do not cancel follow subscribes if one subscribe has an error
|
|
983
|
+
|
|
984
|
+
### 1.4.0 (2023-09-11)
|
|
985
|
+
* (foxriver76) fixed crash on invalid patterns with js-controller version 5
|
|
986
|
+
|
|
981
987
|
### 1.3.3 (2023-08-01)
|
|
982
988
|
* (bluefox) Implemented subscribes of a client on messages from specific instance
|
|
983
989
|
* (bluefox) Moved checkFeatureSupported to regular connection and not only admin
|
package/lib/socketAdmin.js
CHANGED
package/lib/socketCommands.js
CHANGED
|
@@ -262,7 +262,7 @@ class SocketCommands {
|
|
|
262
262
|
return this.logEnabled;
|
|
263
263
|
}
|
|
264
264
|
|
|
265
|
-
subscribe(socket, type, pattern, patternFile) {
|
|
265
|
+
async subscribe(socket, type, pattern, patternFile) {
|
|
266
266
|
if (!pattern) {
|
|
267
267
|
return this.adapter.log.warn('Empty pattern on subscribe!');
|
|
268
268
|
}
|
|
@@ -306,23 +306,35 @@ class SocketCommands {
|
|
|
306
306
|
if (this.subscribes[type][key] === undefined) {
|
|
307
307
|
this.subscribes[type][key] = 1;
|
|
308
308
|
if (type === 'stateChange') {
|
|
309
|
-
|
|
309
|
+
try {
|
|
310
|
+
await this.adapter.subscribeForeignStatesAsync(pattern, options);
|
|
311
|
+
} catch (e) {
|
|
312
|
+
this.adapter.log.error(`Cannot subscribe "${pattern}": ${e.message}`)
|
|
313
|
+
}
|
|
310
314
|
} else if (type === 'objectChange') {
|
|
311
|
-
|
|
315
|
+
try {
|
|
316
|
+
this.adapter.subscribeForeignObjects && await this.adapter.subscribeForeignObjects(pattern, options);
|
|
317
|
+
} catch (e) {
|
|
318
|
+
this.adapter.log.error(`Cannot subscribe "${pattern}": ${e.message}`)
|
|
319
|
+
}
|
|
312
320
|
} else if (type === 'log') {
|
|
313
321
|
if (!this.logEnabled && this.adapter.requireLog) {
|
|
314
322
|
this.logEnabled = true;
|
|
315
323
|
this.adapter.requireLog(true, options);
|
|
316
324
|
}
|
|
317
325
|
} else if (type === 'fileChange' && this.adapter.subscribeForeignFiles) {
|
|
318
|
-
|
|
326
|
+
try {
|
|
327
|
+
await this.adapter.subscribeForeignFiles(pattern, patternFile, options);
|
|
328
|
+
} catch (e) {
|
|
329
|
+
this.adapter.log.error(`Cannot subscribe "${pattern}": ${e.message}`)
|
|
330
|
+
}
|
|
319
331
|
}
|
|
320
332
|
} else {
|
|
321
333
|
this.subscribes[type][key]++;
|
|
322
334
|
}
|
|
323
335
|
};
|
|
324
336
|
|
|
325
|
-
unsubscribe(socket, type, pattern, patternFile) {
|
|
337
|
+
async unsubscribe(socket, type, pattern, patternFile) {
|
|
326
338
|
if (!pattern) {
|
|
327
339
|
return this.adapter.log.warn('Empty pattern on subscribe!');
|
|
328
340
|
}
|
|
@@ -349,25 +361,33 @@ class SocketCommands {
|
|
|
349
361
|
|
|
350
362
|
for (let i = socket.subscribe[type].length - 1; i >= 0; i--) {
|
|
351
363
|
if (socket.subscribe[type][i].pattern === key) {
|
|
352
|
-
// Remove pattern from global list
|
|
364
|
+
// Remove a pattern from a global list
|
|
353
365
|
if (this.subscribes[type][key] !== undefined) {
|
|
354
366
|
this.subscribes[type][key]--;
|
|
355
367
|
if (this.subscribes[type][key] <= 0) {
|
|
356
368
|
if (type === 'stateChange') {
|
|
357
|
-
|
|
358
|
-
|
|
369
|
+
try {
|
|
370
|
+
await this.adapter.unsubscribeForeignStatesAsync(pattern, options);
|
|
371
|
+
} catch (e) {
|
|
372
|
+
this.adapter.log.error(`Cannot unsubscribe "${pattern}": ${e.message}`)
|
|
373
|
+
}
|
|
359
374
|
} else if (type === 'objectChange') {
|
|
360
|
-
|
|
361
|
-
|
|
375
|
+
try {
|
|
376
|
+
this.adapter.unsubscribeForeignObjects && await this.adapter.unsubscribeForeignObjectsAsync(pattern, options);
|
|
377
|
+
} catch (e) {
|
|
378
|
+
this.adapter.log.error(`Cannot unsubscribe "${pattern}": ${e.message}`)
|
|
379
|
+
}
|
|
362
380
|
} else if (type === 'log') {
|
|
363
|
-
//console.log((socket._name || socket.id) + ' requireLog false');
|
|
364
381
|
if (this.logEnabled && this.adapter.requireLog) {
|
|
365
382
|
this.logEnabled = false;
|
|
366
383
|
this.adapter.requireLog(false, options);
|
|
367
384
|
}
|
|
368
385
|
} else if (type === 'fileChange') {
|
|
369
|
-
|
|
370
|
-
|
|
386
|
+
try {
|
|
387
|
+
this.adapter.unsubscribeForeignFiles && await this.adapter.unsubscribeForeignFiles(pattern, patternFile, options);
|
|
388
|
+
} catch (e) {
|
|
389
|
+
this.adapter.log.error(`Cannot unsubscribe "${pattern}": ${e.message}`)
|
|
390
|
+
}
|
|
371
391
|
}
|
|
372
392
|
delete this.subscribes[type][pattern];
|
|
373
393
|
}
|
|
@@ -384,45 +404,67 @@ class SocketCommands {
|
|
|
384
404
|
this.subscribes[type][key]--;
|
|
385
405
|
if (this.subscribes[type][key] <= 0) {
|
|
386
406
|
if (type === 'stateChange') {
|
|
387
|
-
|
|
407
|
+
try {
|
|
408
|
+
await this.adapter.unsubscribeForeignStatesAsync(pattern, options);
|
|
409
|
+
} catch (e) {
|
|
410
|
+
this.adapter.log.error(`Cannot unsubscribe "${pattern}": ${e.message}`)
|
|
411
|
+
}
|
|
388
412
|
} else if (type === 'objectChange') {
|
|
389
|
-
|
|
413
|
+
try {
|
|
414
|
+
this.adapter.unsubscribeForeignObjects && await this.adapter.unsubscribeForeignObjectsAsync(pattern, options);
|
|
415
|
+
} catch (e) {
|
|
416
|
+
this.adapter.log.error(`Cannot unsubscribe "${pattern}": ${e.message}`)
|
|
417
|
+
}
|
|
390
418
|
} else if (type === 'log') {
|
|
391
419
|
if (this.adapter.requireLog && this.logEnabled) {
|
|
392
420
|
this.logEnabled = false;
|
|
393
421
|
this.adapter.requireLog(false, options);
|
|
394
422
|
}
|
|
395
423
|
} else if (type === 'fileChange') {
|
|
396
|
-
|
|
424
|
+
try {
|
|
425
|
+
this.adapter.unsubscribeForeignFiles && await this.adapter.unsubscribeForeignFiles(pattern, patternFile, options);
|
|
426
|
+
} catch (e) {
|
|
427
|
+
this.adapter.log.error(`Cannot unsubscribe "${pattern}": ${e.message}`)
|
|
428
|
+
}
|
|
397
429
|
}
|
|
398
430
|
delete this.subscribes[type][key];
|
|
399
431
|
}
|
|
400
432
|
}
|
|
401
433
|
} else {
|
|
402
|
-
|
|
434
|
+
for (const pattern of Object.keys(this.subscribes[type])) {
|
|
403
435
|
if (type === 'stateChange') {
|
|
404
|
-
|
|
405
|
-
|
|
436
|
+
try {
|
|
437
|
+
await this.adapter.unsubscribeForeignStatesAsync(pattern, options);
|
|
438
|
+
} catch (e) {
|
|
439
|
+
this.adapter.log.error(`Cannot unsubscribe "${pattern}": ${e.message}`)
|
|
440
|
+
}
|
|
406
441
|
} else if (type === 'objectChange') {
|
|
407
|
-
|
|
408
|
-
|
|
442
|
+
try {
|
|
443
|
+
this.adapter.unsubscribeForeignObjects && await this.adapter.unsubscribeForeignObjectsAsync(pattern, options);
|
|
444
|
+
} catch (e) {
|
|
445
|
+
this.adapter.log.error(`Cannot unsubscribe "${pattern}": ${e.message}`)
|
|
446
|
+
}
|
|
409
447
|
} else if (type === 'log') {
|
|
410
|
-
//console.log((socket._name || socket.id) + ' requireLog false');
|
|
448
|
+
// console.log((socket._name || socket.id) + ' requireLog false');
|
|
411
449
|
if (this.adapter.requireLog && this.logEnabled) {
|
|
412
450
|
this.logEnabled = false;
|
|
413
451
|
this.adapter.requireLog(false, options);
|
|
414
452
|
}
|
|
415
453
|
} else if (type === 'fileChange') {
|
|
416
454
|
const [id, fileName] = pattern.split('####');
|
|
417
|
-
|
|
455
|
+
try {
|
|
456
|
+
this.adapter.unsubscribeForeignFiles && await this.adapter.unsubscribeForeignFiles(id, fileName, options);
|
|
457
|
+
} catch (e) {
|
|
458
|
+
this.adapter.log.error(`Cannot unsubscribe "${pattern}": ${e.message}`)
|
|
459
|
+
}
|
|
418
460
|
}
|
|
419
|
-
}
|
|
461
|
+
}
|
|
420
462
|
|
|
421
463
|
this.subscribes[type] = {}
|
|
422
464
|
}
|
|
423
465
|
};
|
|
424
466
|
|
|
425
|
-
subscribeSocket(socket, type) {
|
|
467
|
+
async subscribeSocket(socket, type) {
|
|
426
468
|
if (!socket || !socket.subscribe) {
|
|
427
469
|
return;
|
|
428
470
|
}
|
|
@@ -444,9 +486,17 @@ class SocketCommands {
|
|
|
444
486
|
if (this.subscribes[type][pattern] === undefined) {
|
|
445
487
|
this.subscribes[type][pattern] = 1;
|
|
446
488
|
if (type === 'stateChange') {
|
|
447
|
-
|
|
489
|
+
try {
|
|
490
|
+
await this.adapter.subscribeForeignStatesAsync(pattern, options);
|
|
491
|
+
} catch (e) {
|
|
492
|
+
this.adapter.log.error(`Cannot subscribe "${pattern}": ${e.message}`)
|
|
493
|
+
}
|
|
448
494
|
} else if (type === 'objectChange') {
|
|
449
|
-
|
|
495
|
+
try {
|
|
496
|
+
this.adapter.subscribeForeignObjects && await this.adapter.subscribeForeignObjectsAsync(pattern, options);
|
|
497
|
+
} catch (e) {
|
|
498
|
+
this.adapter.log.error(`Cannot subscribe "${pattern}": ${e.message}`)
|
|
499
|
+
}
|
|
450
500
|
} else if (type === 'log') {
|
|
451
501
|
if (this.adapter.requireLog && !this.logEnabled) {
|
|
452
502
|
this.logEnabled = true;
|
|
@@ -454,7 +504,11 @@ class SocketCommands {
|
|
|
454
504
|
}
|
|
455
505
|
} else if (type === 'fileChange') {
|
|
456
506
|
const [id, fileName] = pattern.split('####');
|
|
457
|
-
|
|
507
|
+
try {
|
|
508
|
+
this.adapter.subscribeForeignFiles && await this.adapter.subscribeForeignFiles(id, fileName, options);
|
|
509
|
+
} catch (e) {
|
|
510
|
+
this.adapter.log.error(`Cannot subscribe "${pattern}": ${e.message}`)
|
|
511
|
+
}
|
|
458
512
|
}
|
|
459
513
|
} else {
|
|
460
514
|
this.subscribes[type][pattern]++;
|
|
@@ -462,7 +516,7 @@ class SocketCommands {
|
|
|
462
516
|
}
|
|
463
517
|
}
|
|
464
518
|
|
|
465
|
-
unsubscribeSocket(socket, type) {
|
|
519
|
+
async unsubscribeSocket(socket, type) {
|
|
466
520
|
if (!socket || !socket.subscribe) {
|
|
467
521
|
return;
|
|
468
522
|
}
|
|
@@ -487,9 +541,17 @@ class SocketCommands {
|
|
|
487
541
|
this.subscribes[type][pattern]--;
|
|
488
542
|
if (this.subscribes[type][pattern] <= 0) {
|
|
489
543
|
if (type === 'stateChange') {
|
|
490
|
-
|
|
544
|
+
try {
|
|
545
|
+
await this.adapter.unsubscribeForeignStatesAsync(pattern, options);
|
|
546
|
+
} catch (e) {
|
|
547
|
+
this.adapter.log.error(`Cannot unsubscribe "${pattern}": ${e.message}`)
|
|
548
|
+
}
|
|
491
549
|
} else if (type === 'objectChange') {
|
|
492
|
-
|
|
550
|
+
try {
|
|
551
|
+
this.adapter.unsubscribeForeignObjects && await this.adapter.unsubscribeForeignObjectsAsync(pattern, options);
|
|
552
|
+
} catch (e) {
|
|
553
|
+
this.adapter.log.error(`Cannot unsubscribe "${pattern}": ${e.message}`)
|
|
554
|
+
}
|
|
493
555
|
} else if (type === 'log') {
|
|
494
556
|
if (this.adapter.requireLog && !this.logEnabled) {
|
|
495
557
|
this.logEnabled = true;
|
|
@@ -497,7 +559,11 @@ class SocketCommands {
|
|
|
497
559
|
}
|
|
498
560
|
} else if (type === 'fileChange') {
|
|
499
561
|
const [id, fileName] = pattern.split('####');
|
|
500
|
-
|
|
562
|
+
try {
|
|
563
|
+
this.adapter.unsubscribeForeignFiles && await this.adapter.unsubscribeForeignFiles(id, fileName, options);
|
|
564
|
+
} catch (e) {
|
|
565
|
+
this.adapter.log.error(`Cannot unsubscribe "${pattern}": ${e.message}`)
|
|
566
|
+
}
|
|
501
567
|
}
|
|
502
568
|
delete this.subscribes[type][pattern];
|
|
503
569
|
}
|
|
@@ -523,7 +589,7 @@ class SocketCommands {
|
|
|
523
589
|
|
|
524
590
|
_unsubscribeStates(socket, pattern, callback) {
|
|
525
591
|
if (this._checkPermissions(socket, 'unsubscribe', callback, pattern)) {
|
|
526
|
-
if (pattern
|
|
592
|
+
if (Array.isArray(pattern)) {
|
|
527
593
|
for (let p = 0; p < pattern.length; p++) {
|
|
528
594
|
this.unsubscribe(socket, 'stateChange', pattern[p]);
|
|
529
595
|
}
|
|
@@ -1495,7 +1561,7 @@ class SocketCommands {
|
|
|
1495
1561
|
// @param {function} callback - `function (error)`
|
|
1496
1562
|
if (this._checkPermissions(socket, 'subscribeObjects', callback, pattern)) {
|
|
1497
1563
|
try {
|
|
1498
|
-
if (pattern
|
|
1564
|
+
if (Array.isArray(pattern)) {
|
|
1499
1565
|
for (let p = 0; p < pattern.length; p++) {
|
|
1500
1566
|
this.subscribe(socket, 'objectChange', pattern[p]);
|
|
1501
1567
|
}
|
|
@@ -1519,7 +1585,7 @@ class SocketCommands {
|
|
|
1519
1585
|
// @param {function} callback - `function (error)`
|
|
1520
1586
|
if (this._checkPermissions(socket, 'unsubscribeObjects', callback, pattern)) {
|
|
1521
1587
|
try {
|
|
1522
|
-
if (pattern
|
|
1588
|
+
if (Array.isArray(pattern)) {
|
|
1523
1589
|
for (let p = 0; p < pattern.length; p++) {
|
|
1524
1590
|
this.unsubscribe(socket, 'objectChange', pattern[p]);
|
|
1525
1591
|
}
|
|
@@ -277,26 +277,17 @@ class SocketCommandsAdmin extends SocketCommands {
|
|
|
277
277
|
this.eventsThreshold.timeActivated = 0;
|
|
278
278
|
this.adapter.log.info('Subscribe to all states again');
|
|
279
279
|
|
|
280
|
-
setTimeout(() => {
|
|
281
|
-
/*
|
|
282
|
-
if (readAll) {
|
|
283
|
-
this.adapter.getForeignStates('*', (error, res) => {
|
|
284
|
-
this.adapter.log.info('received all states');
|
|
285
|
-
for (const id in res) {
|
|
286
|
-
if (res.hasOwnProperty(id) && JSON.stringify(states[id]) !== JSON.stringify(res[id])) {
|
|
287
|
-
this.server.sockets.emit('stateChange', id, res[id]);
|
|
288
|
-
states[id] = res[id];
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
|
-
});
|
|
292
|
-
}
|
|
293
|
-
*/
|
|
294
|
-
|
|
280
|
+
setTimeout(async() => {
|
|
295
281
|
this.onThresholdChanged && this.onThresholdChanged(false);
|
|
296
282
|
this.adapter.unsubscribeForeignStates('system.adapter.*');
|
|
297
283
|
|
|
298
|
-
Object.keys(this.subscribes.stateChange)
|
|
299
|
-
|
|
284
|
+
for (const pattern of Object.keys(this.subscribes.stateChange)) {
|
|
285
|
+
try {
|
|
286
|
+
await this.adapter.subscribeForeignStatesAsync(pattern)
|
|
287
|
+
} catch (e) {
|
|
288
|
+
this.adapter.log.error(`Cannot subscribe "${pattern}": ${e.message}`)
|
|
289
|
+
}
|
|
290
|
+
}
|
|
300
291
|
}, 50);
|
|
301
292
|
}
|
|
302
293
|
}
|
|
@@ -305,15 +296,19 @@ class SocketCommandsAdmin extends SocketCommands {
|
|
|
305
296
|
if (!this.eventsThreshold.active) {
|
|
306
297
|
this.eventsThreshold.active = true;
|
|
307
298
|
|
|
308
|
-
setTimeout(() => {
|
|
299
|
+
setTimeout(async () => {
|
|
309
300
|
this.adapter.log.info(`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})`);
|
|
310
301
|
this.eventsThreshold.timeActivated = Date.now();
|
|
311
302
|
|
|
312
303
|
this.onThresholdChanged && this.onThresholdChanged(true);
|
|
313
|
-
//this.server && this.server.sockets && this.server.sockets.emit('eventsThreshold', true);
|
|
314
304
|
|
|
315
|
-
Object.keys(this.subscribes.stateChange)
|
|
316
|
-
|
|
305
|
+
for (const pattern of Object.keys(this.subscribes.stateChange)) {
|
|
306
|
+
try {
|
|
307
|
+
await this.adapter.unsubscribeForeignStatesAsync(pattern)
|
|
308
|
+
} catch (e) {
|
|
309
|
+
this.adapter.log.error(`Cannot unsubscribe "${pattern}": ${e.message}`)
|
|
310
|
+
}
|
|
311
|
+
}
|
|
317
312
|
|
|
318
313
|
this.adapter.subscribeForeignStates('system.adapter.*');
|
|
319
314
|
}, 100);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@iobroker/socket-classes",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.1",
|
|
4
4
|
"description": "ioBroker server-side web sockets",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "bluefox",
|
|
@@ -24,14 +24,14 @@
|
|
|
24
24
|
"@iobroker/adapter-core": "^3.0.3",
|
|
25
25
|
"passport": "^0.6.0",
|
|
26
26
|
"cookie-parser": "^1.4.6",
|
|
27
|
-
"axios": "^1.
|
|
27
|
+
"axios": "^1.5.0"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
30
|
"@alcalzone/release-script": "^3.6.0",
|
|
31
31
|
"@alcalzone/release-script-plugin-license": "^3.5.9",
|
|
32
32
|
"iobroker.js-controller": "dev",
|
|
33
33
|
"gulp": "^4.0.2",
|
|
34
|
-
"chai": "^4.3.
|
|
34
|
+
"chai": "^4.3.8",
|
|
35
35
|
"mocha": "^10.2.0"
|
|
36
36
|
},
|
|
37
37
|
"bugs": {
|