@iobroker/socket-classes 1.4.2 → 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.
@@ -6,65 +6,65 @@ let zipFiles = null;
6
6
  class SocketCommands {
7
7
  static ERROR_PERMISSION = 'permissionError';
8
8
  static COMMANDS_PERMISSIONS = {
9
- getObject: {type: 'object', operation: 'read'},
10
- getObjects: {type: 'object', operation: 'list'},
11
- getObjectView: {type: 'object', operation: 'list'},
12
- setObject: {type: 'object', operation: 'write'},
13
- requireLog: {type: 'object', operation: 'write'}, // just mapping to some command
14
- delObject: {type: 'object', operation: 'delete'},
15
- extendObject: {type: 'object', operation: 'write'},
16
- getHostByIp: {type: 'object', operation: 'list'},
17
- subscribeObjects: {type: 'object', operation: 'read'},
18
- unsubscribeObjects: {type: 'object', operation: 'read'},
19
-
20
- getStates: {type: 'state', operation: 'list'},
21
- getState: {type: 'state', operation: 'read'},
22
- setState: {type: 'state', operation: 'write'},
23
- delState: {type: 'state', operation: 'delete'},
24
- createState: {type: 'state', operation: 'create'},
25
- subscribe: {type: 'state', operation: 'read'},
26
- unsubscribe: {type: 'state', operation: 'read'},
27
- getStateHistory: {type: 'state', operation: 'read'},
28
- getVersion: {type: '', operation: ''},
29
- getAdapterName: {type: '', operation: ''},
30
-
31
- addUser: {type: 'users', operation: 'create'},
32
- delUser: {type: 'users', operation: 'delete'},
33
- addGroup: {type: 'users', operation: 'create'},
34
- delGroup: {type: 'users', operation: 'delete'},
35
- changePassword: {type: 'users', operation: 'write'},
36
-
37
- httpGet: {type: 'other', operation: 'http'},
38
- cmdExec: {type: 'other', operation: 'execute'},
39
- sendTo: {type: 'other', operation: 'sendto'},
40
- sendToHost: {type: 'other', operation: 'sendto'},
41
- readLogs: {type: 'other', operation: 'execute'},
42
-
43
- readDir: {type: 'file', operation: 'list'},
44
- createFile: {type: 'file', operation: 'create'},
45
- writeFile: {type: 'file', operation: 'write'},
46
- readFile: {type: 'file', operation: 'read'},
47
- fileExists: {type: 'file', operation: 'read'},
48
- deleteFile: {type: 'file', operation: 'delete'},
49
- readFile64: {type: 'file', operation: 'read'},
50
- writeFile64: {type: 'file', operation: 'write'},
51
- unlink: {type: 'file', operation: 'delete'},
52
- rename: {type: 'file', operation: 'write'},
53
- mkdir: {type: 'file', operation: 'write'},
54
- chmodFile: {type: 'file', operation: 'write'},
55
- chownFile: {type: 'file', operation: 'write'},
56
- subscribeFiles: {type: 'file', operation: 'read'},
57
- unsubscribeFiles: {type: 'file', operation: 'read'},
58
-
59
- authEnabled: {type: '', operation: ''},
60
- disconnect: {type: '', operation: ''},
61
- listPermissions: {type: '', operation: ''},
62
- getUserPermissions: {type: 'object', operation: 'read'}
9
+ getObject: { type: 'object', operation: 'read' },
10
+ getObjects: { type: 'object', operation: 'list' },
11
+ getObjectView: { type: 'object', operation: 'list' },
12
+ setObject: { type: 'object', operation: 'write' },
13
+ requireLog: { type: 'object', operation: 'write' }, // just mapping to some command
14
+ delObject: { type: 'object', operation: 'delete' },
15
+ extendObject: { type: 'object', operation: 'write' },
16
+ getHostByIp: { type: 'object', operation: 'list' },
17
+ subscribeObjects: { type: 'object', operation: 'read' },
18
+ unsubscribeObjects: { type: 'object', operation: 'read' },
19
+
20
+ getStates: { type: 'state', operation: 'list' },
21
+ getState: { type: 'state', operation: 'read' },
22
+ setState: { type: 'state', operation: 'write' },
23
+ delState: { type: 'state', operation: 'delete' },
24
+ createState: { type: 'state', operation: 'create' },
25
+ subscribe: { type: 'state', operation: 'read' },
26
+ unsubscribe: { type: 'state', operation: 'read' },
27
+ getStateHistory: { type: 'state', operation: 'read' },
28
+ getVersion: { type: '', operation: '' },
29
+ getAdapterName: { type: '', operation: '' },
30
+
31
+ addUser: { type: 'users', operation: 'create' },
32
+ delUser: { type: 'users', operation: 'delete' },
33
+ addGroup: { type: 'users', operation: 'create' },
34
+ delGroup: { type: 'users', operation: 'delete' },
35
+ changePassword: { type: 'users', operation: 'write' },
36
+
37
+ httpGet: { type: 'other', operation: 'http' },
38
+ cmdExec: { type: 'other', operation: 'execute' },
39
+ sendTo: { type: 'other', operation: 'sendto' },
40
+ sendToHost: { type: 'other', operation: 'sendto' },
41
+ readLogs: { type: 'other', operation: 'execute' },
42
+
43
+ readDir: { type: 'file', operation: 'list' },
44
+ createFile: { type: 'file', operation: 'create' },
45
+ writeFile: { type: 'file', operation: 'write' },
46
+ readFile: { type: 'file', operation: 'read' },
47
+ fileExists: { type: 'file', operation: 'read' },
48
+ deleteFile: { type: 'file', operation: 'delete' },
49
+ readFile64: { type: 'file', operation: 'read' },
50
+ writeFile64: { type: 'file', operation: 'write' },
51
+ unlink: { type: 'file', operation: 'delete' },
52
+ rename: { type: 'file', operation: 'write' },
53
+ mkdir: { type: 'file', operation: 'write' },
54
+ chmodFile: { type: 'file', operation: 'write' },
55
+ chownFile: { type: 'file', operation: 'write' },
56
+ subscribeFiles: { type: 'file', operation: 'read' },
57
+ unsubscribeFiles: { type: 'file', operation: 'read' },
58
+
59
+ authEnabled: { type: '', operation: '' },
60
+ disconnect: { type: '', operation: '' },
61
+ listPermissions: { type: '', operation: '' },
62
+ getUserPermissions: { type: 'object', operation: 'read' }
63
63
  };
64
64
 
65
65
  constructor(adapter, updateSession) {
66
- this.adapter = adapter;
67
- this.commands = {};
66
+ this.adapter = adapter;
67
+ this.commands = {};
68
68
  this.subscribes = {};
69
69
  this.logEnabled = false;
70
70
  this.clientSubscribes = {};
@@ -167,11 +167,17 @@ class SocketCommands {
167
167
  if (SocketCommands.COMMANDS_PERMISSIONS[command]) {
168
168
  // If permission required
169
169
  if (SocketCommands.COMMANDS_PERMISSIONS[command].type) {
170
- if (socket._acl[SocketCommands.COMMANDS_PERMISSIONS[command].type] &&
171
- socket._acl[SocketCommands.COMMANDS_PERMISSIONS[command].type][SocketCommands.COMMANDS_PERMISSIONS[command].operation]) {
170
+ if (
171
+ socket._acl[SocketCommands.COMMANDS_PERMISSIONS[command].type] &&
172
+ socket._acl[SocketCommands.COMMANDS_PERMISSIONS[command].type][
173
+ SocketCommands.COMMANDS_PERMISSIONS[command].operation
174
+ ]
175
+ ) {
172
176
  return true;
173
177
  } else {
174
- this.adapter.log.warn(`No permission for "${socket._acl.user}" to call ${command}. Need "${SocketCommands.COMMANDS_PERMISSIONS[command].type}"."${SocketCommands.COMMANDS_PERMISSIONS[command].operation}"`);
178
+ this.adapter.log.warn(
179
+ `No permission for "${socket._acl.user}" to call ${command}. Need "${SocketCommands.COMMANDS_PERMISSIONS[command].type}"."${SocketCommands.COMMANDS_PERMISSIONS[command].operation}"`
180
+ );
175
181
  }
176
182
  } else {
177
183
  return true;
@@ -191,7 +197,7 @@ class SocketCommands {
191
197
  arg
192
198
  });
193
199
  } else {
194
- socket.emit(SocketCommands.ERROR_PERMISSION, {command, arg});
200
+ socket.emit(SocketCommands.ERROR_PERMISSION, { command, arg });
195
201
  }
196
202
  }
197
203
  return false;
@@ -232,7 +238,8 @@ class SocketCommands {
232
238
  }
233
239
 
234
240
  publishInstanceMessage(socket, sourceInstance, messageType, data) {
235
- if (this.clientSubscribes[socket.id] &&
241
+ if (
242
+ this.clientSubscribes[socket.id] &&
236
243
  this.clientSubscribes[socket.id][sourceInstance] &&
237
244
  this.clientSubscribes[socket.id][sourceInstance].includes(messageType)
238
245
  ) {
@@ -241,7 +248,11 @@ class SocketCommands {
241
248
  }
242
249
 
243
250
  // inform instance about missing subscription
244
- this.adapter.sendTo(sourceInstance, 'clientSubscribeError', {type: messageType, sid: socket.id, reason: 'no one subscribed'});
251
+ this.adapter.sendTo(sourceInstance, 'clientSubscribeError', {
252
+ type: messageType,
253
+ sid: socket.id,
254
+ reason: 'no one subscribed'
255
+ });
245
256
  return false;
246
257
  }
247
258
 
@@ -262,7 +273,7 @@ class SocketCommands {
262
273
  return this.logEnabled;
263
274
  }
264
275
 
265
- async subscribe(socket, type, pattern, patternFile) {
276
+ subscribe(socket, type, pattern, patternFile) {
266
277
  if (!pattern) {
267
278
  return this.adapter.log.warn('Empty pattern on subscribe!');
268
279
  }
@@ -282,8 +293,8 @@ class SocketCommands {
282
293
  try {
283
294
  p = pattern2RegEx(key);
284
295
  } catch (e) {
285
- this.adapter.log.error(`Invalid pattern on subscribe: ${e.message}`)
286
- return
296
+ this.adapter.log.error(`Invalid pattern on subscribe: ${e.message}`);
297
+ return;
287
298
  }
288
299
 
289
300
  if (p === null) {
@@ -298,41 +309,32 @@ class SocketCommands {
298
309
  if (s.find(item => item.pattern === key)) {
299
310
  return;
300
311
  }
301
- s.push({pattern: key, regex: new RegExp(p)});
312
+ s.push({ pattern: key, regex: new RegExp(p) });
302
313
  }
303
314
 
304
- const options = socket && socket._acl ? {user: socket._acl.user} : undefined;
315
+ const options = socket && socket._acl ? { user: socket._acl.user } : undefined;
305
316
 
306
317
  if (this.subscribes[type][key] === undefined) {
307
318
  this.subscribes[type][key] = 1;
308
319
  if (type === 'stateChange') {
309
- try {
310
- await this.adapter.subscribeForeignStatesAsync(pattern, options);
311
- } catch (e) {
312
- this.adapter.log.error(`Cannot subscribe "${pattern}": ${e.message}`)
313
- }
320
+ this.adapter.subscribeForeignStatesAsync(pattern, options)
321
+ .catch(e => this.adapter.log.error(`Cannot subscribe "${pattern}": ${e.message}`));
314
322
  } else if (type === 'objectChange') {
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
- }
323
+ this.adapter.subscribeForeignObjectsAsync(pattern, options)
324
+ .catch(e => this.adapter.log.error(`Cannot subscribe "${pattern}": ${e.message}`));
320
325
  } else if (type === 'log') {
321
326
  if (!this.logEnabled && this.adapter.requireLog) {
322
327
  this.logEnabled = true;
323
328
  this.adapter.requireLog(true, options);
324
329
  }
325
330
  } else if (type === 'fileChange' && this.adapter.subscribeForeignFiles) {
326
- try {
327
- await this.adapter.subscribeForeignFiles(pattern, patternFile, options);
328
- } catch (e) {
329
- this.adapter.log.error(`Cannot subscribe "${pattern}": ${e.message}`)
330
- }
331
+ this.adapter.subscribeForeignFiles(pattern, patternFile, options)
332
+ .catch(e => this.adapter.log.error(`Cannot subscribe "${pattern}": ${e.message}`));
331
333
  }
332
334
  } else {
333
335
  this.subscribes[type][key]++;
334
336
  }
335
- };
337
+ }
336
338
 
337
339
  async unsubscribe(socket, type, pattern, patternFile) {
338
340
  if (!pattern) {
@@ -352,7 +354,7 @@ class SocketCommands {
352
354
  key = pattern;
353
355
  }
354
356
 
355
- const options = socket && socket._acl ? {user: socket._acl.user} : undefined;
357
+ const options = socket && socket._acl ? { user: socket._acl.user } : undefined;
356
358
 
357
359
  if (socket && typeof socket === 'object') {
358
360
  if (!socket.subscribe || !socket.subscribe[type]) {
@@ -366,28 +368,19 @@ class SocketCommands {
366
368
  this.subscribes[type][key]--;
367
369
  if (this.subscribes[type][key] <= 0) {
368
370
  if (type === 'stateChange') {
369
- try {
370
- await this.adapter.unsubscribeForeignStatesAsync(pattern, options);
371
- } catch (e) {
372
- this.adapter.log.error(`Cannot unsubscribe "${pattern}": ${e.message}`)
373
- }
371
+ this.adapter.unsubscribeForeignStatesAsync(pattern, options)
372
+ .catch(e => this.adapter.log.error(`Cannot unsubscribe "${pattern}": ${e.message}`));
374
373
  } else if (type === 'objectChange') {
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
- }
374
+ this.adapter.unsubscribeForeignObjectsAsync(pattern, options)
375
+ .catch(e => this.adapter.log.error(`Cannot unsubscribe "${pattern}": ${e.message}`));
380
376
  } else if (type === 'log') {
381
377
  if (this.logEnabled && this.adapter.requireLog) {
382
378
  this.logEnabled = false;
383
379
  this.adapter.requireLog(false, options);
384
380
  }
385
- } else if (type === 'fileChange') {
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
- }
381
+ } else if (type === 'fileChange' && this.adapter.unsubscribeForeignFiles) {
382
+ this.adapter.unsubscribeForeignFiles(pattern, patternFile, options)
383
+ .catch(e => this.adapter.log.error(`Cannot unsubscribe "${pattern}": ${e.message}`));
391
384
  }
392
385
  delete this.subscribes[type][pattern];
393
386
  }
@@ -404,65 +397,47 @@ class SocketCommands {
404
397
  this.subscribes[type][key]--;
405
398
  if (this.subscribes[type][key] <= 0) {
406
399
  if (type === 'stateChange') {
407
- try {
408
- await this.adapter.unsubscribeForeignStatesAsync(pattern, options);
409
- } catch (e) {
410
- this.adapter.log.error(`Cannot unsubscribe "${pattern}": ${e.message}`)
411
- }
400
+ this.adapter.unsubscribeForeignStatesAsync(pattern, options)
401
+ .catch(e => this.adapter.log.error(`Cannot unsubscribe "${pattern}": ${e.message}`));
412
402
  } else if (type === 'objectChange') {
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
- }
403
+ this.adapter.unsubscribeForeignObjectsAsync(pattern, options)
404
+ .catch(e => this.adapter.log.error(`Cannot unsubscribe "${pattern}": ${e.message}`));
418
405
  } else if (type === 'log') {
419
406
  if (this.adapter.requireLog && this.logEnabled) {
420
407
  this.logEnabled = false;
421
408
  this.adapter.requireLog(false, options);
422
409
  }
423
- } else if (type === 'fileChange') {
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
- }
410
+ } else if (type === 'fileChange' && this.adapter.unsubscribeForeignFiles) {
411
+ this.adapter.unsubscribeForeignFiles(pattern, patternFile, options)
412
+ .catch(e => this.adapter.log.error(`Cannot unsubscribe "${pattern}": ${e.message}`));
429
413
  }
430
414
  delete this.subscribes[type][key];
431
415
  }
432
416
  }
433
417
  } else {
434
- for (const pattern of Object.keys(this.subscribes[type])) {
418
+ for (const pattern of Object.keys(this.subscribes[type])) {
435
419
  if (type === 'stateChange') {
436
- try {
437
- await this.adapter.unsubscribeForeignStatesAsync(pattern, options);
438
- } catch (e) {
439
- this.adapter.log.error(`Cannot unsubscribe "${pattern}": ${e.message}`)
440
- }
420
+ this.adapter.unsubscribeForeignStatesAsync(pattern, options)
421
+ .catch(e => this.adapter.log.error(`Cannot unsubscribe "${pattern}": ${e.message}`));
441
422
  } else if (type === 'objectChange') {
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
- }
423
+ this.adapter.unsubscribeForeignObjectsAsync(pattern, options)
424
+ .catch(e => this.adapter.log.error(`Cannot unsubscribe "${pattern}": ${e.message}`));
447
425
  } else if (type === 'log') {
448
426
  // console.log((socket._name || socket.id) + ' requireLog false');
449
427
  if (this.adapter.requireLog && this.logEnabled) {
450
428
  this.logEnabled = false;
451
429
  this.adapter.requireLog(false, options);
452
430
  }
453
- } else if (type === 'fileChange') {
431
+ } else if (type === 'fileChange' && this.adapter.unsubscribeForeignFiles) {
454
432
  const [id, fileName] = pattern.split('####');
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
- }
433
+ this.adapter.unsubscribeForeignFiles(id, fileName, options)
434
+ .catch(e => this.adapter.log.error(`Cannot unsubscribe "${pattern}": ${e.message}`));
460
435
  }
461
436
  }
462
437
 
463
- this.subscribes[type] = {}
438
+ this.subscribes[type] = {};
464
439
  }
465
- };
440
+ }
466
441
 
467
442
  async subscribeSocket(socket, type) {
468
443
  if (!socket || !socket.subscribe) {
@@ -471,44 +446,34 @@ class SocketCommands {
471
446
 
472
447
  if (!type) {
473
448
  // all
474
- return Object.keys(socket.subscribe)
475
- .forEach(type => this.subscribeSocket(socket, type));
449
+ return Object.keys(socket.subscribe).forEach(type => this.subscribeSocket(socket, type));
476
450
  }
477
451
 
478
452
  if (!socket.subscribe[type]) {
479
453
  return;
480
454
  }
481
455
 
482
- const options = socket && socket._acl ? {user: socket._acl.user} : undefined;
456
+ const options = socket && socket._acl ? { user: socket._acl.user } : undefined;
483
457
 
484
458
  for (let i = 0; i < socket.subscribe[type].length; i++) {
485
459
  const pattern = socket.subscribe[type][i].pattern;
486
460
  if (this.subscribes[type][pattern] === undefined) {
487
461
  this.subscribes[type][pattern] = 1;
488
462
  if (type === 'stateChange') {
489
- try {
490
- await this.adapter.subscribeForeignStatesAsync(pattern, options);
491
- } catch (e) {
492
- this.adapter.log.error(`Cannot subscribe "${pattern}": ${e.message}`)
493
- }
463
+ this.adapter.subscribeForeignStatesAsync(pattern, options)
464
+ .catch(e => this.adapter.log.error(`Cannot subscribe "${pattern}": ${e.message}`));
494
465
  } else if (type === 'objectChange') {
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
- }
466
+ this.adapter.subscribeForeignObjectsAsync(pattern, options)
467
+ .catch(e => this.adapter.log.error(`Cannot subscribe "${pattern}": ${e.message}`));
500
468
  } else if (type === 'log') {
501
469
  if (this.adapter.requireLog && !this.logEnabled) {
502
470
  this.logEnabled = true;
503
471
  this.adapter.requireLog(true, options);
504
472
  }
505
- } else if (type === 'fileChange') {
473
+ } else if (type === 'fileChange' && this.adapter.subscribeForeignFiles) {
506
474
  const [id, fileName] = pattern.split('####');
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
- }
475
+ this.adapter.subscribeForeignFiles(id, fileName, options)
476
+ .catch(e => this.adapter.log.error(`Cannot subscribe "${pattern}": ${e.message}`));
512
477
  }
513
478
  } else {
514
479
  this.subscribes[type][pattern]++;
@@ -525,15 +490,14 @@ class SocketCommands {
525
490
 
526
491
  if (!type) {
527
492
  // all
528
- return Object.keys(socket.subscribe)
529
- .forEach(type => this.unsubscribeSocket(socket, type));
493
+ return Object.keys(socket.subscribe).forEach(type => this.unsubscribeSocket(socket, type));
530
494
  }
531
495
 
532
496
  if (!socket.subscribe[type]) {
533
497
  return;
534
498
  }
535
499
 
536
- const options = socket && socket._acl ? {user: socket._acl.user} : undefined;
500
+ const options = socket && socket._acl ? { user: socket._acl.user } : undefined;
537
501
 
538
502
  for (let i = 0; i < socket.subscribe[type].length; i++) {
539
503
  const pattern = socket.subscribe[type][i].pattern;
@@ -541,29 +505,20 @@ class SocketCommands {
541
505
  this.subscribes[type][pattern]--;
542
506
  if (this.subscribes[type][pattern] <= 0) {
543
507
  if (type === 'stateChange') {
544
- try {
545
- await this.adapter.unsubscribeForeignStatesAsync(pattern, options);
546
- } catch (e) {
547
- this.adapter.log.error(`Cannot unsubscribe "${pattern}": ${e.message}`)
548
- }
508
+ this.adapter.unsubscribeForeignStatesAsync(pattern, options)
509
+ .catch(e => this.adapter.log.error(`Cannot unsubscribe "${pattern}": ${e.message}`));
549
510
  } else if (type === 'objectChange') {
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
- }
511
+ this.adapter.unsubscribeForeignObjectsAsync(pattern, options)
512
+ .catch(e => this.adapter.log.error(`Cannot unsubscribe "${pattern}": ${e.message}`));
555
513
  } else if (type === 'log') {
556
514
  if (this.adapter.requireLog && !this.logEnabled) {
557
515
  this.logEnabled = true;
558
516
  this.adapter.requireLog(true, options);
559
517
  }
560
- } else if (type === 'fileChange') {
518
+ } else if (type === 'fileChange' && this.adapter.unsubscribeForeignFiles) {
561
519
  const [id, fileName] = pattern.split('####');
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
- }
520
+ this.adapter.unsubscribeForeignFiles(id, fileName, options)
521
+ .catch(e => this.adapter.log.error(`Cannot unsubscribe "${pattern}": ${e.message}`));
567
522
  }
568
523
  delete this.subscribes[type][pattern];
569
524
  }
@@ -679,7 +634,12 @@ class SocketCommands {
679
634
  obj.common.adminUI.tab = 'html';
680
635
  }
681
636
 
682
- obj.common.adminUI && this.adapter.log.debug(`Please add to "${obj._id.replace(/\.\d+$/, '')}" common.adminUI=${JSON.stringify(obj.common.adminUI)}`);
637
+ obj.common.adminUI &&
638
+ this.adapter.log.debug(
639
+ `Please add to "${obj._id.replace(/\.\d+$/, '')}" common.adminUI=${JSON.stringify(
640
+ obj.common.adminUI
641
+ )}`
642
+ );
683
643
  }
684
644
  }
685
645
 
@@ -736,7 +696,11 @@ class SocketCommands {
736
696
  if (feature === 'INSTANCE_MESSAGES') {
737
697
  SocketCommands._fixCallback(callback, null, true);
738
698
  } else {
739
- SocketCommands._fixCallback(callback, null, this.adapter.supportsFeature && this.adapter.supportsFeature(feature));
699
+ SocketCommands._fixCallback(
700
+ callback,
701
+ null,
702
+ this.adapter.supportsFeature && this.adapter.supportsFeature(feature)
703
+ );
740
704
  }
741
705
  };
742
706
 
@@ -757,7 +721,8 @@ class SocketCommands {
757
721
  options.aggregate = options.aggregate || 'none';
758
722
  try {
759
723
  this.adapter.getHistory(id, options, (error, ...args) =>
760
- SocketCommands._fixCallback(callback, error, ...args));
724
+ SocketCommands._fixCallback(callback, error, ...args)
725
+ );
761
726
  } catch (error) {
762
727
  this.adapter.log.error(`[getHistory] ERROR: ${error.toString()}`);
763
728
  SocketCommands._fixCallback(callback, error);
@@ -779,7 +744,9 @@ class SocketCommands {
779
744
  timeout: 15000,
780
745
  validateStatus: status => status < 400
781
746
  })
782
- .then(result => callback(null, {status: result.status, statusText: result.statusText}, result.data))
747
+ .then(result =>
748
+ callback(null, { status: result.status, statusText: result.statusText }, result.data)
749
+ )
783
750
  .catch(error => callback(error));
784
751
  } catch (error) {
785
752
  callback(error);
@@ -796,17 +763,32 @@ class SocketCommands {
796
763
  // @param {function} callback - `function (result)`
797
764
  if (this._checkPermissions(socket, 'sendTo', callback, command)) {
798
765
  try {
799
- this.adapter.sendTo(adapterInstance, command, message, res =>
800
- typeof callback === 'function' && setImmediate(() =>
801
- callback(res)));
766
+ this.adapter.sendTo(
767
+ adapterInstance,
768
+ command,
769
+ message,
770
+ res => typeof callback === 'function' && setImmediate(() => callback(res))
771
+ );
802
772
  } catch (error) {
803
- typeof callback === 'function' && setImmediate(() => callback({error}));
773
+ typeof callback === 'function' && setImmediate(() => callback({ error }));
804
774
  }
805
775
  }
806
776
  };
807
777
 
808
778
  // following commands are protected and require the extra permissions
809
- const protectedCommands = ['cmdExec', 'getLocationOnDisk', 'getDiagData', 'getDevList', 'delLogs', 'writeDirAsZip', 'writeObjectsAsZip', 'readObjectsAsZip', 'checkLogging', 'updateMultihost', 'rebuildAdapter'];
779
+ const protectedCommands = [
780
+ 'cmdExec',
781
+ 'getLocationOnDisk',
782
+ 'getDiagData',
783
+ 'getDevList',
784
+ 'delLogs',
785
+ 'writeDirAsZip',
786
+ 'writeObjectsAsZip',
787
+ 'readObjectsAsZip',
788
+ 'checkLogging',
789
+ 'updateMultihost',
790
+ 'rebuildAdapter'
791
+ ];
810
792
 
811
793
  this.commands['sendToHost'] = (socket, host, command, message, callback) => {
812
794
  // Send a message to the specific host.
@@ -815,7 +797,14 @@ class SocketCommands {
815
797
  // @param {string} command - command name
816
798
  // @param {object} message - the message is command-specific
817
799
  // @param {function} callback - `function (result)`
818
- if (this._checkPermissions(socket, protectedCommands.includes(command) ? 'cmdExec' : 'sendToHost', callback, command)) {
800
+ if (
801
+ this._checkPermissions(
802
+ socket,
803
+ protectedCommands.includes(command) ? 'cmdExec' : 'sendToHost',
804
+ callback,
805
+ command
806
+ )
807
+ ) {
819
808
  // Try to decode this file locally as redis has a limitation for files bigger than 20MB
820
809
  if (command === 'writeDirAsZip' && message && message.data.length > 1024 * 1024) {
821
810
  let buffer;
@@ -823,7 +812,7 @@ class SocketCommands {
823
812
  buffer = Buffer.from(message.data, 'base64');
824
813
  } catch (error) {
825
814
  this.adapter.log.error(`Cannot convert data: ${error.toString()}`);
826
- return callback && callback({error: `Cannot convert data: ${error.toString()}`});
815
+ return callback && callback({ error: `Cannot convert data: ${error.toString()}` });
827
816
  }
828
817
 
829
818
  zipFiles = zipFiles || utils.commonTools.zipFiles;
@@ -930,8 +919,9 @@ class SocketCommands {
930
919
  // @param {function} callback - `function (error, data, mimeType)`
931
920
  if (this._checkPermissions(socket, 'readFile', callback, fileName)) {
932
921
  try {
933
- this.adapter.readFile(_adapter, fileName, {user: socket._acl.user}, (error, ...args) =>
934
- SocketCommands._fixCallback(callback, error, ...args));
922
+ this.adapter.readFile(_adapter, fileName, { user: socket._acl.user }, (error, ...args) =>
923
+ SocketCommands._fixCallback(callback, error, ...args)
924
+ );
935
925
  } catch (error) {
936
926
  this.adapter.log.error(`[readFile] ERROR: ${error.toString()}`);
937
927
  SocketCommands._fixCallback(callback, error);
@@ -946,11 +936,15 @@ class SocketCommands {
946
936
  // @param {function} callback - `function (error, base64, mimeType)`
947
937
  if (this._checkPermissions(socket, 'readFile64', callback, fileName)) {
948
938
  try {
949
- this.adapter.readFile(_adapter, fileName, {user: socket._acl.user}, (error, buffer, type) => {
939
+ this.adapter.readFile(_adapter, fileName, { user: socket._acl.user }, (error, buffer, type) => {
950
940
  let data64;
951
941
  if (buffer) {
952
942
  try {
953
- if (type === 'application/json' || type === 'application/json5' || fileName.toLowerCase().endsWith('.json5')) {
943
+ if (
944
+ type === 'application/json' ||
945
+ type === 'application/json5' ||
946
+ fileName.toLowerCase().endsWith('.json5')
947
+ ) {
954
948
  data64 = Buffer.from(encodeURIComponent(buffer)).toString('base64');
955
949
  } else {
956
950
  if (typeof buffer === 'string') {
@@ -987,7 +981,7 @@ class SocketCommands {
987
981
  // @param {function} callback - `function (error)`
988
982
  if (typeof options === 'function') {
989
983
  callback = options;
990
- options = {user: socket._acl.user};
984
+ options = { user: socket._acl.user };
991
985
  }
992
986
 
993
987
  options = options || {};
@@ -1002,7 +996,8 @@ class SocketCommands {
1002
996
  try {
1003
997
  const buffer = Buffer.from(data64, 'base64');
1004
998
  this.adapter.writeFile(_adapter, fileName, buffer, options, (error, ...args) =>
1005
- SocketCommands._fixCallback(callback, error, ...args));
999
+ SocketCommands._fixCallback(callback, error, ...args)
1000
+ );
1006
1001
  } catch (error) {
1007
1002
  this.adapter.log.error(`[writeFile64] Cannot convert data: ${error.toString()}`);
1008
1003
  SocketCommands._fixCallback(callback, `Cannot convert data: ${error.toString()}`);
@@ -1021,7 +1016,7 @@ class SocketCommands {
1021
1016
  if (this._checkPermissions(socket, 'writeFile', callback, fileName)) {
1022
1017
  if (typeof options === 'function') {
1023
1018
  callback = options;
1024
- options = {user: socket._acl.user};
1019
+ options = { user: socket._acl.user };
1025
1020
  }
1026
1021
  options = options || {};
1027
1022
  options.user = socket._acl.user;
@@ -1029,7 +1024,8 @@ class SocketCommands {
1029
1024
  // const buffer = Buffer.from(data64, 'base64');
1030
1025
  try {
1031
1026
  this.adapter.writeFile(_adapter, fileName, data, options, (error, ...args) =>
1032
- SocketCommands._fixCallback(callback, error, ...args));
1027
+ SocketCommands._fixCallback(callback, error, ...args)
1028
+ );
1033
1029
  } catch (error) {
1034
1030
  this.adapter.log.error(`[writeFile] ERROR: ${error.toString()}`);
1035
1031
  SocketCommands._fixCallback(callback, error);
@@ -1044,7 +1040,7 @@ class SocketCommands {
1044
1040
  // @param {function} callback - `function (error)`
1045
1041
  if (this._checkPermissions(socket, 'unlink', callback, name)) {
1046
1042
  try {
1047
- this._unlink(_adapter, name, {user: socket._acl.user})
1043
+ this._unlink(_adapter, name, { user: socket._acl.user })
1048
1044
  .then(() => SocketCommands._fixCallback(callback))
1049
1045
  .catch(error => SocketCommands._fixCallback(callback, error));
1050
1046
  } catch (error) {
@@ -1061,8 +1057,9 @@ class SocketCommands {
1061
1057
  // @param {function} callback - `function (error)`
1062
1058
  if (this._checkPermissions(socket, 'unlink', callback, name)) {
1063
1059
  try {
1064
- this.adapter.unlink(_adapter, name, {user: socket._acl.user}, (error, ...args) =>
1065
- SocketCommands._fixCallback(callback, error, ...args));
1060
+ this.adapter.unlink(_adapter, name, { user: socket._acl.user }, (error, ...args) =>
1061
+ SocketCommands._fixCallback(callback, error, ...args)
1062
+ );
1066
1063
  } catch (error) {
1067
1064
  this.adapter.log.error(`[deleteFile] ERROR: ${error.toString()}`);
1068
1065
  SocketCommands._fixCallback(callback, error);
@@ -1077,7 +1074,7 @@ class SocketCommands {
1077
1074
  // @param {function} callback - `function (error)`
1078
1075
  if (this._checkPermissions(socket, 'unlink', callback, name)) {
1079
1076
  try {
1080
- this._unlink(_adapter, name, {user: socket._acl.user})
1077
+ this._unlink(_adapter, name, { user: socket._acl.user })
1081
1078
  .then(() => SocketCommands._fixCallback(callback, null))
1082
1079
  .catch(error => SocketCommands._fixCallback(callback, error));
1083
1080
  } catch (error) {
@@ -1095,8 +1092,9 @@ class SocketCommands {
1095
1092
  // @param {function} callback - `function (error)`
1096
1093
  if (this._checkPermissions(socket, 'rename', callback, oldName)) {
1097
1094
  try {
1098
- this.adapter.rename(_adapter, oldName, newName, {user: socket._acl.user}, (error, ...args) =>
1099
- SocketCommands._fixCallback(callback, error, ...args));
1095
+ this.adapter.rename(_adapter, oldName, newName, { user: socket._acl.user }, (error, ...args) =>
1096
+ SocketCommands._fixCallback(callback, error, ...args)
1097
+ );
1100
1098
  } catch (error) {
1101
1099
  this.adapter.log.error(`[renameFile] ERROR: ${error.toString()}`);
1102
1100
  SocketCommands._fixCallback(callback, error);
@@ -1112,7 +1110,7 @@ class SocketCommands {
1112
1110
  // @param {function} callback - `function (error)`
1113
1111
  if (this._checkPermissions(socket, 'rename', callback, oldName)) {
1114
1112
  try {
1115
- this._rename(_adapter, oldName, newName, {user: socket._acl.user})
1113
+ this._rename(_adapter, oldName, newName, { user: socket._acl.user })
1116
1114
  .then(() => SocketCommands._fixCallback(callback))
1117
1115
  .catch(error => SocketCommands._fixCallback(callback, error));
1118
1116
  } catch (error) {
@@ -1129,8 +1127,9 @@ class SocketCommands {
1129
1127
  // @param {function} callback - `function (error)`
1130
1128
  if (this._checkPermissions(socket, 'mkdir', callback, dirName)) {
1131
1129
  try {
1132
- this.adapter.mkdir(_adapter, dirName, {user: socket._acl.user}, (error, ...args) =>
1133
- SocketCommands._fixCallback(callback, error, ...args));
1130
+ this.adapter.mkdir(_adapter, dirName, { user: socket._acl.user }, (error, ...args) =>
1131
+ SocketCommands._fixCallback(callback, error, ...args)
1132
+ );
1134
1133
  } catch (error) {
1135
1134
  this.adapter.log.error(`[mkdir] ERROR: ${error.toString()}`);
1136
1135
  SocketCommands._fixCallback(callback, error);
@@ -1157,8 +1156,9 @@ class SocketCommands {
1157
1156
 
1158
1157
  if (this._checkPermissions(socket, 'readDir', callback, dirName)) {
1159
1158
  try {
1160
- this.adapter.readDir(_adapter, dirName, {user: socket._acl.user}, (error, ...args) =>
1161
- SocketCommands._fixCallback(callback, error, ...args));
1159
+ this.adapter.readDir(_adapter, dirName, { user: socket._acl.user }, (error, ...args) =>
1160
+ SocketCommands._fixCallback(callback, error, ...args)
1161
+ );
1162
1162
  } catch (error) {
1163
1163
  this.adapter.log.error(`[readDir] ERROR: ${error.toString()}`);
1164
1164
  SocketCommands._fixCallback(callback, error);
@@ -1186,7 +1186,8 @@ class SocketCommands {
1186
1186
  if (this._checkPermissions(socket, 'chmodFile', callback, fileName)) {
1187
1187
  try {
1188
1188
  this.adapter.chmodFile(_adapter, fileName, options, (error, ...args) =>
1189
- SocketCommands._fixCallback(callback, error, ...args));
1189
+ SocketCommands._fixCallback(callback, error, ...args)
1190
+ );
1190
1191
  } catch (error) {
1191
1192
  this.adapter.log.error(`[chmodFile] ERROR: ${error.toString()}`);
1192
1193
  SocketCommands._fixCallback(callback, error);
@@ -1205,7 +1206,8 @@ class SocketCommands {
1205
1206
  options.user = socket._acl.user;
1206
1207
  try {
1207
1208
  this.adapter.chownFile(_adapter, fileName, options, (error, ...args) =>
1208
- SocketCommands._fixCallback(callback, error, ...args));
1209
+ SocketCommands._fixCallback(callback, error, ...args)
1210
+ );
1209
1211
  } catch (error) {
1210
1212
  this.adapter.log.error(`[chownFile] ERROR: ${error.toString()}`);
1211
1213
  SocketCommands._fixCallback(callback, error);
@@ -1220,8 +1222,9 @@ class SocketCommands {
1220
1222
  // @param {function} callback - `function (error, isExist)`
1221
1223
  if (this._checkPermissions(socket, 'fileExists', callback, fileName)) {
1222
1224
  try {
1223
- this.adapter.fileExists(_adapter, fileName, {user: socket._acl.user}, (error, ...args) =>
1224
- SocketCommands._fixCallback(callback, error, ...args));
1225
+ this.adapter.fileExists(_adapter, fileName, { user: socket._acl.user }, (error, ...args) =>
1226
+ SocketCommands._fixCallback(callback, error, ...args)
1227
+ );
1225
1228
  } catch (error) {
1226
1229
  this.adapter.log.error(`[fileExists] ERROR: ${error.toString()}`);
1227
1230
  SocketCommands._fixCallback(callback, error);
@@ -1235,7 +1238,7 @@ class SocketCommands {
1235
1238
  // @param {string} pattern - file name pattern, e.g. `main/*.json`
1236
1239
  // @param {function} callback - `function (error)`
1237
1240
  return this._subscribeFiles(socket, id, pattern, callback);
1238
- }
1241
+ };
1239
1242
 
1240
1243
  this.commands['unsubscribeFiles'] = (socket, id, pattern, callback) => {
1241
1244
  // Unsubscribe from file changes in ioBroker DB
@@ -1244,7 +1247,7 @@ class SocketCommands {
1244
1247
  // @param {function} callback - `function (error)`
1245
1248
 
1246
1249
  return this._unsubscribeFiles(socket, id, pattern, callback);
1247
- }
1250
+ };
1248
1251
 
1249
1252
  this.commands['getAdapterInstances'] = (socket, adapterName, callback) => {
1250
1253
  // Read all instances of the given adapter, or all instances of all adapters if adapterName is not defined
@@ -1252,31 +1255,44 @@ class SocketCommands {
1252
1255
  // @param {function} callback - `function (error, instanceList)`, where instanceList is an array of instance objects, e.g. `{_id: 'system.adapter.history.0', common: {name: 'history', ...}, native: {...}}`
1253
1256
  if (typeof callback === 'function') {
1254
1257
  if (this._checkPermissions(socket, 'getObject', callback)) {
1255
- let _adapterName = adapterName !== undefined && adapterName !== null ? adapterName : this.adapterName || '';
1258
+ let _adapterName =
1259
+ adapterName !== undefined && adapterName !== null ? adapterName : this.adapterName || '';
1256
1260
  if (_adapterName) {
1257
1261
  _adapterName += '.';
1258
1262
  }
1259
1263
  try {
1260
- this.adapter.getObjectView('system', 'instance',
1261
- {startkey: `system.adapter.${_adapterName}`, endkey: `system.adapter.${_adapterName}\u9999`},
1262
- {user: socket._acl.user},
1264
+ this.adapter.getObjectView(
1265
+ 'system',
1266
+ 'instance',
1267
+ {
1268
+ startkey: `system.adapter.${_adapterName}`,
1269
+ endkey: `system.adapter.${_adapterName}\u9999`
1270
+ },
1271
+ { user: socket._acl.user },
1263
1272
  (error, doc) => {
1264
1273
  if (error) {
1265
1274
  callback(error);
1266
1275
  } else {
1267
- callback(null, doc.rows
1268
- .map(item => {
1269
- const obj = item.value;
1270
- if (obj.common) {
1271
- delete obj.common.news;
1272
- }
1273
- this._fixAdminUI(obj);
1274
- return obj;
1275
- })
1276
- .filter(obj => obj && (!adapterName || (obj.common && obj.common.name === adapterName))));
1276
+ callback(
1277
+ null,
1278
+ doc.rows
1279
+ .map(item => {
1280
+ const obj = item.value;
1281
+ if (obj.common) {
1282
+ delete obj.common.news;
1283
+ }
1284
+ this._fixAdminUI(obj);
1285
+ return obj;
1286
+ })
1287
+ .filter(
1288
+ obj =>
1289
+ obj &&
1290
+ (!adapterName || (obj.common && obj.common.name === adapterName))
1291
+ )
1292
+ );
1277
1293
  }
1278
- });
1279
-
1294
+ }
1295
+ );
1280
1296
  } catch (error) {
1281
1297
  this.adapter.log.error(`[getAdapterInstances] ERROR: ${error.toString()}`);
1282
1298
  SocketCommands._fixCallback(callback, error);
@@ -1298,14 +1314,15 @@ class SocketCommands {
1298
1314
  }
1299
1315
  if (typeof callback === 'function') {
1300
1316
  try {
1301
- this.adapter.getForeignStates(pattern || '*', {user: socket._acl.user}, (error, ...args) =>
1302
- SocketCommands._fixCallback(callback, error, ...args));
1317
+ this.adapter.getForeignStates(pattern || '*', { user: socket._acl.user }, (error, ...args) =>
1318
+ SocketCommands._fixCallback(callback, error, ...args)
1319
+ );
1303
1320
  } catch (error) {
1304
1321
  this.adapter.log.error(`[getStates] ERROR: ${error.toString()}`);
1305
1322
  SocketCommands._fixCallback(callback, error);
1306
1323
  }
1307
1324
  } else {
1308
- this.adapter.log.warn('[getStates] Invalid callback')
1325
+ this.adapter.log.warn('[getStates] Invalid callback');
1309
1326
  }
1310
1327
  }
1311
1328
  };
@@ -1317,14 +1334,15 @@ class SocketCommands {
1317
1334
  if (this._checkPermissions(socket, 'getStates', callback)) {
1318
1335
  if (typeof callback === 'function') {
1319
1336
  try {
1320
- this.adapter.getForeignStates(pattern, {user: socket._acl.user}, (error, ...args) =>
1321
- SocketCommands._fixCallback(callback, error, ...args));
1337
+ this.adapter.getForeignStates(pattern, { user: socket._acl.user }, (error, ...args) =>
1338
+ SocketCommands._fixCallback(callback, error, ...args)
1339
+ );
1322
1340
  } catch (error) {
1323
1341
  this.adapter.log.error(`[getForeignStates] ERROR: ${error}`);
1324
1342
  SocketCommands._fixCallback(callback, error);
1325
1343
  }
1326
1344
  } else {
1327
- this.adapter.log.warn('[getForeignStates] Invalid callback')
1345
+ this.adapter.log.warn('[getForeignStates] Invalid callback');
1328
1346
  }
1329
1347
  }
1330
1348
  };
@@ -1339,8 +1357,9 @@ class SocketCommands {
1339
1357
  callback(null, this.states[id]);
1340
1358
  } else {
1341
1359
  try {
1342
- this.adapter.getForeignState(id, {user: socket._acl.user}, (error, ...args) =>
1343
- SocketCommands._fixCallback(callback, error, ...args));
1360
+ this.adapter.getForeignState(id, { user: socket._acl.user }, (error, ...args) =>
1361
+ SocketCommands._fixCallback(callback, error, ...args)
1362
+ );
1344
1363
  } catch (error) {
1345
1364
  this.adapter.log.error(`[getState] ERROR: ${error.toString()}`);
1346
1365
  SocketCommands._fixCallback(callback, error);
@@ -1359,7 +1378,7 @@ class SocketCommands {
1359
1378
  // @param {function} callback - `function (error, state)`, where `state` is an object like `{val: 123, ts: 1663915537418, ack: true, from: 'system.adapter.admin.0', q: 0, lc: 1663915537418, c: 'javascript.0'}`
1360
1379
  if (this._checkPermissions(socket, 'setState', callback, id)) {
1361
1380
  if (typeof state !== 'object') {
1362
- state = {val: state};
1381
+ state = { val: state };
1363
1382
  }
1364
1383
 
1365
1384
  // clear cache
@@ -1368,8 +1387,9 @@ class SocketCommands {
1368
1387
  }
1369
1388
 
1370
1389
  try {
1371
- this.adapter.setForeignState(id, state, {user: socket._acl.user}, (error, ...args) =>
1372
- SocketCommands._fixCallback(callback, error, ...args));
1390
+ this.adapter.setForeignState(id, state, { user: socket._acl.user }, (error, ...args) =>
1391
+ SocketCommands._fixCallback(callback, error, ...args)
1392
+ );
1373
1393
  } catch (error) {
1374
1394
  this.adapter.log.error(`[setState] ERROR: ${error.toString()}`);
1375
1395
  SocketCommands._fixCallback(callback, error);
@@ -1385,23 +1405,27 @@ class SocketCommands {
1385
1405
  if (typeof callback === 'function') {
1386
1406
  try {
1387
1407
  if (this.adapter.getForeignBinaryState) {
1388
- this.adapter.getForeignBinaryState(id, {user: socket._acl.user}, (error, data) => {
1408
+ this.adapter.getForeignBinaryState(id, { user: socket._acl.user }, (error, data) => {
1389
1409
  if (data) {
1390
1410
  try {
1391
1411
  data = Buffer.from(data).toString('base64');
1392
1412
  } catch (error) {
1393
- this.adapter.log.error(`[getBinaryState] Cannot convert data: ${error.toString()}`);
1413
+ this.adapter.log.error(
1414
+ `[getBinaryState] Cannot convert data: ${error.toString()}`
1415
+ );
1394
1416
  }
1395
1417
  }
1396
1418
  SocketCommands._fixCallback(callback, error, data);
1397
1419
  });
1398
1420
  } else {
1399
- this.adapter.getBinaryState(id, {user: socket._acl.user}, (error, data) => {
1421
+ this.adapter.getBinaryState(id, { user: socket._acl.user }, (error, data) => {
1400
1422
  if (data) {
1401
1423
  try {
1402
1424
  data = Buffer.from(data).toString('base64');
1403
1425
  } catch (error) {
1404
- this.adapter.log.error(`[getBinaryState] Cannot convert data: ${error.toString()}`);
1426
+ this.adapter.log.error(
1427
+ `[getBinaryState] Cannot convert data: ${error.toString()}`
1428
+ );
1405
1429
  }
1406
1430
  }
1407
1431
  SocketCommands._fixCallback(callback, error, data);
@@ -1412,7 +1436,7 @@ class SocketCommands {
1412
1436
  SocketCommands._fixCallback(callback, error);
1413
1437
  }
1414
1438
  } else {
1415
- this.adapter.log.warn('[getBinaryState] Invalid callback')
1439
+ this.adapter.log.warn('[getBinaryState] Invalid callback');
1416
1440
  }
1417
1441
  }
1418
1442
  };
@@ -1426,18 +1450,20 @@ class SocketCommands {
1426
1450
  if (typeof callback === 'function') {
1427
1451
  let data = null;
1428
1452
  try {
1429
- data = Buffer.from(base64, 'base64')
1453
+ data = Buffer.from(base64, 'base64');
1430
1454
  } catch (error) {
1431
1455
  this.adapter.log.warn(`[setBinaryState] Cannot convert base64 data: ${error.toString()}`);
1432
1456
  }
1433
1457
 
1434
1458
  try {
1435
1459
  if (this.adapter.setForeignBinaryState) {
1436
- this.adapter.setForeignBinaryState(id, data, {user: socket._acl.user}, (error, ...args) =>
1437
- SocketCommands._fixCallback(callback, error, ...args));
1460
+ this.adapter.setForeignBinaryState(id, data, { user: socket._acl.user }, (error, ...args) =>
1461
+ SocketCommands._fixCallback(callback, error, ...args)
1462
+ );
1438
1463
  } else {
1439
- this.adapter.setBinaryState(id, data, {user: socket._acl.user}, (error, ...args) =>
1440
- SocketCommands._fixCallback(callback, error, ...args));
1464
+ this.adapter.setBinaryState(id, data, { user: socket._acl.user }, (error, ...args) =>
1465
+ SocketCommands._fixCallback(callback, error, ...args)
1466
+ );
1441
1467
  }
1442
1468
  } catch (error) {
1443
1469
  this.adapter.log.error(`[setBinaryState] ERROR: ${error.toString()}`);
@@ -1485,7 +1511,7 @@ class SocketCommands {
1485
1511
  // @param {function} callback - `function (error, obj)`
1486
1512
  if (this._checkPermissions(socket, 'getObject', callback, id)) {
1487
1513
  try {
1488
- this.adapter.getForeignObject(id, {user: socket._acl.user}, (error, obj) => {
1514
+ this.adapter.getForeignObject(id, { user: socket._acl.user }, (error, obj) => {
1489
1515
  // overload language from current instance
1490
1516
  if (this.adapter._language && id === 'system.config' && obj.common) {
1491
1517
  obj.common.language = this.adapter._language;
@@ -1514,8 +1540,9 @@ class SocketCommands {
1514
1540
  if (this._checkPermissions(socket, 'getObject', callback)) {
1515
1541
  if (typeof callback === 'function') {
1516
1542
  try {
1517
- this.adapter.getForeignObjects(list, {user: socket._acl.user}, (error, objs) =>
1518
- SocketCommands._fixCallback(callback, error, objs));
1543
+ this.adapter.getForeignObjects(list, { user: socket._acl.user }, (error, objs) =>
1544
+ SocketCommands._fixCallback(callback, error, objs)
1545
+ );
1519
1546
  } catch (error) {
1520
1547
  this.adapter.log.error(`[getObjects] ERROR: ${error.toString()}`);
1521
1548
  SocketCommands._fixCallback(callback, error);
@@ -1527,24 +1554,38 @@ class SocketCommands {
1527
1554
  } else if (this._checkPermissions(socket, 'getObjects', callback)) {
1528
1555
  try {
1529
1556
  if (typeof callback === 'function') {
1530
- this.adapter.getForeignObjects('*', 'state', 'rooms', {user: socket._acl.user}, async (error, objs) => {
1531
- try {
1532
- const channels = await this.adapter.getForeignObjectsAsync('*', 'channel', null, {user: socket._acl.user});
1533
- const devices = await this.adapter.getForeignObjectsAsync('*', 'device', null, {user: socket._acl.user});
1534
- const enums = await this.adapter.getForeignObjectsAsync('*', 'enum', null, {user: socket._acl.user});
1535
- const config = await this.adapter.getForeignObjectAsync('system.config', {user: socket._acl.user});
1536
- Object.assign(objs, channels, devices, enums);
1537
- objs['system.config'] = config;
1538
- } catch (e) {
1539
- this.adapter.log.error(`[getObjects] ERROR: ${e.toString()}`);
1540
- }
1541
- // overload language
1542
- if (this.adapter._language && objs['system.config'] && objs['system.config'].common) {
1543
- objs['system.config'].common.language = this.adapter._language;
1544
- }
1557
+ this.adapter.getForeignObjects(
1558
+ '*',
1559
+ 'state',
1560
+ 'rooms',
1561
+ { user: socket._acl.user },
1562
+ async (error, objs) => {
1563
+ try {
1564
+ const channels = await this.adapter.getForeignObjectsAsync('*', 'channel', null, {
1565
+ user: socket._acl.user
1566
+ });
1567
+ const devices = await this.adapter.getForeignObjectsAsync('*', 'device', null, {
1568
+ user: socket._acl.user
1569
+ });
1570
+ const enums = await this.adapter.getForeignObjectsAsync('*', 'enum', null, {
1571
+ user: socket._acl.user
1572
+ });
1573
+ const config = await this.adapter.getForeignObjectAsync('system.config', {
1574
+ user: socket._acl.user
1575
+ });
1576
+ Object.assign(objs, channels, devices, enums);
1577
+ objs['system.config'] = config;
1578
+ } catch (e) {
1579
+ this.adapter.log.error(`[getObjects] ERROR: ${e.toString()}`);
1580
+ }
1581
+ // overload language
1582
+ if (this.adapter._language && objs['system.config'] && objs['system.config'].common) {
1583
+ objs['system.config'].common.language = this.adapter._language;
1584
+ }
1545
1585
 
1546
- SocketCommands._fixCallback(callback, error, objs);
1547
- });
1586
+ SocketCommands._fixCallback(callback, error, objs);
1587
+ }
1588
+ );
1548
1589
  } else {
1549
1590
  this.adapter.log.warn('[getObjects] Invalid callback');
1550
1591
  }
@@ -1612,7 +1653,7 @@ class SocketCommands {
1612
1653
  if (typeof callback === 'function') {
1613
1654
  if (this._checkPermissions(socket, 'getObjectView', callback, search)) {
1614
1655
  try {
1615
- this.adapter.getObjectView(design, search, params, {user: socket._acl.user}, callback);
1656
+ this.adapter.getObjectView(design, search, params, { user: socket._acl.user }, callback);
1616
1657
  } catch (error) {
1617
1658
  this.adapter.log.error(`[getObjectView] ERROR: ${error.toString()}`);
1618
1659
  SocketCommands._fixCallback(callback, error);
@@ -1630,8 +1671,9 @@ class SocketCommands {
1630
1671
  // @param {function} callback - `function (error)`
1631
1672
  if (this._checkPermissions(socket, 'setObject', callback, id)) {
1632
1673
  try {
1633
- this.adapter.setForeignObject(id, obj, {user: socket._acl.user}, (error, ...args) =>
1634
- SocketCommands._fixCallback(callback, error, ...args));
1674
+ this.adapter.setForeignObject(id, obj, { user: socket._acl.user }, (error, ...args) =>
1675
+ SocketCommands._fixCallback(callback, error, ...args)
1676
+ );
1635
1677
  } catch (error) {
1636
1678
  this.adapter.log.error(`[setObject] ERROR: ${error.toString()}`);
1637
1679
  SocketCommands._fixCallback(callback, error);
@@ -1648,8 +1690,9 @@ class SocketCommands {
1648
1690
  if (id.startsWith('flot.') || id.startsWith('fullcalendar.')) {
1649
1691
  if (this._checkPermissions(socket, 'delObject', callback, id)) {
1650
1692
  try {
1651
- this.adapter.delForeignObject(id, {user: socket._acl.user}, (error, ...args) =>
1652
- SocketCommands._fixCallback(callback, error, ...args));
1693
+ this.adapter.delForeignObject(id, { user: socket._acl.user }, (error, ...args) =>
1694
+ SocketCommands._fixCallback(callback, error, ...args)
1695
+ );
1653
1696
  } catch (error) {
1654
1697
  this.adapter.log.error(`[delObject] ERROR: ${error.toString()}`);
1655
1698
  SocketCommands._fixCallback(callback, error);
@@ -1681,8 +1724,9 @@ class SocketCommands {
1681
1724
  this.clientSubscribes[sid][targetInstance].push(messageType);
1682
1725
  }
1683
1726
  // inform instance about new subscription
1684
- this.adapter.sendTo(targetInstance, 'clientSubscribe', {type: messageType, sid, data}, result =>
1685
- SocketCommands._fixCallback(callback, null, result));
1727
+ this.adapter.sendTo(targetInstance, 'clientSubscribe', { type: messageType, sid, data }, result =>
1728
+ SocketCommands._fixCallback(callback, null, result)
1729
+ );
1686
1730
  };
1687
1731
 
1688
1732
  this.commands['clientUnsubscribe'] = (socket, targetInstance, messageType, callback) => {
@@ -1701,7 +1745,11 @@ class SocketCommands {
1701
1745
  if (pos !== -1) {
1702
1746
  this.clientSubscribes[sid][targetInstance].splice(pos, 1);
1703
1747
  // inform instance about unsubscription
1704
- this.adapter.sendTo(targetInstance, 'clientUnsubscribe', { type: [messageType], sid, reason: 'client' });
1748
+ this.adapter.sendTo(targetInstance, 'clientUnsubscribe', {
1749
+ type: [messageType],
1750
+ sid,
1751
+ reason: 'client'
1752
+ });
1705
1753
  SocketCommands._fixCallback(callback, null, true);
1706
1754
  return;
1707
1755
  }
@@ -1724,7 +1772,7 @@ class SocketCommands {
1724
1772
  this.adapter.sendTo(targetInstance, 'clientUnsubscribe', {
1725
1773
  type: this.clientSubscribes[socketId][targetInstance],
1726
1774
  sid: socketId,
1727
- reason: 'disconnect',
1775
+ reason: 'disconnect'
1728
1776
  });
1729
1777
  });
1730
1778
  delete this.clientSubscribes[socketId];
@@ -1732,12 +1780,13 @@ class SocketCommands {
1732
1780
  }
1733
1781
 
1734
1782
  applyCommands(socket) {
1735
- Object.keys(this.commands)
1736
- .forEach(command => socket.on(command, (...args) => {
1783
+ Object.keys(this.commands).forEach(command =>
1784
+ socket.on(command, (...args) => {
1737
1785
  if (this._updateSession(socket)) {
1738
1786
  this.commands[command](socket, ...args);
1739
1787
  }
1740
- }));
1788
+ })
1789
+ );
1741
1790
  }
1742
1791
 
1743
1792
  destroy() {