@iobroker/socket-classes 1.1.2 → 1.1.4

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,12 @@ 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.4 (2023-03-13)
892
+ * (bluefox) Added command `name`
893
+
894
+ ### 1.1.3 (2023-03-12)
895
+ * (bluefox) Treat `json5` as `json`
896
+
891
897
  ### 1.1.2 (2023-03-03)
892
898
  * (bluefox) Allow deletion of fullcalendar objects
893
899
 
@@ -850,7 +850,7 @@ class SocketCommands {
850
850
  let data64;
851
851
  if (buffer) {
852
852
  try {
853
- if (type === 'application/json') {
853
+ if (type === 'application/json' || type === 'application/json5' || fileName.toLowerCase().endsWith('.json5')) {
854
854
  data64 = Buffer.from(encodeURIComponent(buffer)).toString('base64');
855
855
  } else {
856
856
  if (typeof buffer === 'string') {
@@ -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,26 @@ class SocketCommon {
271
271
 
272
272
  this._updateConnectedInfo();
273
273
 
274
- this.commands.applyCommands(socket);
274
+ const commands = this.commands.getCommandHandler();
275
+
276
+ if (!commands['name']) {
277
+ // socket sends its name => update list of sockets
278
+ commands['name'] = (_socket, name, cb) => {
279
+ this.adapter.log.debug(`Connection from "${name}"`);
280
+ if (_socket._name === undefined) {
281
+ _socket._name = name;
282
+ this._updateConnectedInfo();
283
+ } else if (_socket._name !== name) {
284
+ this.adapter.log.warn(`socket ${_socket.id} changed socket name from ${_socket._name} to ${name}`);
285
+ _socket._name = name;
286
+ this._updateConnectedInfo();
287
+ }
275
288
 
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
- }
289
+ typeof cb === 'function' && cb();
290
+ };
291
+ }
287
292
 
288
- typeof cb === 'function' && cb();
289
- });
293
+ this.commands.applyCommands(socket);
290
294
 
291
295
  // disconnect
292
296
  socket.on('disconnect', error => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@iobroker/socket-classes",
3
- "version": "1.1.2",
3
+ "version": "1.1.4",
4
4
  "description": "ioBroker server-side web sockets",
5
5
  "author": {
6
6
  "name": "bluefox",