@iobroker/socket-classes 1.4.4 → 1.5.0
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/LICENSE +1 -1
- package/README.md +9 -2
- package/lib/socketAdmin.js +15 -18
- package/lib/socketCommandsAdmin.js +43 -21
- package/lib/socketCommon.js +27 -9
- package/package.json +9 -9
package/LICENSE
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
The MIT License (MIT)
|
|
2
2
|
|
|
3
|
-
Copyright (c) 2020-
|
|
3
|
+
Copyright (c) 2020-2024 bluefox <dogafox@gmail.com>
|
|
4
4
|
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
6
|
of this software and associated documentation files (the "Software"), to deal
|
package/README.md
CHANGED
|
@@ -740,8 +740,9 @@ Get one object
|
|
|
740
740
|
* id *(string)*: object ID.
|
|
741
741
|
* callback *(function)*: `function (error, obj)`
|
|
742
742
|
|
|
743
|
-
### <a name="getobjects_a"></a>getObjects(callback)
|
|
743
|
+
### <a name="getobjects_a"></a>getObjects(list, callback)
|
|
744
744
|
Read absolutely all objects. Same as `getAllObjects`.
|
|
745
|
+
* list *(string[])*: optional list of IDs.
|
|
745
746
|
* callback *(function)*: `function (error, objects)`, where `objects` is an object like `{'system.adapter.admin.0': {...}, 'system.adapter.web.0': {...}}`
|
|
746
747
|
|
|
747
748
|
### <a name="subscribeobjects_a"></a>subscribeObjects(pattern, callback)
|
|
@@ -978,6 +979,12 @@ Read all instances of the given adapter, or all instances of all adapters if ada
|
|
|
978
979
|
-->
|
|
979
980
|
|
|
980
981
|
## Changelog
|
|
982
|
+
### 1.5.0 (2024-02-22)
|
|
983
|
+
* (bluefox) Extended getObjects function with the possibility to read the list of IDs in admin
|
|
984
|
+
|
|
985
|
+
### 1.4.6 (2023-10-19)
|
|
986
|
+
* (bluefox) Added `publishInstanceMessageAll` command
|
|
987
|
+
|
|
981
988
|
### 1.4.4 (2023-10-11)
|
|
982
989
|
* (bluefox) Caught errors by subscribe/unsubscribe
|
|
983
990
|
|
|
@@ -1113,7 +1120,7 @@ Read all instances of the given adapter, or all instances of all adapters if ada
|
|
|
1113
1120
|
## License
|
|
1114
1121
|
The MIT License (MIT)
|
|
1115
1122
|
|
|
1116
|
-
Copyright (c) 2020-
|
|
1123
|
+
Copyright (c) 2020-2024 Bluefox <dogafox@gmail.com>
|
|
1117
1124
|
|
|
1118
1125
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
1119
1126
|
of this software and associated documentation files (the "Software"), to deal
|
package/lib/socketAdmin.js
CHANGED
|
@@ -140,27 +140,24 @@ class SocketAdmin extends SocketCommon {
|
|
|
140
140
|
stateChange(id, state) {
|
|
141
141
|
this.commands.stateChange(id, state);
|
|
142
142
|
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
143
|
+
const sockets = this.getSocketsList();
|
|
144
|
+
if (sockets) {
|
|
146
145
|
sockets.forEach(socket =>
|
|
147
146
|
this.commands.publish(socket, 'stateChange', id, state));
|
|
148
147
|
}
|
|
149
148
|
}
|
|
150
149
|
|
|
151
150
|
fileChange(id, fileName, size) {
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
151
|
+
const sockets = this.getSocketsList();
|
|
152
|
+
if (sockets) {
|
|
155
153
|
sockets.forEach(socket =>
|
|
156
154
|
this.commands.publishFile(socket, id, fileName, size));
|
|
157
155
|
}
|
|
158
156
|
}
|
|
159
157
|
|
|
160
158
|
repoUpdated() {
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
159
|
+
const sockets = this.getSocketsList();
|
|
160
|
+
if (sockets) {
|
|
164
161
|
sockets.forEach(socket =>
|
|
165
162
|
this.__updateSession(socket));
|
|
166
163
|
|
|
@@ -169,9 +166,8 @@ class SocketAdmin extends SocketCommon {
|
|
|
169
166
|
}
|
|
170
167
|
|
|
171
168
|
objectChange(id, obj) {
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
169
|
+
const sockets = this.getSocketsList();
|
|
170
|
+
if (sockets) {
|
|
175
171
|
sockets.forEach(socket =>
|
|
176
172
|
this.commands.publish(socket, 'objectChange', id, obj));
|
|
177
173
|
}
|
|
@@ -186,13 +182,14 @@ class SocketAdmin extends SocketCommon {
|
|
|
186
182
|
}
|
|
187
183
|
|
|
188
184
|
sendCommand(obj) {
|
|
189
|
-
if (this.commands.sendCommand(obj)
|
|
190
|
-
const sockets = this.
|
|
185
|
+
if (this.commands.sendCommand(obj)) {
|
|
186
|
+
const sockets = this.getSocketsList();
|
|
187
|
+
if (sockets) {
|
|
188
|
+
sockets.forEach(socket =>
|
|
189
|
+
this.__updateSession(socket));
|
|
191
190
|
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
this.server.sockets.emit(obj.command, obj.message.id, obj.message.data);
|
|
191
|
+
this.server.sockets.emit(obj.command, obj.message.id, obj.message.data);
|
|
192
|
+
}
|
|
196
193
|
}
|
|
197
194
|
}
|
|
198
195
|
|
|
@@ -203,8 +203,8 @@ class SocketCommandsAdmin extends SocketCommands {
|
|
|
203
203
|
if (error.response) {
|
|
204
204
|
throw new Error(
|
|
205
205
|
(error.response.data && error.response.data.error) ||
|
|
206
|
-
|
|
207
|
-
|
|
206
|
+
error.response.data ||
|
|
207
|
+
error.response.status
|
|
208
208
|
);
|
|
209
209
|
} else if (error.request) {
|
|
210
210
|
throw new Error('no response');
|
|
@@ -1204,16 +1204,16 @@ class SocketCommandsAdmin extends SocketCommands {
|
|
|
1204
1204
|
if (this._checkPermissions(socket, 'getObject', callback)) {
|
|
1205
1205
|
this.adapter.getForeignObject('system.repositories', { user: socket._acl.user }, (error, obj) => {
|
|
1206
1206
|
obj &&
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1207
|
+
obj.native &&
|
|
1208
|
+
obj.native.repositories &&
|
|
1209
|
+
Object.keys(obj.native.repositories).forEach(name => {
|
|
1210
|
+
if (obj.native.repositories[name].json) {
|
|
1211
|
+
// limit information to _repoInfo
|
|
1212
|
+
obj.native.repositories[name].json = {
|
|
1213
|
+
_repoInfo: obj.native.repositories[name].json._repoInfo
|
|
1214
|
+
};
|
|
1215
|
+
}
|
|
1216
|
+
});
|
|
1217
1217
|
callback(error, obj);
|
|
1218
1218
|
});
|
|
1219
1219
|
}
|
|
@@ -1227,13 +1227,13 @@ class SocketCommandsAdmin extends SocketCommands {
|
|
|
1227
1227
|
// Extract only the version and icon
|
|
1228
1228
|
const result = {};
|
|
1229
1229
|
data &&
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1230
|
+
Object.keys(data).forEach(
|
|
1231
|
+
name =>
|
|
1232
|
+
(result[name] = {
|
|
1233
|
+
version: data[name].version,
|
|
1234
|
+
icon: data[name].extIcon
|
|
1235
|
+
})
|
|
1236
|
+
);
|
|
1237
1237
|
callback(result);
|
|
1238
1238
|
});
|
|
1239
1239
|
}
|
|
@@ -1333,10 +1333,32 @@ class SocketCommandsAdmin extends SocketCommands {
|
|
|
1333
1333
|
};
|
|
1334
1334
|
|
|
1335
1335
|
// Identical to getAllObjects
|
|
1336
|
-
this.commands['getObjects'] = (socket, callback) => {
|
|
1336
|
+
this.commands['getObjects'] = (socket, list, callback) => {
|
|
1337
1337
|
// Read absolutely all objects. Same as `getAllObjects`.
|
|
1338
|
+
// @param {string[]} list - optional list of IDs.
|
|
1338
1339
|
// @param {function} callback - `function (error, objects)`, where `objects` is an object like `{'system.adapter.admin.0': {...}, 'system.adapter.web.0': {...}}`
|
|
1339
|
-
|
|
1340
|
+
if (typeof list === 'function') {
|
|
1341
|
+
callback = list;
|
|
1342
|
+
list = null;
|
|
1343
|
+
}
|
|
1344
|
+
if (list && list.length) {
|
|
1345
|
+
if (this._checkPermissions(socket, 'getObject', callback)) {
|
|
1346
|
+
if (typeof callback === 'function') {
|
|
1347
|
+
try {
|
|
1348
|
+
this.adapter.getForeignObjects(list, { user: socket._acl.user }, (error, objs) =>
|
|
1349
|
+
SocketCommands._fixCallback(callback, error, objs)
|
|
1350
|
+
);
|
|
1351
|
+
} catch (error) {
|
|
1352
|
+
this.adapter.log.error(`[getObjects] ERROR: ${error.toString()}`);
|
|
1353
|
+
SocketCommands._fixCallback(callback, error);
|
|
1354
|
+
}
|
|
1355
|
+
} else {
|
|
1356
|
+
this.adapter.log.warn('[getObjects] Invalid callback');
|
|
1357
|
+
}
|
|
1358
|
+
}
|
|
1359
|
+
} else {
|
|
1360
|
+
return this._getAllObjects(socket, callback);
|
|
1361
|
+
}
|
|
1340
1362
|
};
|
|
1341
1363
|
|
|
1342
1364
|
this.commands['extendObject'] = (socket, id, obj, callback) => {
|
package/lib/socketCommon.js
CHANGED
|
@@ -198,9 +198,10 @@ class SocketCommon {
|
|
|
198
198
|
_unsubscribeAll() {
|
|
199
199
|
if (this.server && this.server.ioBroker) {
|
|
200
200
|
// this could be an object or array
|
|
201
|
-
const sockets = this.
|
|
202
|
-
|
|
203
|
-
|
|
201
|
+
const sockets = this.getSocketsList();
|
|
202
|
+
if (sockets) {
|
|
203
|
+
Object.keys(sockets).forEach(i => this.commands.unsubscribeSocket(sockets[i]));
|
|
204
|
+
}
|
|
204
205
|
} else if (this.server && this.server.sockets) {
|
|
205
206
|
for (const socket in this.server.sockets) {
|
|
206
207
|
if (Object.prototype.hasOwnProperty.call(this.server.sockets, socket)) {
|
|
@@ -383,10 +384,9 @@ class SocketCommon {
|
|
|
383
384
|
|
|
384
385
|
if (this.server) {
|
|
385
386
|
const clientsArray = [];
|
|
386
|
-
|
|
387
|
+
const sockets = this.getSocketsList();
|
|
388
|
+
if (sockets) {
|
|
387
389
|
// this could be an object or array
|
|
388
|
-
const sockets = this.server.sockets.sockets || this.server.sockets.connected;
|
|
389
|
-
|
|
390
390
|
Object.keys(sockets).forEach(i => clientsArray.push(sockets[i]._name || 'noname'));
|
|
391
391
|
}
|
|
392
392
|
const text = `[${clientsArray.length}]${clientsArray.join(', ')}`;
|
|
@@ -423,15 +423,33 @@ class SocketCommon {
|
|
|
423
423
|
return this.commands.publishFile(socket, id, fileName, size);
|
|
424
424
|
}
|
|
425
425
|
|
|
426
|
+
getSocketsList() {
|
|
427
|
+
if (this.server && this.server.sockets) {
|
|
428
|
+
// this could be an object or array
|
|
429
|
+
return this.server.sockets.sockets || this.server.sockets.connected;
|
|
430
|
+
}
|
|
431
|
+
return null;
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
publishInstanceMessageAll(sourceInstance, messageType, sid, data) {
|
|
435
|
+
const sockets = this.getSocketsList();
|
|
436
|
+
if (sockets) {
|
|
437
|
+
Object.keys(sockets).forEach(i => {
|
|
438
|
+
if (sockets[i].id === sid) {
|
|
439
|
+
this.publishInstanceMessage(sockets[i], sourceInstance, messageType, data);
|
|
440
|
+
}
|
|
441
|
+
});
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
|
|
426
445
|
close() {
|
|
427
446
|
this._unsubscribeAll();
|
|
428
447
|
|
|
429
448
|
this.commands.destroy();
|
|
430
449
|
|
|
431
|
-
|
|
450
|
+
const sockets = this.getSocketsList();
|
|
451
|
+
if (sockets) {
|
|
432
452
|
// this could be an object or array
|
|
433
|
-
const sockets = this.server.sockets.sockets || this.server.sockets.connected;
|
|
434
|
-
|
|
435
453
|
Object.keys(sockets).forEach(i => {
|
|
436
454
|
const socket = sockets[i];
|
|
437
455
|
if (socket._sessionTimer) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@iobroker/socket-classes",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.0",
|
|
4
4
|
"description": "ioBroker server-side web sockets",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "bluefox",
|
|
@@ -21,19 +21,19 @@
|
|
|
21
21
|
"url": "https://github.com/ioBroker/ioBroker.socket-classes"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@iobroker/adapter-core": "^3.0.
|
|
25
|
-
"axios": "^1.
|
|
24
|
+
"@iobroker/adapter-core": "^3.0.4",
|
|
25
|
+
"axios": "^1.6.7",
|
|
26
26
|
"cookie-parser": "^1.4.6",
|
|
27
|
-
"passport": "^0.
|
|
27
|
+
"passport": "^0.7.0"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
|
-
"@alcalzone/release-script": "^3.
|
|
31
|
-
"@alcalzone/release-script-plugin-license": "^3.
|
|
32
|
-
"@foxriver76/eslint-config": "^1.0.
|
|
33
|
-
"chai": "^4.
|
|
30
|
+
"@alcalzone/release-script": "^3.7.0",
|
|
31
|
+
"@alcalzone/release-script-plugin-license": "^3.7.0",
|
|
32
|
+
"@foxriver76/eslint-config": "^1.0.2",
|
|
33
|
+
"chai": "^4.4.1",
|
|
34
34
|
"gulp": "^4.0.2",
|
|
35
35
|
"iobroker.js-controller": "dev",
|
|
36
|
-
"mocha": "^10.
|
|
36
|
+
"mocha": "^10.3.0"
|
|
37
37
|
},
|
|
38
38
|
"bugs": {
|
|
39
39
|
"url": "https://github.com/ioBroker/ioBroker.web/issues"
|