@iobroker/socket-classes 1.2.0 → 1.3.2

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
@@ -63,12 +63,66 @@ io.start(server.server, ws, {userKey: 'connect.sid', checkUser, store, secret: a
63
63
  io.close();
64
64
  ```
65
65
 
66
+ ## GUI subscribes
67
+ GUI client can send to desired instance the `subscribe` message
68
+ ```
69
+ socket.emit('clientSubscribe', 'cameras.0', 'startCamera', {width: 640, height: 480}, result => console.log('Started: ' + result));
70
+ ```
71
+
72
+ The instance 'cameras.0' will receive message `clientSubscribe` with information who want to receive messages.
73
+ ```
74
+ adapter.on('message', obj => {
75
+ if (obj?.command === 'clientSubscribe') {
76
+ if (obj?.message.type && obj.message.type.startsWith('startCamera/')) {
77
+ const [, camera] = obj.message.type.split('/');
78
+ // start camera with obj.message.data
79
+ // ...
80
+
81
+ // inform GUI that camera is started
82
+ adapter.sendTo(obj.from, obj.command, {result: true}, obj.callback);
83
+ this.subscribes = this.subscribes || [];
84
+ this.subscribes.push({sid: obj.message.sid, from: obj.from, type: obj.message.type, camera});
85
+ }
86
+ } else
87
+ if (obj?.command === 'clientUnsubscribe' || obj?.command === 'clientSubscribeError') {
88
+ if (obj?.message.type && obj.message.type.startsWith('startCamera/')) {
89
+ const [, camera] = obj.message.type.split('/');
90
+ if (this.subscribes) {
91
+ const pos = this.subscribes.findIndex(s => s.sid === obj.message.sid && s.from === obj.from && s.type === obj.message.type);
92
+ if (pos !== -1) {
93
+ this.subscribes.splice(pos, 1);
94
+
95
+ // stop camera
96
+ // ...
97
+ }
98
+ }
99
+ }
100
+ }
101
+ });
102
+ ```
103
+
104
+ and after that client will receive messages from instance
105
+
106
+ ```
107
+ function sendImage(camera, data) {
108
+ this.subscribes.forEach(it => {
109
+ if (it.camera !== camera) {
110
+ return;
111
+ }
112
+ // send image to GUI
113
+ adapter.sendTo(it.from, 'im', {m: it.type, s: it.sid, d: data});
114
+ });
115
+ }
116
+ ```
117
+
118
+
66
119
  ## Web Methods
67
120
  <!-- WEB_METHODS_START -->
68
121
  ### List of commands
69
122
  * [authenticate](#authenticate_w)
70
123
  * [error](#error_w)
71
124
  * [log](#log_w)
125
+ * [checkFeatureSupported](#checkfeaturesupported_w)
72
126
  * [getHistory](#gethistory_w)
73
127
  * [httpGet](#httpget_w)
74
128
  * [sendTo](#sendto_w)
@@ -86,6 +140,8 @@ io.close();
86
140
  * [getObjectView](#getobjectview_w)
87
141
  * [setObject](#setobject_w)
88
142
  * [delObject](#delobject_w)
143
+ * [clientSubscribe](#clientsubscribe_w)
144
+ * [clientUnsubscribe](#clientunsubscribe_w)
89
145
  * [getStates](#getstates_w)
90
146
  * [getForeignStates](#getforeignstates_w)
91
147
  * [getState](#getstate_w)
@@ -128,6 +184,11 @@ Write log entry into ioBroker log
128
184
  * text *(string)*: log text
129
185
  * level *(string)*: one of `['silly', 'debug', 'info', 'warn', 'error']`. Default is 'debug'.
130
186
 
187
+ ### <a name="checkfeaturesupported_w"></a>checkFeatureSupported(feature, callback)
188
+ Checks, if the same feature is supported by the current js-controller
189
+ * feature *(string)*: feature name like `CONTROLLER_LICENSE_MANAGER`
190
+ * callback *(function)*: `function (error, isSupported)`
191
+
131
192
  ### <a name="gethistory_w"></a>getHistory(id, options, callback)
132
193
  Get history data from specific instance
133
194
  * id *(string)*: object ID
@@ -218,6 +279,19 @@ Delete object. Only deletion of flot objects is allowed
218
279
  * options *(string)*: ignored
219
280
  * callback *(function)*: `function (error)`
220
281
 
282
+ ### <a name="clientsubscribe_w"></a>clientSubscribe(targetInstance, messageType, data, callback)
283
+ Client informs specific instance about subscription on its messages. After subscription the socket will receive "im" messages from desired instance
284
+ * targetInstance *(string)*: instance name, e.g. "cameras.0"
285
+ * messageType *(string)*: message type, e.g. "startRecording/cam1"
286
+ * data *(object)*: optional data object, e.g. {width: 640, height: 480}
287
+ * callback *(function)*: `function (error, result)`, target instance MUST acknowledge the subscription and return some object as result
288
+
289
+ ### <a name="clientunsubscribe_w"></a>clientUnsubscribe(targetInstance, messageType, callback)
290
+ Client unsubscribes from specific instance's messages
291
+ * targetInstance *(string)*: instance name, e.g. "cameras.0"
292
+ * messageType *(string)*: message type, e.g. "startRecording/cam1"
293
+ * callback *(function)*: `function (error, wasSubscribed)`, target instance MUST NOT acknowledge the un-subscription
294
+
221
295
  ### <a name="getstates_w"></a>getStates(pattern, callback)
222
296
  Read states by pattern
223
297
  * pattern *(string)*: optional pattern, like `system.adapter.*` or array of state IDs
@@ -273,19 +347,19 @@ Unsubscribe from state changes by pattern. Same as `unsubscribe`.
273
347
  ### <a name="readfile_w"></a>readFile(_adapter, fileName, callback)
274
348
  Read file from ioBroker DB
275
349
  * _adapter *(string)*: instance name, e.g. `vis.0`
276
- * fileName *(string)*: file name, e.g `main/vis-views.json`
350
+ * fileName *(string)*: file name, e.g. `main/vis-views.json`
277
351
  * callback *(function)*: `function (error, data, mimeType)`
278
352
 
279
353
  ### <a name="readfile64_w"></a>readFile64(_adapter, fileName, callback)
280
354
  Read file from ioBroker DB as base64 string
281
355
  * _adapter *(string)*: instance name, e.g. `vis.0`
282
- * fileName *(string)*: file name, e.g `main/vis-views.json`
356
+ * fileName *(string)*: file name, e.g. `main/vis-views.json`
283
357
  * callback *(function)*: `function (error, base64, mimeType)`
284
358
 
285
359
  ### <a name="writefile64_w"></a>writeFile64(_adapter, fileName, data64, options, callback)
286
360
  Write file into ioBroker DB as base64 string
287
361
  * _adapter *(string)*: instance name, e.g. `vis.0`
288
- * fileName *(string)*: file name, e.g `main/vis-views.json`
362
+ * fileName *(string)*: file name, e.g. `main/vis-views.json`
289
363
  * data64 *(string)*: file content as base64 string
290
364
  * options *(object)*: optional `{mode: 0x0644}`
291
365
  * callback *(function)*: `function (error)`
@@ -293,7 +367,7 @@ Write file into ioBroker DB as base64 string
293
367
  ### <a name="writefile_w"></a>writeFile(_adapter, fileName, data, options, callback)
294
368
  Write file into ioBroker DB as text **DEPRECATED**
295
369
  * _adapter *(string)*: instance name, e.g. `vis.0`
296
- * fileName *(string)*: file name, e.g `main/vis-views.json`
370
+ * fileName *(string)*: file name, e.g. `main/vis-views.json`
297
371
  * data64 *(string)*: file content as base64 string
298
372
  * options *(object)*: optional `{mode: 0x644}`
299
373
  * callback *(function)*: `function (error)`
@@ -301,83 +375,83 @@ Write file into ioBroker DB as text **DEPRECATED**
301
375
  ### <a name="unlink_w"></a>unlink(_adapter, name, callback)
302
376
  Delete file in ioBroker DB
303
377
  * _adapter *(string)*: instance name, e.g. `vis.0`
304
- * name *(string)*: file name, e.g `main/vis-views.json`
378
+ * name *(string)*: file name, e.g. `main/vis-views.json`
305
379
  * callback *(function)*: `function (error)`
306
380
 
307
381
  ### <a name="deletefile_w"></a>deleteFile(_adapter, name, callback)
308
382
  Delete file in ioBroker DB (same as unlink, but only for files)
309
383
  * _adapter *(string)*: instance name, e.g. `vis.0`
310
- * name *(string)*: file name, e.g `main/vis-views.json`
384
+ * name *(string)*: file name, e.g. `main/vis-views.json`
311
385
  * callback *(function)*: `function (error)`
312
386
 
313
387
  ### <a name="deletefolder_w"></a>deleteFolder(_adapter, name, callback)
314
388
  Delete file in ioBroker DB (same as unlink, but only for folders)
315
389
  * _adapter *(string)*: instance name, e.g. `vis.0`
316
- * name *(string)*: folder name, e.g `main`
390
+ * name *(string)*: folder name, e.g. `main`
317
391
  * callback *(function)*: `function (error)`
318
392
 
319
393
  ### <a name="renamefile_w"></a>renameFile(_adapter, oldName, newName, callback)
320
394
  Rename file in ioBroker DB
321
395
  * _adapter *(string)*: instance name, e.g. `vis.0`
322
- * oldName *(string)*: current file name, e.g `main/vis-views.json`
323
- * newName *(string)*: new file name, e.g `main/vis-views-new.json`
396
+ * oldName *(string)*: current file name, e.g. `main/vis-views.json`
397
+ * newName *(string)*: new file name, e.g. `main/vis-views-new.json`
324
398
  * callback *(function)*: `function (error)`
325
399
 
326
400
  ### <a name="rename_w"></a>rename(_adapter, oldName, newName, callback)
327
401
  Rename file or folder in ioBroker DB
328
402
  * _adapter *(string)*: instance name, e.g. `vis.0`
329
- * oldName *(string)*: current file name, e.g `main/vis-views.json`
330
- * newName *(string)*: new file name, e.g `main/vis-views-new.json`
403
+ * oldName *(string)*: current file name, e.g. `main/vis-views.json`
404
+ * newName *(string)*: new file name, e.g. `main/vis-views-new.json`
331
405
  * callback *(function)*: `function (error)`
332
406
 
333
407
  ### <a name="mkdir_w"></a>mkdir(_adapter, dirName, callback)
334
408
  Create folder in ioBroker DB
335
409
  * _adapter *(string)*: instance name, e.g. `vis.0`
336
- * dirName *(string)*: desired folder name, e.g `main`
410
+ * dirName *(string)*: desired folder name, e.g. `main`
337
411
  * callback *(function)*: `function (error)`
338
412
 
339
413
  ### <a name="readdir_w"></a>readDir(_adapter, dirName, options, callback)
340
414
  Read content of folder in ioBroker DB
341
415
  * _adapter *(string)*: instance name, e.g. `vis.0`
342
- * dirName *(string)*: folder name, e.g `main`
416
+ * dirName *(string)*: folder name, e.g. `main`
343
417
  * options *(object)*: optional `{filter: '*'}` or `{filter: '*.json'}`
344
418
  * callback *(function)*: `function (error, files)` where `files` is an array of objects, like `{file: 'vis-views.json', isDir: false, stats: {size: 123}, modifiedAt: 1661336290090, acl: {owner: 'system.user.admin', ownerGroup: 'system.group.administrator', permissions: 1632, read: true, write: true}`
345
419
 
346
420
  ### <a name="chmodfile_w"></a>chmodFile(_adapter, fileName, options, callback)
347
421
  Change file mode in ioBroker DB
348
422
  * _adapter *(string)*: instance name, e.g. `vis.0`
349
- * fileName *(string)*: file name, e.g `main/vis-views.json`
423
+ * fileName *(string)*: file name, e.g. `main/vis-views.json`
350
424
  * options *(object)*: `{mode: 0x644}` or 0x644. The first digit is user, second group, third others. Bit 1 is `execute`, bit 2 is `write`, bit 3 is `read`
351
425
  * callback *(function)*: `function (error)`
352
426
 
353
427
  ### <a name="chownfile_w"></a>chownFile(_adapter, fileName, options, callback)
354
428
  Change file owner in ioBroker DB
355
429
  * _adapter *(string)*: instance name, e.g. `vis.0`
356
- * fileName *(string)*: file name, e.g `main/vis-views.json`
430
+ * fileName *(string)*: file name, e.g. `main/vis-views.json`
357
431
  * options *(object)*: `{owner: 'system.user.user', ownerGroup: ''system.group.administrator'}` or 'system.user.user'. If ownerGroup is not defined, it will be taken from owner.
358
432
  * callback *(function)*: `function (error)`
359
433
 
360
434
  ### <a name="fileexists_w"></a>fileExists(_adapter, fileName, callback)
361
435
  Check if the file or folder exists in ioBroker DB
362
436
  * _adapter *(string)*: instance name, e.g. `vis.0`
363
- * fileName *(string)*: file name, e.g `main/vis-views.json`
437
+ * fileName *(string)*: file name, e.g. `main/vis-views.json`
364
438
  * callback *(function)*: `function (error, isExist)`
365
439
 
366
440
  ### <a name="subscribefiles_w"></a>subscribeFiles(id, pattern, callback)
367
441
  Subscribe to file changes in ioBroker DB
368
442
  * id *(string)*: instance name, e.g. `vis.0` or any object ID of type `meta`. `id` could have wildcards `*` too.
369
- * pattern *(string)*: file name pattern, e.g `main/*.json`
443
+ * pattern *(string)*: file name pattern, e.g. `main/*.json`
370
444
  * callback *(function)*: `function (error)`
371
445
 
372
446
  ### <a name="unsubscribefiles_w"></a>unsubscribeFiles(id, pattern, callback)
373
447
  Unsubscribe from file changes in ioBroker DB
374
448
  * id *(string)*: instance name, e.g. `vis.0` or any object ID of type `meta`. `id` could have wildcards `*` too.
375
- * pattern *(string)*: file name pattern, e.g `main/*.json`
449
+ * pattern *(string)*: file name pattern, e.g. `main/*.json`
376
450
  * callback *(function)*: `function (error)`
377
451
 
378
452
  ### <a name="getadapterinstances_w"></a>getAdapterInstances(adapterName, callback)
379
453
  Read all instances of the given adapter, or all instances of all adapters if adapterName is not defined
380
- * adapterName *(string)*: optional adapter name, e.g `history`.
454
+ * adapterName *(string)*: optional adapter name, e.g. `history`.
381
455
  * callback *(function)*: `function (error, instanceList)`, where instanceList is an array of instance objects, e.g. `{_id: 'system.adapter.history.0', common: {name: 'history', ...}, native: {...}}`
382
456
 
383
457
  <!-- WEB_METHODS_END -->
@@ -388,6 +462,7 @@ Read all instances of the given adapter, or all instances of all adapters if ada
388
462
  * [authenticate](#authenticate_a)
389
463
  * [error](#error_a)
390
464
  * [log](#log_a)
465
+ * [checkFeatureSupported](#checkfeaturesupported_a)
391
466
  * [getHistory](#gethistory_a)
392
467
  * [httpGet](#httpget_a)
393
468
  * [sendTo](#sendto_a)
@@ -406,7 +481,6 @@ Read all instances of the given adapter, or all instances of all adapters if ada
406
481
  * [eventsThreshold](#eventsthreshold_a)
407
482
  * [getRatings](#getratings_a)
408
483
  * [getCurrentInstance](#getcurrentinstance_a)
409
- * [checkFeatureSupported](#checkfeaturesupported_a)
410
484
  * [decrypt](#decrypt_a)
411
485
  * [encrypt](#encrypt_a)
412
486
  * [getIsEasyModeStrict](#getiseasymodestrict_a)
@@ -432,6 +506,8 @@ Read all instances of the given adapter, or all instances of all adapters if ada
432
506
  * [getObjectView](#getobjectview_a)
433
507
  * [setObject](#setobject_a)
434
508
  * [delObject](#delobject_a)
509
+ * [clientSubscribe](#clientsubscribe_a)
510
+ * [clientUnsubscribe](#clientunsubscribe_a)
435
511
  * [getAllObjects](#getallobjects_a)
436
512
  * [extendObject](#extendobject_a)
437
513
  * [getForeignObjects](#getforeignobjects_a)
@@ -478,6 +554,11 @@ Write log entry into ioBroker log
478
554
  * text *(string)*: log text
479
555
  * level *(string)*: one of `['silly', 'debug', 'info', 'warn', 'error']`. Default is 'debug'.
480
556
 
557
+ ### <a name="checkfeaturesupported_a"></a>checkFeatureSupported(feature, callback)
558
+ Checks, if the same feature is supported by the current js-controller
559
+ * feature *(string)*: feature name like `CONTROLLER_LICENSE_MANAGER`
560
+ * callback *(function)*: `function (error, isSupported)`
561
+
481
562
  ### <a name="gethistory_a"></a>getHistory(id, options, callback)
482
563
  Get history data from specific instance
483
564
  * id *(string)*: object ID
@@ -568,11 +649,6 @@ Read ratings of adapters
568
649
  Return current instance name like `admin.0`
569
650
  * callback *(function)*: `function (error, namespace)`
570
651
 
571
- ### <a name="checkfeaturesupported_a"></a>checkFeatureSupported(feature, callback)
572
- Checks, if the same feature is supported by the current js-controller
573
- * feature *(string)*: feature name like `CONTROLLER_LICENSE_MANAGER`
574
- * callback *(function)*: `function (error, isSupported)`
575
-
576
652
  ### <a name="decrypt_a"></a>decrypt(encryptedText, callback)
577
653
  Decrypts text with the system secret key
578
654
  * encryptedText *(string)*: encrypted text
@@ -697,6 +773,19 @@ Delete an object or objects recursively. Objects with `dontDelete` cannot be del
697
773
  * options *(string)*: `{recursive: true}`
698
774
  * callback *(function)*: `function (error)`
699
775
 
776
+ ### <a name="clientsubscribe_a"></a>clientSubscribe(targetInstance, messageType, data, callback)
777
+ Client informs specific instance about subscription on its messages. After subscription the socket will receive "im" messages from desired instance
778
+ * targetInstance *(string)*: instance name, e.g. "cameras.0"
779
+ * messageType *(string)*: message type, e.g. "startRecording/cam1"
780
+ * data *(object)*: optional data object, e.g. {width: 640, height: 480}
781
+ * callback *(function)*: `function (error, result)`, target instance MUST acknowledge the subscription and return some object as result
782
+
783
+ ### <a name="clientunsubscribe_a"></a>clientUnsubscribe(targetInstance, messageType, callback)
784
+ Client unsubscribes from specific instance's messages
785
+ * targetInstance *(string)*: instance name, e.g. "cameras.0"
786
+ * messageType *(string)*: message type, e.g. "startRecording/cam1"
787
+ * callback *(function)*: `function (error, wasSubscribed)`, target instance MUST NOT acknowledge the un-subscription
788
+
700
789
  ### <a name="getallobjects_a"></a>getAllObjects(callback)
701
790
  Read absolutely all objects
702
791
  * callback *(function)*: `function (error, objects)`, where `objects` is an object like `{'system.adapter.admin.0': {...}, 'system.adapter.web.0': {...}}`
@@ -774,19 +863,19 @@ Unsubscribe from state changes by pattern. Same as `unsubscribe`.
774
863
  ### <a name="readfile_a"></a>readFile(_adapter, fileName, callback)
775
864
  Read file from ioBroker DB
776
865
  * _adapter *(string)*: instance name, e.g. `vis.0`
777
- * fileName *(string)*: file name, e.g `main/vis-views.json`
866
+ * fileName *(string)*: file name, e.g. `main/vis-views.json`
778
867
  * callback *(function)*: `function (error, data, mimeType)`
779
868
 
780
869
  ### <a name="readfile64_a"></a>readFile64(_adapter, fileName, callback)
781
870
  Read file from ioBroker DB as base64 string
782
871
  * _adapter *(string)*: instance name, e.g. `vis.0`
783
- * fileName *(string)*: file name, e.g `main/vis-views.json`
872
+ * fileName *(string)*: file name, e.g. `main/vis-views.json`
784
873
  * callback *(function)*: `function (error, base64, mimeType)`
785
874
 
786
875
  ### <a name="writefile64_a"></a>writeFile64(_adapter, fileName, data64, options, callback)
787
876
  Write file into ioBroker DB as base64 string
788
877
  * _adapter *(string)*: instance name, e.g. `vis.0`
789
- * fileName *(string)*: file name, e.g `main/vis-views.json`
878
+ * fileName *(string)*: file name, e.g. `main/vis-views.json`
790
879
  * data64 *(string)*: file content as base64 string
791
880
  * options *(object)*: optional `{mode: 0x0644}`
792
881
  * callback *(function)*: `function (error)`
@@ -802,83 +891,83 @@ Write file into ioBroker DB as base64 string
802
891
  ### <a name="unlink_a"></a>unlink(_adapter, name, callback)
803
892
  Delete file in ioBroker DB
804
893
  * _adapter *(string)*: instance name, e.g. `vis.0`
805
- * name *(string)*: file name, e.g `main/vis-views.json`
894
+ * name *(string)*: file name, e.g. `main/vis-views.json`
806
895
  * callback *(function)*: `function (error)`
807
896
 
808
897
  ### <a name="deletefile_a"></a>deleteFile(_adapter, name, callback)
809
898
  Delete file in ioBroker DB (same as unlink, but only for files)
810
899
  * _adapter *(string)*: instance name, e.g. `vis.0`
811
- * name *(string)*: file name, e.g `main/vis-views.json`
900
+ * name *(string)*: file name, e.g. `main/vis-views.json`
812
901
  * callback *(function)*: `function (error)`
813
902
 
814
903
  ### <a name="deletefolder_a"></a>deleteFolder(_adapter, name, callback)
815
904
  Delete file in ioBroker DB (same as unlink, but only for folders)
816
905
  * _adapter *(string)*: instance name, e.g. `vis.0`
817
- * name *(string)*: folder name, e.g `main`
906
+ * name *(string)*: folder name, e.g. `main`
818
907
  * callback *(function)*: `function (error)`
819
908
 
820
909
  ### <a name="renamefile_a"></a>renameFile(_adapter, oldName, newName, callback)
821
910
  Rename file in ioBroker DB
822
911
  * _adapter *(string)*: instance name, e.g. `vis.0`
823
- * oldName *(string)*: current file name, e.g `main/vis-views.json`
824
- * newName *(string)*: new file name, e.g `main/vis-views-new.json`
912
+ * oldName *(string)*: current file name, e.g. `main/vis-views.json`
913
+ * newName *(string)*: new file name, e.g. `main/vis-views-new.json`
825
914
  * callback *(function)*: `function (error)`
826
915
 
827
916
  ### <a name="rename_a"></a>rename(_adapter, oldName, newName, callback)
828
917
  Rename file or folder in ioBroker DB
829
918
  * _adapter *(string)*: instance name, e.g. `vis.0`
830
- * oldName *(string)*: current file name, e.g `main/vis-views.json`
831
- * newName *(string)*: new file name, e.g `main/vis-views-new.json`
919
+ * oldName *(string)*: current file name, e.g. `main/vis-views.json`
920
+ * newName *(string)*: new file name, e.g. `main/vis-views-new.json`
832
921
  * callback *(function)*: `function (error)`
833
922
 
834
923
  ### <a name="mkdir_a"></a>mkdir(_adapter, dirName, callback)
835
924
  Create folder in ioBroker DB
836
925
  * _adapter *(string)*: instance name, e.g. `vis.0`
837
- * dirName *(string)*: desired folder name, e.g `main`
926
+ * dirName *(string)*: desired folder name, e.g. `main`
838
927
  * callback *(function)*: `function (error)`
839
928
 
840
929
  ### <a name="readdir_a"></a>readDir(_adapter, dirName, options, callback)
841
930
  Read content of folder in ioBroker DB
842
931
  * _adapter *(string)*: instance name, e.g. `vis.0`
843
- * dirName *(string)*: folder name, e.g `main`
932
+ * dirName *(string)*: folder name, e.g. `main`
844
933
  * options *(object)*: optional `{filter: '*'}` or `{filter: '*.json'}`
845
934
  * callback *(function)*: `function (error, files)` where `files` is an array of objects, like `{file: 'vis-views.json', isDir: false, stats: {size: 123}, modifiedAt: 1661336290090, acl: {owner: 'system.user.admin', ownerGroup: 'system.group.administrator', permissions: 1632, read: true, write: true}`
846
935
 
847
936
  ### <a name="chmodfile_a"></a>chmodFile(_adapter, fileName, options, callback)
848
937
  Change file mode in ioBroker DB
849
938
  * _adapter *(string)*: instance name, e.g. `vis.0`
850
- * fileName *(string)*: file name, e.g `main/vis-views.json`
939
+ * fileName *(string)*: file name, e.g. `main/vis-views.json`
851
940
  * options *(object)*: `{mode: 0x644}` or 0x644. The first digit is user, second group, third others. Bit 1 is `execute`, bit 2 is `write`, bit 3 is `read`
852
941
  * callback *(function)*: `function (error)`
853
942
 
854
943
  ### <a name="chownfile_a"></a>chownFile(_adapter, fileName, options, callback)
855
944
  Change file owner in ioBroker DB
856
945
  * _adapter *(string)*: instance name, e.g. `vis.0`
857
- * fileName *(string)*: file name, e.g `main/vis-views.json`
946
+ * fileName *(string)*: file name, e.g. `main/vis-views.json`
858
947
  * options *(object)*: `{owner: 'system.user.user', ownerGroup: ''system.group.administrator'}` or 'system.user.user'. If ownerGroup is not defined, it will be taken from owner.
859
948
  * callback *(function)*: `function (error)`
860
949
 
861
950
  ### <a name="fileexists_a"></a>fileExists(_adapter, fileName, callback)
862
951
  Check if the file or folder exists in ioBroker DB
863
952
  * _adapter *(string)*: instance name, e.g. `vis.0`
864
- * fileName *(string)*: file name, e.g `main/vis-views.json`
953
+ * fileName *(string)*: file name, e.g. `main/vis-views.json`
865
954
  * callback *(function)*: `function (error, isExist)`
866
955
 
867
956
  ### <a name="subscribefiles_a"></a>subscribeFiles(id, pattern, callback)
868
957
  Subscribe to file changes in ioBroker DB
869
958
  * id *(string)*: instance name, e.g. `vis.0` or any object ID of type `meta`. `id` could have wildcards `*` too.
870
- * pattern *(string)*: file name pattern, e.g `main/*.json`
959
+ * pattern *(string)*: file name pattern, e.g. `main/*.json`
871
960
  * callback *(function)*: `function (error)`
872
961
 
873
962
  ### <a name="unsubscribefiles_a"></a>unsubscribeFiles(id, pattern, callback)
874
963
  Unsubscribe from file changes in ioBroker DB
875
964
  * id *(string)*: instance name, e.g. `vis.0` or any object ID of type `meta`. `id` could have wildcards `*` too.
876
- * pattern *(string)*: file name pattern, e.g `main/*.json`
965
+ * pattern *(string)*: file name pattern, e.g. `main/*.json`
877
966
  * callback *(function)*: `function (error)`
878
967
 
879
968
  ### <a name="getadapterinstances_a"></a>getAdapterInstances(adapterName, callback)
880
969
  Read all instances of the given adapter, or all instances of all adapters if adapterName is not defined
881
- * adapterName *(string)*: optional adapter name, e.g `history`.
970
+ * adapterName *(string)*: optional adapter name, e.g. `history`.
882
971
  * callback *(function)*: `function (error, instanceList)`, where instanceList is an array of instance objects, e.g. `{_id: 'system.adapter.history.0', common: {name: 'history', ...}, native: {...}}`
883
972
 
884
973
  <!-- ADMIN_METHODS_END -->
@@ -889,6 +978,10 @@ Read all instances of the given adapter, or all instances of all adapters if ada
889
978
  -->
890
979
 
891
980
  ## Changelog
981
+ ### 1.3.2 (2023-08-01)
982
+ * (bluefox) Implemented subscribes of a client on messages from specific instance
983
+ * (bluefox) Moved checkFeatureSupported to regular connection and not only admin
984
+
892
985
  ### 1.2.0 (2023-07-07)
893
986
  * (foxriver76) fixed crash on invalid patterns with js-controller version 5
894
987
  * (bluefox) extended the getObjects function with the possibility to read the list of IDs
@@ -943,13 +1036,13 @@ Read all instances of the given adapter, or all instances of all adapters if ada
943
1036
  * (bluefox) Do not show error with failed authentication
944
1037
 
945
1038
  ### 0.4.7 (2022-06-20)
946
- * (bluefox) Allowed to overload system language
1039
+ * (bluefox) Allowed overloading system language
947
1040
 
948
1041
  ### 0.4.6 (2022-06-20)
949
1042
  * (bluefox) updated `passport`
950
1043
 
951
1044
  ### 0.4.5 (2022-06-20)
952
- * (bluefox) allow to run socket.io behind reverse proxy
1045
+ * (bluefox) allowed running socket.io behind reverse proxy
953
1046
 
954
1047
  ### 0.4.4 (2022-06-09)
955
1048
  * (bluefox) Do not show requireLog message
@@ -67,6 +67,7 @@ class SocketCommands {
67
67
  this.commands = {};
68
68
  this.subscribes = {};
69
69
  this.logEnabled = false;
70
+ this.clientSubscribes = {};
70
71
 
71
72
  this._updateSession = updateSession;
72
73
 
@@ -230,6 +231,20 @@ class SocketCommands {
230
231
  return false;
231
232
  }
232
233
 
234
+ publishInstanceMessage(socket, sourceInstance, messageType, data) {
235
+ if (this.clientSubscribes[socket.id] &&
236
+ this.clientSubscribes[socket.id][sourceInstance] &&
237
+ this.clientSubscribes[socket.id][sourceInstance].includes(messageType)
238
+ ) {
239
+ socket.emit('im', messageType, sourceInstance, data);
240
+ return true;
241
+ } else {
242
+ // inform instance about missing subscription
243
+ this.adapter.sendTo(sourceInstance, 'clientSubscribeError', {type: messageType, sid: socket.id});
244
+ return false;
245
+ }
246
+ }
247
+
233
248
  _showSubscribes(socket, type) {
234
249
  if (socket && socket.subscribe) {
235
250
  const s = socket.subscribe[type] || [];
@@ -364,7 +379,7 @@ class SocketCommands {
364
379
  }
365
380
  }
366
381
  } else if (key) {
367
- // Remove pattern from global list
382
+ // Remove a pattern from a global list
368
383
  if (this.subscribes[type][key] !== undefined) {
369
384
  this.subscribes[type][key]--;
370
385
  if (this.subscribes[type][key] <= 0) {
@@ -451,6 +466,8 @@ class SocketCommands {
451
466
  if (!socket || !socket.subscribe) {
452
467
  return;
453
468
  }
469
+ // inform all instances about disconnected socket
470
+ this._informAboutDisconnect(socket.id);
454
471
 
455
472
  if (!type) {
456
473
  // all
@@ -646,6 +663,17 @@ class SocketCommands {
646
663
  }
647
664
  };
648
665
 
666
+ this.commands['checkFeatureSupported'] = (socket, feature, callback) => {
667
+ // Checks, if the same feature is supported by the current js-controller
668
+ // @param {string} feature - feature name like `CONTROLLER_LICENSE_MANAGER`
669
+ // @param {function} callback - `function (error, isSupported)`
670
+ if (feature === 'INSTANCE_MESSAGES') {
671
+ SocketCommands._fixCallback(callback, null, true);
672
+ } else {
673
+ SocketCommands._fixCallback(callback, null, this.adapter.supportsFeature && this.adapter.supportsFeature(feature));
674
+ }
675
+ };
676
+
649
677
  // new History
650
678
  this.commands['getHistory'] = (socket, id, options, callback) => {
651
679
  // Get history data from specific instance
@@ -832,7 +860,7 @@ class SocketCommands {
832
860
  this.commands['readFile'] = (socket, _adapter, fileName, callback) => {
833
861
  // Read file from ioBroker DB
834
862
  // @param {string} _adapter - instance name, e.g. `vis.0`
835
- // @param {string} fileName - file name, e.g `main/vis-views.json`
863
+ // @param {string} fileName - file name, e.g. `main/vis-views.json`
836
864
  // @param {function} callback - `function (error, data, mimeType)`
837
865
  if (this._checkPermissions(socket, 'readFile', callback, fileName)) {
838
866
  try {
@@ -848,7 +876,7 @@ class SocketCommands {
848
876
  this.commands['readFile64'] = (socket, _adapter, fileName, callback) => {
849
877
  // Read file from ioBroker DB as base64 string
850
878
  // @param {string} _adapter - instance name, e.g. `vis.0`
851
- // @param {string} fileName - file name, e.g `main/vis-views.json`
879
+ // @param {string} fileName - file name, e.g. `main/vis-views.json`
852
880
  // @param {function} callback - `function (error, base64, mimeType)`
853
881
  if (this._checkPermissions(socket, 'readFile64', callback, fileName)) {
854
882
  try {
@@ -887,7 +915,7 @@ class SocketCommands {
887
915
  this.commands['writeFile64'] = (socket, _adapter, fileName, data64, options, callback) => {
888
916
  // Write file into ioBroker DB as base64 string
889
917
  // @param {string} _adapter - instance name, e.g. `vis.0`
890
- // @param {string} fileName - file name, e.g `main/vis-views.json`
918
+ // @param {string} fileName - file name, e.g. `main/vis-views.json`
891
919
  // @param {string} data64 - file content as base64 string
892
920
  // @param {object} options - optional `{mode: 0x0644}`
893
921
  // @param {function} callback - `function (error)`
@@ -920,7 +948,7 @@ class SocketCommands {
920
948
  this.commands['writeFile'] = (socket, _adapter, fileName, data, options, callback) => {
921
949
  // Write file into ioBroker DB as text **DEPRECATED**
922
950
  // @param {string} _adapter - instance name, e.g. `vis.0`
923
- // @param {string} fileName - file name, e.g `main/vis-views.json`
951
+ // @param {string} fileName - file name, e.g. `main/vis-views.json`
924
952
  // @param {string} data64 - file content as base64 string
925
953
  // @param {object} options - optional `{mode: 0x644}`
926
954
  // @param {function} callback - `function (error)`
@@ -946,7 +974,7 @@ class SocketCommands {
946
974
  this.commands['unlink'] = (socket, _adapter, name, callback) => {
947
975
  // Delete file in ioBroker DB
948
976
  // @param {string} _adapter - instance name, e.g. `vis.0`
949
- // @param {string} name - file name, e.g `main/vis-views.json`
977
+ // @param {string} name - file name, e.g. `main/vis-views.json`
950
978
  // @param {function} callback - `function (error)`
951
979
  if (this._checkPermissions(socket, 'unlink', callback, name)) {
952
980
  try {
@@ -963,7 +991,7 @@ class SocketCommands {
963
991
  this.commands['deleteFile'] = (socket, _adapter, name, callback) => {
964
992
  // Delete file in ioBroker DB (same as unlink, but only for files)
965
993
  // @param {string} _adapter - instance name, e.g. `vis.0`
966
- // @param {string} name - file name, e.g `main/vis-views.json`
994
+ // @param {string} name - file name, e.g. `main/vis-views.json`
967
995
  // @param {function} callback - `function (error)`
968
996
  if (this._checkPermissions(socket, 'unlink', callback, name)) {
969
997
  try {
@@ -979,7 +1007,7 @@ class SocketCommands {
979
1007
  this.commands['deleteFolder'] = (socket, _adapter, name, callback) => {
980
1008
  // Delete file in ioBroker DB (same as unlink, but only for folders)
981
1009
  // @param {string} _adapter - instance name, e.g. `vis.0`
982
- // @param {string} name - folder name, e.g `main`
1010
+ // @param {string} name - folder name, e.g. `main`
983
1011
  // @param {function} callback - `function (error)`
984
1012
  if (this._checkPermissions(socket, 'unlink', callback, name)) {
985
1013
  try {
@@ -996,8 +1024,8 @@ class SocketCommands {
996
1024
  this.commands['renameFile'] = (socket, _adapter, oldName, newName, callback) => {
997
1025
  // Rename file in ioBroker DB
998
1026
  // @param {string} _adapter - instance name, e.g. `vis.0`
999
- // @param {string} oldName - current file name, e.g `main/vis-views.json`
1000
- // @param {string} newName - new file name, e.g `main/vis-views-new.json`
1027
+ // @param {string} oldName - current file name, e.g. `main/vis-views.json`
1028
+ // @param {string} newName - new file name, e.g. `main/vis-views-new.json`
1001
1029
  // @param {function} callback - `function (error)`
1002
1030
  if (this._checkPermissions(socket, 'rename', callback, oldName)) {
1003
1031
  try {
@@ -1013,8 +1041,8 @@ class SocketCommands {
1013
1041
  this.commands['rename'] = (socket, _adapter, oldName, newName, callback) => {
1014
1042
  // Rename file or folder in ioBroker DB
1015
1043
  // @param {string} _adapter - instance name, e.g. `vis.0`
1016
- // @param {string} oldName - current file name, e.g `main/vis-views.json`
1017
- // @param {string} newName - new file name, e.g `main/vis-views-new.json`
1044
+ // @param {string} oldName - current file name, e.g. `main/vis-views.json`
1045
+ // @param {string} newName - new file name, e.g. `main/vis-views-new.json`
1018
1046
  // @param {function} callback - `function (error)`
1019
1047
  if (this._checkPermissions(socket, 'rename', callback, oldName)) {
1020
1048
  try {
@@ -1031,7 +1059,7 @@ class SocketCommands {
1031
1059
  this.commands['mkdir'] = (socket, _adapter, dirName, callback) => {
1032
1060
  // Create folder in ioBroker DB
1033
1061
  // @param {string} _adapter - instance name, e.g. `vis.0`
1034
- // @param {string} dirName - desired folder name, e.g `main`
1062
+ // @param {string} dirName - desired folder name, e.g. `main`
1035
1063
  // @param {function} callback - `function (error)`
1036
1064
  if (this._checkPermissions(socket, 'mkdir', callback, dirName)) {
1037
1065
  try {
@@ -1047,7 +1075,7 @@ class SocketCommands {
1047
1075
  this.commands['readDir'] = (socket, _adapter, dirName, options, callback) => {
1048
1076
  // Read content of folder in ioBroker DB
1049
1077
  // @param {string} _adapter - instance name, e.g. `vis.0`
1050
- // @param {string} dirName - folder name, e.g `main`
1078
+ // @param {string} dirName - folder name, e.g. `main`
1051
1079
  // @param {object} options - optional `{filter: '*'}` or `{filter: '*.json'}`
1052
1080
  // @param {function} callback - `function (error, files)` where `files` is an array of objects, like `{file: 'vis-views.json', isDir: false, stats: {size: 123}, modifiedAt: 1661336290090, acl: {owner: 'system.user.admin', ownerGroup: 'system.group.administrator', permissions: 1632, read: true, write: true}`
1053
1081
  if (typeof options === 'function') {
@@ -1075,7 +1103,7 @@ class SocketCommands {
1075
1103
  this.commands['chmodFile'] = (socket, _adapter, fileName, options, callback) => {
1076
1104
  // Change file mode in ioBroker DB
1077
1105
  // @param {string} _adapter - instance name, e.g. `vis.0`
1078
- // @param {string} fileName - file name, e.g `main/vis-views.json`
1106
+ // @param {string} fileName - file name, e.g. `main/vis-views.json`
1079
1107
  // @param {object} options - `{mode: 0x644}` or 0x644. The first digit is user, second group, third others. Bit 1 is `execute`, bit 2 is `write`, bit 3 is `read`
1080
1108
  // @param {function} callback - `function (error)`
1081
1109
  if (typeof options === 'function') {
@@ -1103,7 +1131,7 @@ class SocketCommands {
1103
1131
  this.commands['chownFile'] = (socket, _adapter, fileName, options, callback) => {
1104
1132
  // Change file owner in ioBroker DB
1105
1133
  // @param {string} _adapter - instance name, e.g. `vis.0`
1106
- // @param {string} fileName - file name, e.g `main/vis-views.json`
1134
+ // @param {string} fileName - file name, e.g. `main/vis-views.json`
1107
1135
  // @param {object} options - `{owner: 'system.user.user', ownerGroup: ''system.group.administrator'}` or 'system.user.user'. If ownerGroup is not defined, it will be taken from owner.
1108
1136
  // @param {function} callback - `function (error)`
1109
1137
  if (this._checkPermissions(socket, 'chownFile', callback, fileName)) {
@@ -1122,7 +1150,7 @@ class SocketCommands {
1122
1150
  this.commands['fileExists'] = (socket, _adapter, fileName, callback) => {
1123
1151
  // Check if the file or folder exists in ioBroker DB
1124
1152
  // @param {string} _adapter - instance name, e.g. `vis.0`
1125
- // @param {string} fileName - file name, e.g `main/vis-views.json`
1153
+ // @param {string} fileName - file name, e.g. `main/vis-views.json`
1126
1154
  // @param {function} callback - `function (error, isExist)`
1127
1155
  if (this._checkPermissions(socket, 'fileExists', callback, fileName)) {
1128
1156
  try {
@@ -1138,7 +1166,7 @@ class SocketCommands {
1138
1166
  this.commands['subscribeFiles'] = (socket, id, pattern, callback) => {
1139
1167
  // Subscribe to file changes in ioBroker DB
1140
1168
  // @param {string} id - instance name, e.g. `vis.0` or any object ID of type `meta`. `id` could have wildcards `*` too.
1141
- // @param {string} pattern - file name pattern, e.g `main/*.json`
1169
+ // @param {string} pattern - file name pattern, e.g. `main/*.json`
1142
1170
  // @param {function} callback - `function (error)`
1143
1171
  return this._subscribeFiles(socket, id, pattern, callback);
1144
1172
  }
@@ -1146,7 +1174,7 @@ class SocketCommands {
1146
1174
  this.commands['unsubscribeFiles'] = (socket, id, pattern, callback) => {
1147
1175
  // Unsubscribe from file changes in ioBroker DB
1148
1176
  // @param {string} id - instance name, e.g. `vis.0` or any object ID of type `meta`. `id` could have wildcards `*` too.
1149
- // @param {string} pattern - file name pattern, e.g `main/*.json`
1177
+ // @param {string} pattern - file name pattern, e.g. `main/*.json`
1150
1178
  // @param {function} callback - `function (error)`
1151
1179
 
1152
1180
  return this._unsubscribeFiles(socket, id, pattern, callback);
@@ -1154,7 +1182,7 @@ class SocketCommands {
1154
1182
 
1155
1183
  this.commands['getAdapterInstances'] = (socket, adapterName, callback) => {
1156
1184
  // Read all instances of the given adapter, or all instances of all adapters if adapterName is not defined
1157
- // @param {string} adapterName - optional adapter name, e.g `history`.
1185
+ // @param {string} adapterName - optional adapter name, e.g. `history`.
1158
1186
  // @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: {...}}`
1159
1187
  if (typeof callback === 'function') {
1160
1188
  if (this._checkPermissions(socket, 'getObject', callback)) {
@@ -1565,6 +1593,55 @@ class SocketCommands {
1565
1593
  SocketCommands._fixCallback(callback, SocketCommands.ERROR_PERMISSION);
1566
1594
  }
1567
1595
  };
1596
+
1597
+ this.commands['clientSubscribe'] = (socket, targetInstance, messageType, data, callback) => {
1598
+ // Client informs specific instance about subscription on its messages. After subscription the socket will receive "im" messages from desired instance
1599
+ // @param {string} targetInstance - instance name, e.g. "cameras.0"
1600
+ // @param {string} messageType - message type, e.g. "startRecording/cam1"
1601
+ // @param {object} data - optional data object, e.g. {width: 640, height: 480}
1602
+ // @param {function} callback - `function (error, result)`, target instance MUST acknowledge the subscription and return some object as result
1603
+ if (typeof data === 'function') {
1604
+ callback = data;
1605
+ data = null;
1606
+ }
1607
+ if (!targetInstance.startsWith('system.adapter.')) {
1608
+ targetInstance = `system.adapter.${targetInstance}`;
1609
+ }
1610
+ const sid = socket.id;
1611
+ // GUI subscribes for messages from targetInstance
1612
+ this.clientSubscribes[sid] = this.clientSubscribes[sid] || {};
1613
+ this.clientSubscribes[sid][targetInstance] = this.clientSubscribes[sid][targetInstance] || [];
1614
+ if (!this.clientSubscribes[sid][targetInstance].includes(messageType)) {
1615
+ this.clientSubscribes[sid][targetInstance].push(messageType);
1616
+ }
1617
+ // inform instance about new subscription
1618
+ this.adapter.sendTo(targetInstance, 'clientSubscribe', {type: messageType, sid, data}, result =>
1619
+ SocketCommands._fixCallback(callback, null, result));
1620
+ };
1621
+
1622
+ this.commands['clientUnsubscribe'] = (socket, targetInstance, messageType, callback) => {
1623
+ // Client unsubscribes from specific instance's messages
1624
+ // @param {string} targetInstance - instance name, e.g. "cameras.0"
1625
+ // @param {string} messageType - message type, e.g. "startRecording/cam1"
1626
+ // @param {function} callback - `function (error, wasSubscribed)`, target instance MUST NOT acknowledge the un-subscription
1627
+ const sid = socket.id;
1628
+ if (!targetInstance.startsWith('system.adapter.')) {
1629
+ targetInstance = `system.adapter.${targetInstance}`;
1630
+ }
1631
+
1632
+ // GUI unsubscribes for messages from targetInstance
1633
+ if (this.clientSubscribes[sid] && this.clientSubscribes[sid][targetInstance]) {
1634
+ const pos = this.clientSubscribes[sid][targetInstance].indexOf(messageType);
1635
+ if (pos !== -1) {
1636
+ this.clientSubscribes[sid][targetInstance].splice(pos, 1);
1637
+ // inform instance about unsubscription
1638
+ this.adapter.sendTo(targetInstance, 'clientUnsubscribe', {type: [messageType], sid});
1639
+ SocketCommands._fixCallback(callback, null, true);
1640
+ return;
1641
+ }
1642
+ }
1643
+ SocketCommands._fixCallback(callback, null, false);
1644
+ };
1568
1645
  }
1569
1646
 
1570
1647
  _initCommands() {
@@ -1574,6 +1651,20 @@ class SocketCommands {
1574
1651
  this.__initCommandsFiles();
1575
1652
  }
1576
1653
 
1654
+ _informAboutDisconnect(socketId) {
1655
+ // say to all instances, that this socket was disconnected
1656
+ if (this.clientSubscribes[socketId]) {
1657
+ Object.keys(this.clientSubscribes[socketId]).forEach(targetInstance => {
1658
+ this.adapter.sendTo(targetInstance, 'clientUnsubscribe', {
1659
+ message: this.clientSubscribes[socketId][targetInstance],
1660
+ sid: socketId,
1661
+ provider: this.adapter.namespace
1662
+ });
1663
+ });
1664
+ delete this.clientSubscribes[socketId];
1665
+ }
1666
+ }
1667
+
1577
1668
  applyCommands(socket) {
1578
1669
  Object.keys(this.commands)
1579
1670
  .forEach(command => socket.on(command, (...args) => {
@@ -810,13 +810,6 @@ class SocketCommandsAdmin extends SocketCommands {
810
810
  SocketCommands._fixCallback(callback, null, this.adapter.namespace);
811
811
  };
812
812
 
813
- this.commands['checkFeatureSupported'] = (socket, feature, callback) => {
814
- // Checks, if the same feature is supported by the current js-controller
815
- // @param {string} feature - feature name like `CONTROLLER_LICENSE_MANAGER`
816
- // @param {function} callback - `function (error, isSupported)`
817
- SocketCommands._fixCallback(callback, null, this.adapter.supportsFeature && this.adapter.supportsFeature(feature));
818
- };
819
-
820
813
  this.commands['decrypt'] = (socket, encryptedText, callback) => {
821
814
  // Decrypts text with the system secret key
822
815
  // @param {string} encryptedText - encrypted text
@@ -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.2.0",
3
+ "version": "1.3.2",
4
4
  "description": "ioBroker server-side web sockets",
5
5
  "author": {
6
6
  "name": "bluefox",
@@ -21,7 +21,7 @@
21
21
  "url": "https://github.com/ioBroker/ioBroker.socket-classes"
22
22
  },
23
23
  "dependencies": {
24
- "@iobroker/adapter-core": "^2.6.8",
24
+ "@iobroker/adapter-core": "^3.0.3",
25
25
  "passport": "^0.6.0",
26
26
  "cookie-parser": "^1.4.6",
27
27
  "axios": "^1.4.0"