@iobroker/socket-classes 1.1.5 → 1.3.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.
@@ -70,7 +70,7 @@ class SocketCommandsAdmin extends SocketCommands {
70
70
  }
71
71
 
72
72
  try {
73
- const response = await axios.get('https://rating.iobroker.net/rating?uuid=' + uuid, {timeout: 15000, validateStatus: status => status < 400})
73
+ const response = await axios.get(`https://rating.iobroker.net/rating?uuid=${uuid}`, {timeout: 15000, validateStatus: status => status < 400})
74
74
  this.adapter._ratings = response.data;
75
75
  if (!this.adapter._ratings || typeof this.adapter._ratings !== 'object' || Array.isArray(this.adapter._ratings)) {
76
76
  this.adapter._ratings = {};
@@ -95,7 +95,7 @@ class SocketCommandsAdmin extends SocketCommands {
95
95
 
96
96
  _readInstanceConfig(id, user, isTab, configs) {
97
97
  return new Promise(resolve =>
98
- this.adapter.getForeignObject('system.adapter.' + id, {user}, (error, obj) => {
98
+ this.adapter.getForeignObject(`system.adapter.${id}`, {user}, (error, obj) => {
99
99
  if (obj && obj.common) {
100
100
  const instance = id.split('.').pop();
101
101
  const config = {
@@ -103,7 +103,7 @@ class SocketCommandsAdmin extends SocketCommands {
103
103
  title: obj.common.titleLang || obj.common.title,
104
104
  desc: obj.common.desc,
105
105
  color: obj.common.color,
106
- url: `/adapter/${obj.common.name}/${isTab ? 'tab' : 'index'}${!isTab && obj.common.materialize ? '_m' : ''}.html${instance ? '?' + instance : ''}`,
106
+ url: `/adapter/${obj.common.name}/${isTab ? 'tab' : 'index'}${!isTab && obj.common.materialize ? '_m' : ''}.html${instance ? `?${instance}` : ''}`,
107
107
  icon: obj.common.icon,
108
108
  materialize: obj.common.materialize,
109
109
  jsonConfig: obj.common.jsonConfig,
@@ -157,7 +157,7 @@ class SocketCommandsAdmin extends SocketCommands {
157
157
  typeof callback === 'function' && setImmediate(() => callback(res));
158
158
  });
159
159
  } catch (error) {
160
- this.adapter.log.error('[sendToHost] ERROR: ' + error.toString());
160
+ this.adapter.log.error(`[sendToHost] ERROR: ${error.toString()}`);
161
161
  typeof callback === 'function' && setImmediate(() => callback({ error }));
162
162
  }
163
163
  }
@@ -275,7 +275,7 @@ class SocketCommandsAdmin extends SocketCommands {
275
275
  this.eventsThreshold.count = 0;
276
276
  this.eventsThreshold.active = false;
277
277
  this.eventsThreshold.timeActivated = 0;
278
- this.adapter.log.info('Subscribe on all states again');
278
+ this.adapter.log.info('Subscribe to all states again');
279
279
 
280
280
  setTimeout(() => {
281
281
  /*
@@ -331,12 +331,12 @@ class SocketCommandsAdmin extends SocketCommands {
331
331
  }
332
332
 
333
333
  try {
334
- this.adapter.getForeignObject('system.user.' + user, options, (error, obj) => {
334
+ this.adapter.getForeignObject(`system.user.${user}`, options, (error, obj) => {
335
335
  if (obj) {
336
336
  SocketCommands._fixCallback(callback, 'User yet exists');
337
337
  } else {
338
338
  try {
339
- this.adapter.setForeignObject('system.user.' + user, {
339
+ this.adapter.setForeignObject(`system.user.${user}`, {
340
340
  type: 'user',
341
341
  common: {
342
342
  name: user,
@@ -347,25 +347,25 @@ class SocketCommandsAdmin extends SocketCommands {
347
347
  try {
348
348
  this.adapter.setPassword(user, pw, options, callback);
349
349
  } catch (error) {
350
- this.adapter.log.error('[_addUser] cannot set password: ' + error.toString());
350
+ this.adapter.log.error(`[_addUser] cannot set password: ${error.toString()}`);
351
351
  SocketCommands._fixCallback(callback, error);
352
352
  }
353
353
  });
354
354
  } catch (error) {
355
- this.adapter.log.error('[_addUser] cannot save user: ' + error.toString());
355
+ this.adapter.log.error(`[_addUser] cannot save user: ${error.toString()}`);
356
356
  SocketCommands._fixCallback(callback, error);
357
357
  }
358
358
  }
359
359
  });
360
360
  } catch (error) {
361
- this.adapter.log.error('[_addUser] cannot read user: ' + error.toString());
361
+ this.adapter.log.error(`[_addUser] cannot read user: ${error.toString()}`);
362
362
  SocketCommands._fixCallback(callback, error);
363
363
  }
364
364
  }
365
365
 
366
366
  _delUser(user, options, callback) {
367
367
  try {
368
- this.adapter.getForeignObject('system.user.' + user, options, (error, obj) => {
368
+ this.adapter.getForeignObject(`system.user.${user}`, options, (error, obj) => {
369
369
  if (error || !obj) {
370
370
  SocketCommands._fixCallback(callback, 'User does not exist');
371
371
  } else {
@@ -373,18 +373,18 @@ class SocketCommandsAdmin extends SocketCommands {
373
373
  SocketCommands._fixCallback(callback, 'Cannot delete user, while is system user');
374
374
  } else {
375
375
  try {
376
- this.adapter.delForeignObject('system.user.' + user, options, error =>
376
+ this.adapter.delForeignObject(`system.user.${user}`, options, error =>
377
377
  // Remove this user from all groups in web client
378
378
  SocketCommands._fixCallback(callback, error));
379
379
  } catch (error) {
380
- this.adapter.log.error('[_delUser] cannot delete user: ' + error.toString());
380
+ this.adapter.log.error(`[_delUser] cannot delete user: ${error.toString()}`);
381
381
  SocketCommands._fixCallback(callback, error);
382
382
  }
383
383
  }
384
384
  }
385
385
  });
386
386
  } catch (error) {
387
- this.adapter.log.error('[_delUser] cannot read user: ' + error.toString());
387
+ this.adapter.log.error(`[_delUser] cannot read user: ${error.toString()}`);
388
388
  SocketCommands._fixCallback(callback, error);
389
389
  }
390
390
  }
@@ -437,14 +437,14 @@ class SocketCommandsAdmin extends SocketCommands {
437
437
  }
438
438
  });
439
439
  } catch (error) {
440
- this.adapter.log.error('[_addGroup] cannot read group: ' + error.toString());
440
+ this.adapter.log.error(`[_addGroup] cannot read group: ${error.toString()}`);
441
441
  SocketCommands._fixCallback(callback, error);
442
442
  }
443
443
  }
444
444
 
445
445
  _delGroup(group, options, callback) {
446
446
  try {
447
- this.adapter.getForeignObject('system.group.' + group, options, (error, obj) => {
447
+ this.adapter.getForeignObject(`system.group.${group}`, options, (error, obj) => {
448
448
  if (error || !obj) {
449
449
  SocketCommands._fixCallback(callback, 'Group does not exist');
450
450
  } else {
@@ -453,7 +453,7 @@ class SocketCommandsAdmin extends SocketCommands {
453
453
  } else {
454
454
  try {
455
455
  this.adapter.delForeignObject(`system.group.${group}`, options, error =>
456
- // Remove this group from all users in web client
456
+ // Remove this group from all users in the web client
457
457
  SocketCommands._fixCallback(callback, error));
458
458
  } catch (error) {
459
459
  this.adapter.log.error(`[_delGroup] cannot delete group: ${error.toString()}`);
@@ -463,13 +463,13 @@ class SocketCommandsAdmin extends SocketCommands {
463
463
  }
464
464
  });
465
465
  } catch (error) {
466
- this.adapter.log.error('[_delGroup] cannot read group: ' + error.toString());
466
+ this.adapter.log.error(`[_delGroup] cannot read group: ${error.toString()}`);
467
467
  SocketCommands._fixCallback(callback, error);
468
468
  }
469
469
  }
470
470
 
471
471
  static _checkObject(obj, options, flag) {
472
- // read rights of object
472
+ // read rights of the object
473
473
  if (!obj || !obj.common || !obj.acl || flag === 'list') {
474
474
  return true;
475
475
  }
@@ -572,7 +572,7 @@ class SocketCommandsAdmin extends SocketCommands {
572
572
  };
573
573
 
574
574
  this.commands['addGroup'] = (socket, group, desc, acl, callback) => {
575
- // Add new group.
575
+ // Add a new group.
576
576
  // @param {string} group - user name, like 'benjamin
577
577
  // @param {string} desc - optional description
578
578
  // @param {object} acl - optional access control list object, like `{"object":{"list":true,"read":true,"write":false,"delete":false},"state":{"list":true,"read":true,"write":true,"create":true,"delete":false},"users":{"list":true,"read":true,"write":false,"create":false,"delete":false},"other":{"execute":false,"http":true,"sendto":false},"file":{"list":true,"read":true,"write":false,"create":false,"delete":false}}`
@@ -584,7 +584,7 @@ class SocketCommandsAdmin extends SocketCommands {
584
584
  };
585
585
 
586
586
  this.commands['delGroup'] = (socket, group, callback) => {
587
- // Delete existing group. Administrator group cannot be deleted.
587
+ // Delete the existing group. Administrator group cannot be deleted.
588
588
  // @param {string} group - group name, like 'users`
589
589
  // @param {function} callback - `function (error)`
590
590
  if (this._checkPermissions(socket, 'delGroup', callback, group)) {
@@ -603,7 +603,7 @@ class SocketCommandsAdmin extends SocketCommands {
603
603
  this.adapter.setPassword(user, pass, {user: socket._acl.user}, (error, ...args) =>
604
604
  SocketCommands._fixCallback(callback, error, ...args));
605
605
  } catch (error) {
606
- this.adapter.log.error('[_changePassword] ERROR: ' + error.toString());
606
+ this.adapter.log.error(`[_changePassword] ERROR: ${error.toString()}`);
607
607
  SocketCommands._fixCallback(callback, error);
608
608
  }
609
609
  }
@@ -612,9 +612,9 @@ class SocketCommandsAdmin extends SocketCommands {
612
612
 
613
613
  _initCommandsAdmin() {
614
614
  this.commands['getHostByIp'] = (socket, ip, callback) => {
615
- // Read host object by IP address
615
+ // Read the host object by IP address
616
616
  // @param {string} ip - ip address. IPv4 or IPv6
617
- // @param {function} callback - `function (ip, obj)`. If host not found, obj is null
617
+ // @param {function} callback - `function (ip, obj)`. If host is not found, obj is null
618
618
  if (typeof callback !== 'function') {
619
619
  return this.adapter.log.warn('[getHostByIp] Invalid callback');
620
620
  }
@@ -648,7 +648,7 @@ class SocketCommandsAdmin extends SocketCommands {
648
648
  callback(ip, null);
649
649
  });
650
650
  } catch (error) {
651
- this.adapter.log.error('[_changePassword] ERROR: ' + error.toString());
651
+ this.adapter.log.error(`[_changePassword] ERROR: ${error.toString()}`);
652
652
  SocketCommands._fixCallback(callback, error);
653
653
  }
654
654
  }
@@ -680,7 +680,7 @@ class SocketCommandsAdmin extends SocketCommands {
680
680
  if (timeout) {
681
681
  let result = {list: []};
682
682
 
683
- // deliver file list
683
+ // deliver the file list
684
684
  try {
685
685
  const config = this.adapter.systemConfig;
686
686
  // detect file log
@@ -742,7 +742,7 @@ class SocketCommandsAdmin extends SocketCommands {
742
742
  };
743
743
 
744
744
  this.commands['delState'] = (socket, id, callback) => {
745
- // Delete state. Corresponding object will be deleted too.
745
+ // Delete state. The corresponding object will be deleted too.
746
746
  // @param {string} id - state ID
747
747
  // @param {function} callback - `function (error)`
748
748
  if (this._checkPermissions(socket, 'delState', callback, id)) {
@@ -763,7 +763,7 @@ class SocketCommandsAdmin extends SocketCommands {
763
763
  // commands will be executed on host/controller
764
764
  // following response commands are expected: cmdStdout, cmdStderr, cmdExit
765
765
  this.commands['cmdExec'] = (socket, host, id, cmd, callback) => {
766
- // Execute shell command on host/controller. Following response commands are expected: ´cmdStdout, cmdStderr, cmdExit´
766
+ // Execute the shell command on host/controller. Following response commands are expected: ´cmdStdout, cmdStderr, cmdExit´
767
767
  // @param {string} host - host name, like 'system.host.raspberrypi'
768
768
  // @param {string} id - session ID, like `Date.now()´. This session ID will come in events `cmdStdout, cmdStderr, cmdExit`
769
769
  // @param {string} cmd - command
@@ -783,7 +783,7 @@ class SocketCommandsAdmin extends SocketCommands {
783
783
  };
784
784
 
785
785
  this.commands['eventsThreshold'] = (socket, isActive) => {
786
- // Used only for admin to limit number of events to front-end.
786
+ // Used only for admin to the limited number of events to front-end.
787
787
  // @param {boolean} isActive - if true, then events will be limited
788
788
  if (!isActive) {
789
789
  this.disableEventThreshold(true);
@@ -811,14 +811,14 @@ class SocketCommandsAdmin extends SocketCommands {
811
811
  };
812
812
 
813
813
  this.commands['checkFeatureSupported'] = (socket, feature, callback) => {
814
- // Checks if same feature is supported by current js-controller
814
+ // Checks, if the same feature is supported by the current js-controller
815
815
  // @param {string} feature - feature name like `CONTROLLER_LICENSE_MANAGER`
816
816
  // @param {function} callback - `function (error, isSupported)`
817
817
  SocketCommands._fixCallback(callback, null, this.adapter.supportsFeature && this.adapter.supportsFeature(feature));
818
818
  };
819
819
 
820
820
  this.commands['decrypt'] = (socket, encryptedText, callback) => {
821
- // Decrypts text with system secret key
821
+ // Decrypts text with the system secret key
822
822
  // @param {string} encryptedText - encrypted text
823
823
  // @param {function} callback - `function (error, decryptedText)`
824
824
  if (this.secret) {
@@ -842,7 +842,7 @@ class SocketCommandsAdmin extends SocketCommands {
842
842
  };
843
843
 
844
844
  this.commands['encrypt'] = (socket, plainText, callback) => {
845
- // Encrypts text with system secret key
845
+ // Encrypts text with the system secret key
846
846
  // @param {string} plainText - normal text
847
847
  // @param {function} callback - `function (error, encryptedText)`
848
848
  if (this.secret) {
@@ -922,7 +922,7 @@ class SocketCommandsAdmin extends SocketCommands {
922
922
  .then(() =>
923
923
  callback(null, {
924
924
  strict: false,
925
- configs
925
+ configs,
926
926
  })
927
927
  );
928
928
  });
@@ -1010,7 +1010,7 @@ class SocketCommandsAdmin extends SocketCommands {
1010
1010
  adminTab: obj.common.adminTab,
1011
1011
  name: obj.common.name,
1012
1012
  icon: obj.common.icon,
1013
- enabled: obj.common.enabled
1013
+ enabled: obj.common.enabled,
1014
1014
  };
1015
1015
  });
1016
1016
 
@@ -1106,7 +1106,7 @@ class SocketCommandsAdmin extends SocketCommands {
1106
1106
  // @param {function} callback - `function (error, repository)`, where `repository` is an object like `{'javascript': {version: '1.0.1', icon}, 'admin': {version: '1.0.1', icon}}`
1107
1107
  if (this._checkPermissions(socket, 'sendToHost', callback)) {
1108
1108
  this._sendToHost(host, 'getRepository', null, data => {
1109
- // Extract only version and icon
1109
+ // Extract only the version and icon
1110
1110
  const result = {};
1111
1111
  data && Object.keys(data).forEach(name => result[name] = {
1112
1112
  version: data[name].version,
@@ -1210,7 +1210,7 @@ class SocketCommandsAdmin extends SocketCommands {
1210
1210
  }
1211
1211
 
1212
1212
  this.commands['extendObject'] = (socket, id, obj, callback) => {
1213
- // Extend existing object
1213
+ // Extend the existing object
1214
1214
  // @param {string} id - object ID
1215
1215
  // @param {object} obj - new parts of the object, like `{common: {name: 'new name'}}`
1216
1216
  // @param {function} callback - `function (error)`
@@ -1251,7 +1251,7 @@ class SocketCommandsAdmin extends SocketCommands {
1251
1251
  };
1252
1252
 
1253
1253
  this.commands['delObject'] = (socket, id, options, callback) => {
1254
- // Delete object or objects recursively. Objects with `dontDelete` cannot be deleted.
1254
+ // Delete an object or objects recursively. Objects with `dontDelete` cannot be deleted.
1255
1255
  // @param {string} id - Object ID like, 'adapterName.0.channel'
1256
1256
  // @param {string} options - `{recursive: true}`
1257
1257
  // @param {function} callback - `function (error)`
@@ -65,7 +65,7 @@ class SocketCommon {
65
65
 
66
66
  this.settings.ttl = parseInt(this.settings.ttl, 10) || 3600;
67
67
 
68
- // it can be used as client too for cloud
68
+ // it can be used as a client too for cloud
69
69
  if (socketClass) {
70
70
  if (!server.__inited) {
71
71
  if (typeof socketClass.listen === 'function') {
@@ -88,7 +88,7 @@ class SocketCommon {
88
88
  this.__initAuthentication(authOptions);
89
89
  }
90
90
 
91
- // Enable cross domain access
91
+ // Enable cross-domain access
92
92
  // deprecated, because no more used in socket.io@4 only(in @2)
93
93
  if (this.settings.crossDomain && this.server.set) {
94
94
  this.server.set('origins', '*:*');
@@ -111,9 +111,9 @@ class SocketCommon {
111
111
  if ((error && error.message && error.message.includes('authentication failed') ||
112
112
  (details && details.toString().includes('authentication failed')))
113
113
  ) {
114
- this.adapter.log.debug(`Error: ${(error && error.message) || JSON.stringify(error)}${details ? ' - ' + details : ''}`);
114
+ this.adapter.log.debug(`Error: ${(error && error.message) || JSON.stringify(error)}${details ? ` - ${details}` : ''}`);
115
115
  } else {
116
- this.adapter.log.error(`Error: ${(error && error.message) || JSON.stringify(error)}${details ? ' - ' + details : ''}`);
116
+ this.adapter.log.error(`Error: ${(error && error.message) || JSON.stringify(error)}${details ? ` - ${details}` : ''}`);
117
117
  }
118
118
  }
119
119
  });
@@ -123,9 +123,9 @@ class SocketCommon {
123
123
  // ignore "failed connection" as it already shown
124
124
  if (!error || !error.message || !error.message.includes('failed connection')) {
125
125
  if (error && error.message && error.message.includes('authentication failed')) {
126
- this.adapter.log.debug(`Error: ${(error && error.message) || JSON.stringify(error)}${details ? ' - ' + details : ''}`);
126
+ this.adapter.log.debug(`Error: ${(error && error.message) || JSON.stringify(error)}${details ? ` - ${details}` : ''}`);
127
127
  } else {
128
- this.adapter.log.error(`Error: ${(error && error.message) || JSON.stringify(error)}${details ? ' - ' + details : ''}`);
128
+ this.adapter.log.error(`Error: ${(error && error.message) || JSON.stringify(error)}${details ? ` - ${details}` : ''}`);
129
129
  }
130
130
  }
131
131
  });
@@ -201,17 +201,17 @@ class SocketCommon {
201
201
  return address;
202
202
  }
203
203
 
204
- // check if address is IPv4
204
+ // check if the address is IPv4
205
205
  const addressParts = address.split('.');
206
206
  if (addressParts.length !== 4) {
207
207
  return null;
208
208
  }
209
209
 
210
- // do we have settings for wild carded ips?
210
+ // do we have settings for wild-carded ips?
211
211
  const wildCardIps = Object.keys(whiteList).filter(key => key.includes('*'));
212
212
 
213
213
  if (!wildCardIps.length) {
214
- // no wild carded ips => no ip configured
214
+ // no wild-carded ips => no ip configured
215
215
  return null;
216
216
  }
217
217
 
@@ -253,7 +253,7 @@ class SocketCommon {
253
253
  });
254
254
 
255
255
  if (whiteListAcl.user !== 'auth') {
256
- acl.user = 'system.user.' + whiteListAcl.user;
256
+ acl.user = `system.user.${whiteListAcl.user}`;
257
257
  }
258
258
  }
259
259
  }
@@ -391,6 +391,10 @@ class SocketCommon {
391
391
  return this.commands.publish(socket, type, id, obj);
392
392
  }
393
393
 
394
+ publishInstanceMessage(socket, sourceInstance, messageType, data) {
395
+ return this.commands.publishInstanceMessage(socket, sourceInstance, messageType, data);
396
+ }
397
+
394
398
  publishFile(socket, id, fileName, size) {
395
399
  return this.commands.publishFile(socket, id, fileName, size);
396
400
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@iobroker/socket-classes",
3
- "version": "1.1.5",
3
+ "version": "1.3.1",
4
4
  "description": "ioBroker server-side web sockets",
5
5
  "author": {
6
6
  "name": "bluefox",
@@ -21,13 +21,13 @@
21
21
  "url": "https://github.com/ioBroker/ioBroker.socket-classes"
22
22
  },
23
23
  "dependencies": {
24
- "@iobroker/adapter-core": "^2.6.7",
24
+ "@iobroker/adapter-core": "^3.0.3",
25
25
  "passport": "^0.6.0",
26
26
  "cookie-parser": "^1.4.6",
27
- "axios": "^1.3.4"
27
+ "axios": "^1.4.0"
28
28
  },
29
29
  "devDependencies": {
30
- "@alcalzone/release-script": "^3.5.9",
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",
@@ -51,6 +51,7 @@
51
51
  "release-patch": "release-script patch --yes",
52
52
  "release-minor": "release-script minor --yes",
53
53
  "release-major": "release-script major --yes",
54
+ "update-packages": "ncu --upgrade",
54
55
  "docs": "gulp"
55
56
  },
56
57
  "license": "MIT",