@iobroker/socket-classes 1.1.3 → 1.1.5

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
@@ -888,6 +888,9 @@ Read all instances of the given adapter, or all instances of all adapters if ada
888
888
  -->
889
889
 
890
890
  ## Changelog
891
+ ### 1.1.5 (2023-03-13)
892
+ * (bluefox) Added command `name`
893
+
891
894
  ### 1.1.3 (2023-03-12)
892
895
  * (bluefox) Treat `json5` as `json`
893
896
 
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Class Socket
3
3
  *
4
- * Copyright 2014-2022 bluefox <dogafox@gmail.com>,
4
+ * Copyright 2014-2023 bluefox <dogafox@gmail.com>,
5
5
  * MIT License
6
6
  *
7
7
  */
@@ -271,22 +271,24 @@ class SocketCommon {
271
271
 
272
272
  this._updateConnectedInfo();
273
273
 
274
- this.commands.applyCommands(socket);
274
+ if (!this.commands.getCommandHandler('name')) {
275
+ // socket sends its name => update list of sockets
276
+ this.addCommandHandler('name', (_socket, name, cb) => {
277
+ this.adapter.log.debug(`Connection from "${name}"`);
278
+ if (_socket._name === undefined) {
279
+ _socket._name = name;
280
+ this._updateConnectedInfo();
281
+ } else if (_socket._name !== name) {
282
+ this.adapter.log.warn(`socket ${_socket.id} changed socket name from ${_socket._name} to ${name}`);
283
+ _socket._name = name;
284
+ this._updateConnectedInfo();
285
+ }
275
286
 
276
- // socket sends its name => update list of sockets
277
- socket.on('name', (name, cb) => {
278
- this.adapter.log.debug(`Connection from "${name}"`);
279
- if (socket._name === undefined) {
280
- socket._name = name;
281
- this._updateConnectedInfo();
282
- } else if (socket._name !== name) {
283
- this.adapter.log.warn(`socket ${socket.id} changed socket name from ${socket._name} to ${name}`);
284
- socket._name = name;
285
- this._updateConnectedInfo();
286
- }
287
+ typeof cb === 'function' && cb();
288
+ });
289
+ }
287
290
 
288
- typeof cb === 'function' && cb();
289
- });
291
+ this.commands.applyCommands(socket);
290
292
 
291
293
  // disconnect
292
294
  socket.on('disconnect', error => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@iobroker/socket-classes",
3
- "version": "1.1.3",
3
+ "version": "1.1.5",
4
4
  "description": "ioBroker server-side web sockets",
5
5
  "author": {
6
6
  "name": "bluefox",