@iobroker/socket-classes 2.6.2 → 2.7.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.
@@ -1,4 +1,5 @@
1
1
  "use strict";
2
+ var _a;
2
3
  Object.defineProperty(exports, "__esModule", { value: true });
3
4
  exports.SocketCommands = exports.COMMANDS_PERMISSIONS = void 0;
4
5
  const adapter_core_1 = require("@iobroker/adapter-core"); // Get common adapter utils
@@ -196,41 +197,41 @@ class SocketCommands {
196
197
  if (socket._acl?.user !== 'system.user.admin') {
197
198
  // type: file, object, state, other
198
199
  // operation: create, read, write, list, delete, sendto, execute, sendToHost, readLogs
199
- if (SocketCommands.COMMANDS_PERMISSIONS[_command]) {
200
+ if (_a.COMMANDS_PERMISSIONS[_command]) {
200
201
  // If permission required
201
- const commandType = SocketCommands.COMMANDS_PERMISSIONS[_command].type;
202
+ const commandType = _a.COMMANDS_PERMISSIONS[_command].type;
202
203
  if (commandType) {
203
204
  if (commandType === 'object') {
204
- const operation = SocketCommands.COMMANDS_PERMISSIONS[_command].operation;
205
+ const operation = _a.COMMANDS_PERMISSIONS[_command].operation;
205
206
  if (socket._acl?.object?.[operation]) {
206
207
  return true;
207
208
  }
208
209
  }
209
210
  else if (commandType === 'state') {
210
- const operation = SocketCommands.COMMANDS_PERMISSIONS[_command].operation;
211
+ const operation = _a.COMMANDS_PERMISSIONS[_command].operation;
211
212
  if (socket._acl?.state?.[operation]) {
212
213
  return true;
213
214
  }
214
215
  }
215
216
  else if (commandType === 'users') {
216
- const operation = SocketCommands.COMMANDS_PERMISSIONS[_command].operation;
217
+ const operation = _a.COMMANDS_PERMISSIONS[_command].operation;
217
218
  if (socket._acl?.users?.[operation]) {
218
219
  return true;
219
220
  }
220
221
  }
221
222
  else if (commandType === 'other') {
222
- const operation = SocketCommands.COMMANDS_PERMISSIONS[_command].operation;
223
+ const operation = _a.COMMANDS_PERMISSIONS[_command].operation;
223
224
  if (socket._acl?.other?.[operation]) {
224
225
  return true;
225
226
  }
226
227
  }
227
228
  else if (commandType === 'file') {
228
- const operation = SocketCommands.COMMANDS_PERMISSIONS[_command].operation;
229
+ const operation = _a.COMMANDS_PERMISSIONS[_command].operation;
229
230
  if (socket._acl?.file?.[operation]) {
230
231
  return true;
231
232
  }
232
233
  }
233
- this.adapter.log.warn(`No permission for "${socket._acl?.user}" to call ${_command}. Need "${commandType}"."${SocketCommands.COMMANDS_PERMISSIONS[_command].operation}"`);
234
+ this.adapter.log.warn(`No permission for "${socket._acl?.user}" to call ${_command}. Need "${commandType}"."${_a.COMMANDS_PERMISSIONS[_command].operation}"`);
234
235
  }
235
236
  else {
236
237
  return true;
@@ -240,19 +241,19 @@ class SocketCommands {
240
241
  this.adapter.log.warn(`No rule for command: ${_command}`);
241
242
  }
242
243
  if (typeof callback === 'function') {
243
- callback(SocketCommands.ERROR_PERMISSION);
244
+ callback(_a.ERROR_PERMISSION);
244
245
  }
245
246
  else {
246
- if (SocketCommands.COMMANDS_PERMISSIONS[_command]) {
247
- socket.emit(SocketCommands.ERROR_PERMISSION, {
247
+ if (_a.COMMANDS_PERMISSIONS[_command]) {
248
+ socket.emit(_a.ERROR_PERMISSION, {
248
249
  command,
249
- type: SocketCommands.COMMANDS_PERMISSIONS[_command].type,
250
- operation: SocketCommands.COMMANDS_PERMISSIONS[_command].operation,
250
+ type: _a.COMMANDS_PERMISSIONS[_command].type,
251
+ operation: _a.COMMANDS_PERMISSIONS[_command].operation,
251
252
  args,
252
253
  });
253
254
  }
254
255
  else {
255
- socket.emit(SocketCommands.ERROR_PERMISSION, { command: _command, args });
256
+ socket.emit(_a.ERROR_PERMISSION, { command: _command, args });
256
257
  }
257
258
  }
258
259
  return false;
@@ -288,17 +289,29 @@ class SocketCommands {
288
289
  }
289
290
  return false;
290
291
  }
292
+ /**
293
+ * The send options for a message triggered by this socket: the user it is sent on behalf of.
294
+ *
295
+ * Objects, states and files have always been read and written with `{ user }` so the database
296
+ * applies the ACLs of the logged-in user. A message had no such channel: the receiving instance saw
297
+ * `from` and nothing else, so every adapter reachable over `sendTo` had to act with its own rights,
298
+ * and could not tell one caller from another. The user travels with the message now, for the
299
+ * controller versions that support it - older ones ignore the option, so nothing breaks, but a
300
+ * receiver must treat `obj.user` as optional (`adapter.supportsFeature('ADAPTER_MESSAGE_USER_CONTEXT')`).
301
+ *
302
+ * @param socket the socket the command came in on
303
+ */
304
+ static sendOptionsOf(socket) {
305
+ const user = socket?._acl?.user;
306
+ return user ? { user } : undefined;
307
+ }
291
308
  publishInstanceMessage(socket, sourceInstance, messageType, data) {
292
309
  if (this.#clientSubscribes[socket.id]?.[sourceInstance]?.includes(messageType)) {
293
310
  socket.emit('im', messageType, sourceInstance, data);
294
311
  return true;
295
312
  }
296
313
  // inform instance about missing subscription
297
- this.adapter.sendTo(sourceInstance, 'clientSubscribeError', {
298
- type: messageType,
299
- sid: socket.id,
300
- reason: 'no one subscribed',
301
- });
314
+ this.adapter.sendTo(sourceInstance, 'clientSubscribeError', { type: messageType, sid: socket.id, reason: 'no one subscribed' }, undefined, _a.sendOptionsOf(socket));
302
315
  return false;
303
316
  }
304
317
  _showSubscribes(socket, type) {
@@ -550,7 +563,7 @@ class SocketCommands {
550
563
  return;
551
564
  }
552
565
  // inform all instances about disconnected socket, also if the socket has never subscribed to anything
553
- this.#informAboutDisconnect(socket.id);
566
+ this.#informAboutDisconnect(socket);
554
567
  if (!socket.subscribe) {
555
568
  return;
556
569
  }
@@ -859,18 +872,18 @@ class SocketCommands {
859
872
  */
860
873
  this.commands.checkFeatureSupported = (_socket, feature, callback) => {
861
874
  if (feature === 'INSTANCE_MESSAGES') {
862
- SocketCommands._fixCallback(callback, null, true);
875
+ _a._fixCallback(callback, null, true);
863
876
  }
864
877
  else if (feature === 'PARTIAL_OBJECT_TREE') {
865
- SocketCommands._fixCallback(callback, null, true);
878
+ _a._fixCallback(callback, null, true);
866
879
  }
867
880
  else if (feature === 'OBJECTS_COUNT') {
868
881
  // only the admin variant of these commands has it, and a client that asks must not
869
882
  // send a command that nobody answers - it would sit there until its timeout
870
- SocketCommands._fixCallback(callback, null, !!this.commands.getObjectsCount);
883
+ _a._fixCallback(callback, null, !!this.commands.getObjectsCount);
871
884
  }
872
885
  else {
873
- SocketCommands._fixCallback(callback, null, this.adapter.supportsFeature(feature));
886
+ _a._fixCallback(callback, null, this.adapter.supportsFeature(feature));
874
887
  }
875
888
  };
876
889
  /**
@@ -894,11 +907,11 @@ class SocketCommands {
894
907
  options.user = socket._acl?.user;
895
908
  options.aggregate ||= 'none';
896
909
  try {
897
- this.adapter.getHistory(id, options, (error, ...args) => SocketCommands._fixCallback(callback, error, ...args));
910
+ this.adapter.getHistory(id, options, (error, ...args) => _a._fixCallback(callback, error, ...args));
898
911
  }
899
912
  catch (error) {
900
913
  this.adapter.log.error(`[getHistory] ERROR: ${error.toString()}`);
901
- SocketCommands._fixCallback(callback, error);
914
+ _a._fixCallback(callback, error);
902
915
  }
903
916
  }
904
917
  };
@@ -936,7 +949,7 @@ class SocketCommands {
936
949
  this.commands.sendTo = (socket, adapterInstance, command, message, callback) => {
937
950
  if (this._checkPermissions(socket, 'sendTo', callback, command)) {
938
951
  try {
939
- this.adapter.sendTo(adapterInstance, command, message, res => typeof callback === 'function' && setImmediate(() => callback(res)));
952
+ this.adapter.sendTo(adapterInstance, command, message, res => typeof callback === 'function' && setImmediate(() => callback(res)), _a.sendOptionsOf(socket));
940
953
  }
941
954
  catch (error) {
942
955
  if (typeof callback === 'function') {
@@ -971,7 +984,7 @@ class SocketCommands {
971
984
  * @param callback callback `(result: { error?: string; result?: any }) => void`
972
985
  */
973
986
  this.commands.sendToHost = (socket, host, command, message, callback) => {
974
- if (this._checkPermissions(socket, protectedCommands.includes(command) ? 'cmdExec' : 'sendToHost', (error) => callback({ error: error || SocketCommands.ERROR_PERMISSION }), command)) {
987
+ if (this._checkPermissions(socket, protectedCommands.includes(command) ? 'cmdExec' : 'sendToHost', (error) => callback({ error: error || _a.ERROR_PERMISSION }), command)) {
975
988
  // Try to decode this file locally as redis has a limitation for files bigger than 20MB
976
989
  if (command === 'writeDirAsZip' && message && message.data.length > 1024 * 1024) {
977
990
  let buffer;
@@ -1002,7 +1015,10 @@ class SocketCommands {
1002
1015
  }
1003
1016
  else {
1004
1017
  try {
1005
- this.adapter.sendToHost(host, command, message, callback);
1018
+ // the 5th parameter exists from the controller version that reports
1019
+ // `ADAPTER_MESSAGE_USER_CONTEXT`; an older one ignores the extra argument
1020
+ const sendToHost = this.adapter.sendToHost;
1021
+ sendToHost.call(this.adapter, host, command, message, callback, _a.sendOptionsOf(socket));
1006
1022
  }
1007
1023
  catch (error) {
1008
1024
  if (callback) {
@@ -1101,7 +1117,7 @@ class SocketCommands {
1101
1117
  */
1102
1118
  this.commands.listPermissions = (_socket, callback) => {
1103
1119
  if (typeof callback === 'function') {
1104
- callback(SocketCommands.COMMANDS_PERMISSIONS);
1120
+ callback(_a.COMMANDS_PERMISSIONS);
1105
1121
  }
1106
1122
  else {
1107
1123
  this.adapter.log.warn('[listPermissions] Invalid callback');
@@ -1173,11 +1189,11 @@ class SocketCommands {
1173
1189
  this.commands.readFile = (socket, adapter, fileName, callback) => {
1174
1190
  if (this._checkPermissions(socket, 'readFile', callback, fileName)) {
1175
1191
  try {
1176
- this.adapter.readFile(adapter, fileName, { user: socket._acl?.user }, (error, ...args) => SocketCommands._fixCallback(callback, error, ...args));
1192
+ this.adapter.readFile(adapter, fileName, { user: socket._acl?.user }, (error, ...args) => _a._fixCallback(callback, error, ...args));
1177
1193
  }
1178
1194
  catch (error) {
1179
1195
  this.adapter.log.error(`[readFile] ERROR: ${error.toString()}`);
1180
- SocketCommands._fixCallback(callback, error);
1196
+ _a._fixCallback(callback, error);
1181
1197
  }
1182
1198
  }
1183
1199
  };
@@ -1226,7 +1242,7 @@ class SocketCommands {
1226
1242
  }
1227
1243
  catch (error) {
1228
1244
  this.adapter.log.error(`[readFile64] ERROR: ${error.toString()}`);
1229
- SocketCommands._fixCallback(callback, error);
1245
+ _a._fixCallback(callback, error);
1230
1246
  }
1231
1247
  }
1232
1248
  };
@@ -1255,16 +1271,16 @@ class SocketCommands {
1255
1271
  }
1256
1272
  if (this._checkPermissions(socket, 'writeFile64', callback, fileName)) {
1257
1273
  if (!data64) {
1258
- return SocketCommands._fixCallback(callback, 'No data provided');
1274
+ return _a._fixCallback(callback, 'No data provided');
1259
1275
  }
1260
1276
  // Convert base 64 to buffer
1261
1277
  try {
1262
1278
  const buffer = Buffer.from(data64, 'base64');
1263
- this.adapter.writeFile(adapter, fileName, buffer, _options, (error, ...args) => SocketCommands._fixCallback(callback, error, ...args));
1279
+ this.adapter.writeFile(adapter, fileName, buffer, _options, (error, ...args) => _a._fixCallback(callback, error, ...args));
1264
1280
  }
1265
1281
  catch (error) {
1266
1282
  this.adapter.log.error(`[writeFile64] Cannot convert data: ${error.toString()}`);
1267
- SocketCommands._fixCallback(callback, `Cannot convert data: ${error.toString()}`);
1283
+ _a._fixCallback(callback, `Cannot convert data: ${error.toString()}`);
1268
1284
  }
1269
1285
  }
1270
1286
  };
@@ -1297,11 +1313,11 @@ class SocketCommands {
1297
1313
  }
1298
1314
  this.adapter.log.debug('writeFile deprecated. Please use writeFile64');
1299
1315
  try {
1300
- this.adapter.writeFile(adapter, fileName, data, _options, (error, ...args) => SocketCommands._fixCallback(callback, error, ...args));
1316
+ this.adapter.writeFile(adapter, fileName, data, _options, (error, ...args) => _a._fixCallback(callback, error, ...args));
1301
1317
  }
1302
1318
  catch (error) {
1303
1319
  this.adapter.log.error(`[writeFile] ERROR: ${error.toString()}`);
1304
- SocketCommands._fixCallback(callback, error);
1320
+ _a._fixCallback(callback, error);
1305
1321
  }
1306
1322
  }
1307
1323
  };
@@ -1318,12 +1334,12 @@ class SocketCommands {
1318
1334
  if (this._checkPermissions(socket, 'unlink', callback, name)) {
1319
1335
  try {
1320
1336
  this.#unlink(adapter, name, { user: socket._acl?.user })
1321
- .then(() => SocketCommands._fixCallback(callback, undefined))
1322
- .catch(error => SocketCommands._fixCallback(callback, error));
1337
+ .then(() => _a._fixCallback(callback, undefined))
1338
+ .catch(error => _a._fixCallback(callback, error));
1323
1339
  }
1324
1340
  catch (error) {
1325
1341
  this.adapter.log.error(`[unlink] ERROR: ${error.toString()}`);
1326
- SocketCommands._fixCallback(callback, error);
1342
+ _a._fixCallback(callback, error);
1327
1343
  }
1328
1344
  }
1329
1345
  };
@@ -1339,11 +1355,11 @@ class SocketCommands {
1339
1355
  this.commands.deleteFile = (socket, adapter, name, callback) => {
1340
1356
  if (this._checkPermissions(socket, 'unlink', callback, name)) {
1341
1357
  try {
1342
- this.adapter.unlink(adapter, name, { user: socket._acl?.user }, (error, ...args) => SocketCommands._fixCallback(callback, error, ...args));
1358
+ this.adapter.unlink(adapter, name, { user: socket._acl?.user }, (error, ...args) => _a._fixCallback(callback, error, ...args));
1343
1359
  }
1344
1360
  catch (error) {
1345
1361
  this.adapter.log.error(`[deleteFile] ERROR: ${error.toString()}`);
1346
- SocketCommands._fixCallback(callback, error);
1362
+ _a._fixCallback(callback, error);
1347
1363
  }
1348
1364
  }
1349
1365
  };
@@ -1360,12 +1376,12 @@ class SocketCommands {
1360
1376
  if (this._checkPermissions(socket, 'unlink', callback, name)) {
1361
1377
  try {
1362
1378
  this.#unlink(adapter, name, { user: socket._acl?.user })
1363
- .then(() => SocketCommands._fixCallback(callback, null))
1364
- .catch(error => SocketCommands._fixCallback(callback, error));
1379
+ .then(() => _a._fixCallback(callback, null))
1380
+ .catch(error => _a._fixCallback(callback, error));
1365
1381
  }
1366
1382
  catch (error) {
1367
1383
  this.adapter.log.error(`[deleteFolder] ERROR: ${error.toString()}`);
1368
- SocketCommands._fixCallback(callback, error);
1384
+ _a._fixCallback(callback, error);
1369
1385
  }
1370
1386
  }
1371
1387
  };
@@ -1382,11 +1398,11 @@ class SocketCommands {
1382
1398
  this.commands.renameFile = (socket, adapter, oldName, newName, callback) => {
1383
1399
  if (this._checkPermissions(socket, 'rename', callback, oldName)) {
1384
1400
  try {
1385
- this.adapter.rename(adapter, oldName, newName, { user: socket._acl?.user }, (error, ...args) => SocketCommands._fixCallback(callback, error, ...args));
1401
+ this.adapter.rename(adapter, oldName, newName, { user: socket._acl?.user }, (error, ...args) => _a._fixCallback(callback, error, ...args));
1386
1402
  }
1387
1403
  catch (error) {
1388
1404
  this.adapter.log.error(`[renameFile] ERROR: ${error.toString()}`);
1389
- SocketCommands._fixCallback(callback, error);
1405
+ _a._fixCallback(callback, error);
1390
1406
  }
1391
1407
  }
1392
1408
  };
@@ -1404,12 +1420,12 @@ class SocketCommands {
1404
1420
  if (this._checkPermissions(socket, 'rename', callback, oldName)) {
1405
1421
  try {
1406
1422
  this.#rename(adapter, oldName, newName, { user: socket._acl?.user })
1407
- .then(() => SocketCommands._fixCallback(callback, undefined))
1408
- .catch(error => SocketCommands._fixCallback(callback, error));
1423
+ .then(() => _a._fixCallback(callback, undefined))
1424
+ .catch(error => _a._fixCallback(callback, error));
1409
1425
  }
1410
1426
  catch (error) {
1411
1427
  this.adapter.log.error(`[rename] ERROR: ${error.toString()}`);
1412
- SocketCommands._fixCallback(callback, error);
1428
+ _a._fixCallback(callback, error);
1413
1429
  }
1414
1430
  }
1415
1431
  };
@@ -1425,11 +1441,11 @@ class SocketCommands {
1425
1441
  this.commands.mkdir = (socket, adapter, dirName, callback) => {
1426
1442
  if (this._checkPermissions(socket, 'mkdir', callback, dirName)) {
1427
1443
  try {
1428
- this.adapter.mkdir(adapter, dirName, { user: socket._acl?.user }, (error, ...args) => SocketCommands._fixCallback(callback, error, ...args));
1444
+ this.adapter.mkdir(adapter, dirName, { user: socket._acl?.user }, (error, ...args) => _a._fixCallback(callback, error, ...args));
1429
1445
  }
1430
1446
  catch (error) {
1431
1447
  this.adapter.log.error(`[mkdir] ERROR: ${error.toString()}`);
1432
- SocketCommands._fixCallback(callback, error);
1448
+ _a._fixCallback(callback, error);
1433
1449
  }
1434
1450
  }
1435
1451
  };
@@ -1449,11 +1465,11 @@ class SocketCommands {
1449
1465
  }
1450
1466
  if (this._checkPermissions(socket, 'readDir', callback, dirName)) {
1451
1467
  try {
1452
- this.adapter.readDir(adapter, dirName, { user: socket._acl?.user }, (error, ...args) => SocketCommands._fixCallback(callback, error, ...args));
1468
+ this.adapter.readDir(adapter, dirName, { user: socket._acl?.user }, (error, ...args) => _a._fixCallback(callback, error, ...args));
1453
1469
  }
1454
1470
  catch (error) {
1455
1471
  this.adapter.log.error(`[readDir] ERROR: ${error.toString()}`);
1456
- SocketCommands._fixCallback(callback, error);
1472
+ _a._fixCallback(callback, error);
1457
1473
  }
1458
1474
  }
1459
1475
  };
@@ -1475,16 +1491,16 @@ class SocketCommands {
1475
1491
  }
1476
1492
  else {
1477
1493
  this.adapter.log.error(`[chownFile] ERROR: no options`);
1478
- SocketCommands._fixCallback(callback, 'no options');
1494
+ _a._fixCallback(callback, 'no options');
1479
1495
  return;
1480
1496
  }
1481
1497
  if (this._checkPermissions(socket, 'chmodFile', callback, fileName)) {
1482
1498
  try {
1483
- this.adapter.chmodFile(adapter, fileName, _options, (error, ...args) => SocketCommands._fixCallback(callback, error, ...args));
1499
+ this.adapter.chmodFile(adapter, fileName, _options, (error, ...args) => _a._fixCallback(callback, error, ...args));
1484
1500
  }
1485
1501
  catch (error) {
1486
1502
  this.adapter.log.error(`[chmodFile] ERROR: ${error.toString()}`);
1487
- SocketCommands._fixCallback(callback, error);
1503
+ _a._fixCallback(callback, error);
1488
1504
  }
1489
1505
  }
1490
1506
  };
@@ -1507,16 +1523,16 @@ class SocketCommands {
1507
1523
  }
1508
1524
  else {
1509
1525
  this.adapter.log.error(`[chownFile] ERROR: no options`);
1510
- SocketCommands._fixCallback(callback, 'no options');
1526
+ _a._fixCallback(callback, 'no options');
1511
1527
  return;
1512
1528
  }
1513
1529
  if (this._checkPermissions(socket, 'chownFile', callback, fileName)) {
1514
1530
  try {
1515
- this.adapter.chownFile(adapter, fileName, _options, (error, ...args) => SocketCommands._fixCallback(callback, error, ...args));
1531
+ this.adapter.chownFile(adapter, fileName, _options, (error, ...args) => _a._fixCallback(callback, error, ...args));
1516
1532
  }
1517
1533
  catch (error) {
1518
1534
  this.adapter.log.error(`[chownFile] ERROR: ${error.toString()}`);
1519
- SocketCommands._fixCallback(callback, error);
1535
+ _a._fixCallback(callback, error);
1520
1536
  }
1521
1537
  }
1522
1538
  };
@@ -1532,11 +1548,11 @@ class SocketCommands {
1532
1548
  this.commands.fileExists = (socket, adapter, fileName, callback) => {
1533
1549
  if (this._checkPermissions(socket, 'fileExists', callback, fileName)) {
1534
1550
  try {
1535
- this.adapter.fileExists(adapter, fileName, { user: socket._acl?.user }, (error, ...args) => SocketCommands._fixCallback(callback, error, ...args));
1551
+ this.adapter.fileExists(adapter, fileName, { user: socket._acl?.user }, (error, ...args) => _a._fixCallback(callback, error, ...args));
1536
1552
  }
1537
1553
  catch (error) {
1538
1554
  this.adapter.log.error(`[fileExists] ERROR: ${error.toString()}`);
1539
- SocketCommands._fixCallback(callback, error);
1555
+ _a._fixCallback(callback, error);
1540
1556
  }
1541
1557
  }
1542
1558
  };
@@ -1603,7 +1619,7 @@ class SocketCommands {
1603
1619
  }
1604
1620
  catch (error) {
1605
1621
  this.adapter.log.error(`[getAdapterInstances] ERROR: ${error.toString()}`);
1606
- SocketCommands._fixCallback(callback, error);
1622
+ _a._fixCallback(callback, error);
1607
1623
  }
1608
1624
  }
1609
1625
  }
@@ -1627,11 +1643,11 @@ class SocketCommands {
1627
1643
  }
1628
1644
  if (typeof callback === 'function') {
1629
1645
  try {
1630
- this.adapter.getForeignStates(pattern || '*', { user: socket._acl?.user }, (error, ...args) => SocketCommands._fixCallback(callback, error, ...args));
1646
+ this.adapter.getForeignStates(pattern || '*', { user: socket._acl?.user }, (error, ...args) => _a._fixCallback(callback, error, ...args));
1631
1647
  }
1632
1648
  catch (error) {
1633
1649
  this.adapter.log.error(`[getStates] ERROR: ${error.toString()}`);
1634
- SocketCommands._fixCallback(callback, error);
1650
+ _a._fixCallback(callback, error);
1635
1651
  }
1636
1652
  }
1637
1653
  else {
@@ -1669,15 +1685,15 @@ class SocketCommands {
1669
1685
  try {
1670
1686
  void this.adapter
1671
1687
  .getForeignStateAsync(id, { user: socket._acl?.user })
1672
- .then(state => SocketCommands._fixCallback(callback, null, state))
1688
+ .then(state => _a._fixCallback(callback, null, state))
1673
1689
  .catch(error => {
1674
1690
  this.adapter.log.error(`[getState] ERROR: ${error.toString()}`);
1675
- SocketCommands._fixCallback(callback, error);
1691
+ _a._fixCallback(callback, error);
1676
1692
  });
1677
1693
  }
1678
1694
  catch (error) {
1679
1695
  this.adapter.log.error(`[getState] ERROR: ${error.toString()}`);
1680
- SocketCommands._fixCallback(callback, error);
1696
+ _a._fixCallback(callback, error);
1681
1697
  }
1682
1698
  }
1683
1699
  }
@@ -1705,11 +1721,11 @@ class SocketCommands {
1705
1721
  delete this.states[id];
1706
1722
  }
1707
1723
  try {
1708
- this.adapter.setForeignState(id, state, { user: socket._acl?.user }, (error, ...args) => SocketCommands._fixCallback(callback, error, ...args));
1724
+ this.adapter.setForeignState(id, state, { user: socket._acl?.user }, (error, ...args) => _a._fixCallback(callback, error, ...args));
1709
1725
  }
1710
1726
  catch (error) {
1711
1727
  this.adapter.log.error(`[setState] ERROR: ${error.toString()}`);
1712
- SocketCommands._fixCallback(callback, error);
1728
+ _a._fixCallback(callback, error);
1713
1729
  }
1714
1730
  }
1715
1731
  };
@@ -1810,12 +1826,12 @@ class SocketCommands {
1810
1826
  if (this.context.language && id === 'system.config' && obj?.common) {
1811
1827
  obj.common.language = this.context.language;
1812
1828
  }
1813
- SocketCommands._fixCallback(callback, error, obj);
1829
+ _a._fixCallback(callback, error, obj);
1814
1830
  });
1815
1831
  }
1816
1832
  catch (error) {
1817
1833
  this.adapter.log.error(`[getObject] ERROR: ${error.toString()}`);
1818
- SocketCommands._fixCallback(callback, error);
1834
+ _a._fixCallback(callback, error);
1819
1835
  }
1820
1836
  }
1821
1837
  };
@@ -1837,11 +1853,11 @@ class SocketCommands {
1837
1853
  if (this._checkPermissions(socket, 'getObject', callback)) {
1838
1854
  if (typeof callback === 'function') {
1839
1855
  try {
1840
- this.adapter.getForeignObjects(list, { user: socket._acl?.user }, (error, objs) => SocketCommands._fixCallback(callback, error, objs));
1856
+ this.adapter.getForeignObjects(list, { user: socket._acl?.user }, (error, objs) => _a._fixCallback(callback, error, objs));
1841
1857
  }
1842
1858
  catch (error) {
1843
1859
  this.adapter.log.error(`[getObjects] ERROR: ${error.toString()}`);
1844
- SocketCommands._fixCallback(callback, error);
1860
+ _a._fixCallback(callback, error);
1845
1861
  }
1846
1862
  }
1847
1863
  else {
@@ -1879,7 +1895,7 @@ class SocketCommands {
1879
1895
  if (this.context.language && result['system.config']?.common) {
1880
1896
  result['system.config'].common.language = this.context.language;
1881
1897
  }
1882
- SocketCommands._fixCallback(callback, error, result);
1898
+ _a._fixCallback(callback, error, result);
1883
1899
  });
1884
1900
  }
1885
1901
  else {
@@ -1888,7 +1904,7 @@ class SocketCommands {
1888
1904
  }
1889
1905
  catch (error) {
1890
1906
  this.adapter.log.error(`[getObjects] ERROR: ${error.toString()}`);
1891
- SocketCommands._fixCallback(callback, error);
1907
+ _a._fixCallback(callback, error);
1892
1908
  }
1893
1909
  }
1894
1910
  };
@@ -2045,7 +2061,7 @@ class SocketCommands {
2045
2061
  }
2046
2062
  catch (error) {
2047
2063
  this.adapter.log.error(`[getObjectView] ERROR: ${error.toString()}`);
2048
- SocketCommands._fixCallback(callback, error);
2064
+ _a._fixCallback(callback, error);
2049
2065
  }
2050
2066
  }
2051
2067
  }
@@ -2065,11 +2081,11 @@ class SocketCommands {
2065
2081
  this.commands.setObject = (socket, id, obj, callback) => {
2066
2082
  if (this._checkPermissions(socket, 'setObject', callback, id)) {
2067
2083
  try {
2068
- void this.adapter.setForeignObject(id, obj, { user: socket._acl?.user }, (error, ...args) => SocketCommands._fixCallback(callback, error, ...args));
2084
+ void this.adapter.setForeignObject(id, obj, { user: socket._acl?.user }, (error, ...args) => _a._fixCallback(callback, error, ...args));
2069
2085
  }
2070
2086
  catch (error) {
2071
2087
  this.adapter.log.error(`[setObject] ERROR: ${error.toString()}`);
2072
- SocketCommands._fixCallback(callback, error);
2088
+ _a._fixCallback(callback, error);
2073
2089
  }
2074
2090
  }
2075
2091
  };
@@ -2087,16 +2103,16 @@ class SocketCommands {
2087
2103
  if (id.startsWith('flot.') || id.startsWith('fullcalendar.')) {
2088
2104
  if (this._checkPermissions(socket, 'delObject', callback, id)) {
2089
2105
  try {
2090
- this.adapter.delForeignObject(id, { user: socket._acl?.user }, (error, ...args) => SocketCommands._fixCallback(callback, error, ...args));
2106
+ this.adapter.delForeignObject(id, { user: socket._acl?.user }, (error, ...args) => _a._fixCallback(callback, error, ...args));
2091
2107
  }
2092
2108
  catch (error) {
2093
2109
  this.adapter.log.error(`[delObject] ERROR: ${error.toString()}`);
2094
- SocketCommands._fixCallback(callback, error);
2110
+ _a._fixCallback(callback, error);
2095
2111
  }
2096
2112
  }
2097
2113
  }
2098
2114
  else {
2099
- SocketCommands._fixCallback(callback, SocketCommands.ERROR_PERMISSION);
2115
+ _a._fixCallback(callback, _a.ERROR_PERMISSION);
2100
2116
  }
2101
2117
  };
2102
2118
  /**
@@ -2131,7 +2147,7 @@ class SocketCommands {
2131
2147
  this.#clientSubscribes[sid][targetInstance].push(messageType);
2132
2148
  }
2133
2149
  // inform instance about new subscription
2134
- this.adapter.sendTo(targetInstance, 'clientSubscribe', { type: messageType, sid, data }, result => SocketCommands._fixCallback(callback, null, result));
2150
+ this.adapter.sendTo(targetInstance, 'clientSubscribe', { type: messageType, sid, data }, result => _a._fixCallback(callback, null, result), _a.sendOptionsOf(socket));
2135
2151
  };
2136
2152
  /**
2137
2153
  * #DOCUMENTATION commands
@@ -2157,16 +2173,12 @@ class SocketCommands {
2157
2173
  if (pos !== -1) {
2158
2174
  this.#clientSubscribes[sid][targetInstance].splice(pos, 1);
2159
2175
  // inform instance about unsubscription
2160
- this.adapter.sendTo(targetInstance, 'clientUnsubscribe', {
2161
- type: [messageType],
2162
- sid,
2163
- reason: 'client',
2164
- });
2165
- SocketCommands._fixCallback(callback, null, true);
2176
+ this.adapter.sendTo(targetInstance, 'clientUnsubscribe', { type: [messageType], sid, reason: 'client' }, undefined, _a.sendOptionsOf(socket));
2177
+ _a._fixCallback(callback, null, true);
2166
2178
  return;
2167
2179
  }
2168
2180
  }
2169
- SocketCommands._fixCallback(callback, null, false);
2181
+ _a._fixCallback(callback, null, false);
2170
2182
  };
2171
2183
  /**
2172
2184
  * #DOCUMENTATION commands
@@ -2190,7 +2202,7 @@ class SocketCommands {
2190
2202
  obj.native ||= {};
2191
2203
  obj.native.vendor = vendor;
2192
2204
  }
2193
- SocketCommands._fixCallback(callback, error, obj);
2205
+ _a._fixCallback(callback, error, obj);
2194
2206
  });
2195
2207
  }
2196
2208
  };
@@ -2202,15 +2214,26 @@ class SocketCommands {
2202
2214
  this._initCommandsStates();
2203
2215
  this._initCommandsFiles();
2204
2216
  }
2205
- #informAboutDisconnect(socketId) {
2217
+ /**
2218
+ * Tell every instance this socket had subscribed to that it is gone.
2219
+ *
2220
+ * Carries the user of the connection like the explicit `clientUnsubscribe` does: an instance that
2221
+ * keeps something per user - a recording, a session, a pending request - learns whose it was,
2222
+ * instead of only which socket id disappeared.
2223
+ *
2224
+ * @param socket the socket that went away
2225
+ */
2226
+ #informAboutDisconnect(socket) {
2227
+ const socketId = socket.id;
2206
2228
  // say to all instances that this socket was disconnected
2207
2229
  if (this.#clientSubscribes[socketId]) {
2230
+ const options = _a.sendOptionsOf(socket);
2208
2231
  Object.keys(this.#clientSubscribes[socketId]).forEach(targetInstance => {
2209
2232
  this.adapter.sendTo(targetInstance, 'clientUnsubscribe', {
2210
2233
  type: this.#clientSubscribes[socketId][targetInstance],
2211
2234
  sid: socketId,
2212
2235
  reason: 'disconnect',
2213
- });
2236
+ }, undefined, options);
2214
2237
  });
2215
2238
  delete this.#clientSubscribes[socketId];
2216
2239
  }
@@ -2220,7 +2243,7 @@ class SocketCommands {
2220
2243
  // Check if the authentication is still valid. Announcing a new access token is the only way
2221
2244
  // to make an expired session valid again, so that command must pass the check - otherwise
2222
2245
  // a client whose token has expired could never recover without reloading the page.
2223
- if (SocketCommands.COMMANDS_WITHOUT_SESSION_CHECK.includes(command) || this.#updateSession(socket)) {
2246
+ if (_a.COMMANDS_WITHOUT_SESSION_CHECK.includes(command) || this.#updateSession(socket)) {
2224
2247
  this.commands[command](socket, ...args);
2225
2248
  }
2226
2249
  else {
@@ -2236,4 +2259,5 @@ class SocketCommands {
2236
2259
  }
2237
2260
  }
2238
2261
  exports.SocketCommands = SocketCommands;
2262
+ _a = SocketCommands;
2239
2263
  //# sourceMappingURL=socketCommands.js.map