@iobroker/adapter-react-v5 4.12.3 → 4.13.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.
@@ -31,6 +31,7 @@ export declare const ERRORS: {
31
31
  PERMISSION_ERROR: string;
32
32
  NOT_CONNECTED: string;
33
33
  };
34
+ export type BinaryStateChangeHandler = (id: string, base64: string | null) => void;
34
35
  /** Converts ioB pattern into regex */
35
36
  export declare function pattern2RegEx(pattern: string): string;
36
37
  interface ConnectionProps {
@@ -173,9 +174,9 @@ declare class Connection {
173
174
  /** The ioBroker state ID. */
174
175
  id: string | string[],
175
176
  /** Set to true if the given state is binary and requires Base64 decoding. */
176
- binary: boolean | ioBroker.StateChangeHandler | ((id: string, base64: string) => void),
177
+ binary: boolean | ioBroker.StateChangeHandler | BinaryStateChangeHandler,
177
178
  /** The callback. */
178
- cb?: ioBroker.StateChangeHandler | ((id: string, base64: string) => void)): void;
179
+ cb?: ioBroker.StateChangeHandler | BinaryStateChangeHandler): void;
179
180
  /**
180
181
  * Subscribe to changes of the given state.
181
182
  */
@@ -191,7 +192,7 @@ declare class Connection {
191
192
  /** The ioBroker state ID or array of states */
192
193
  id: string | string[],
193
194
  /** The callback. */
194
- cb?: ioBroker.StateChangeHandler | ((id: string, base64: string) => void)): void;
195
+ cb?: ioBroker.StateChangeHandler | BinaryStateChangeHandler): void;
195
196
  /**
196
197
  * Subscribe to changes of the given object.
197
198
  */
@@ -479,24 +479,26 @@ class Connection {
479
479
  !this.statesSubscribes[_id].cbs.includes(cb) && this.statesSubscribes[_id].cbs.push(cb);
480
480
  }
481
481
  }
482
- if (toSubscribe.length && this.connected) {
482
+ if (!this.connected) {
483
+ return;
484
+ }
485
+ if (toSubscribe.length) {
483
486
  // no answer from server required
484
487
  this._socket.emit('subscribe', toSubscribe);
485
488
  }
486
- if (typeof cb === 'function' && this.connected) {
487
- if (binary) {
488
- // todo: if array of ids
489
- this.getBinaryState(ids[0])
490
- .then((base64) => cb && cb(ids[0], base64))
491
- .catch(e => console.error(`Cannot getForeignStates "${id}": ${JSON.stringify(e)}`));
492
- }
493
- else {
494
- this._socket.emit(Connection.isWeb() ? 'getStates' : 'getForeignStates', id, (err, states) => {
495
- err && console.error(`Cannot getForeignStates "${id}": ${JSON.stringify(err)}`);
496
- states && Object.keys(states).forEach(_id => cb(_id, states[_id]));
497
- });
489
+ if (binary) {
490
+ for (let i = 0; i < ids.length; i++) {
491
+ this.getBinaryState(ids[i])
492
+ .then((base64) => cb && cb(ids[i], base64))
493
+ .catch(e => console.error(`Cannot getBinaryState "${ids[i]}": ${JSON.stringify(e)}`));
498
494
  }
499
495
  }
496
+ else {
497
+ this._socket.emit(Connection.isWeb() ? 'getStates' : 'getForeignStates', id, (err, states) => {
498
+ err && console.error(`Cannot getForeignStates "${id}": ${JSON.stringify(err)}`);
499
+ states && Object.keys(states).forEach(_id => cb(_id, states[_id]));
500
+ });
501
+ }
500
502
  }
501
503
  /**
502
504
  * Subscribe to changes of the given state.
package/README.md CHANGED
@@ -670,6 +670,9 @@ socket.getObjectViewCustom('custom', 'state', 'startKey', 'endKey')
670
670
  -->
671
671
 
672
672
  ## Changelog
673
+ ### 4.13.0 (2024-03-30)
674
+ * (bluefox) used new connection classes
675
+
673
676
  ### 4.12.3 (2024-03-30)
674
677
  * (bluefox) Migrated legacy connection to typescript
675
678
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@iobroker/adapter-react-v5",
3
- "version": "4.12.3",
3
+ "version": "4.13.0",
4
4
  "description": "React classes to develop admin interfaces for ioBroker with react.",
5
5
  "author": {
6
6
  "name": "Denis Haev (bluefox)",
@@ -28,19 +28,19 @@
28
28
  "devDependencies": {},
29
29
  "dependencies": {
30
30
  "@emotion/react": "^11.11.4",
31
- "@emotion/styled": "^11.11.0",
31
+ "@emotion/styled": "^11.11.5",
32
32
  "@iobroker/dm-utils": "^0.1.9",
33
- "@iobroker/json-config": "^6.14.1",
34
- "@iobroker/socket-client": "^2.3.16",
33
+ "@iobroker/json-config": "^6.15.2",
34
+ "@iobroker/socket-client": "^2.4.0",
35
35
  "@iobroker/types": "^5.0.19",
36
36
  "@iobroker/js-controller-common": "^5.0.19",
37
37
  "@iobroker/js-controller-common-db": "^5.0.19",
38
- "@mui/icons-material": "^5.15.11",
38
+ "@mui/icons-material": "^5.15.14",
39
39
  "@mui/material": "5.14.14",
40
40
  "@mui/styles": "5.14.14",
41
- "@mui/x-date-pickers": "^6.19.5",
42
- "@sentry/browser": "^7.104.0",
43
- "@sentry/integrations": "^7.106.0",
41
+ "@mui/x-date-pickers": "^7.1.0",
42
+ "@sentry/browser": "^7.109.0",
43
+ "@sentry/integrations": "^7.109.0",
44
44
  "react-color": "^2.19.3",
45
45
  "react-colorful": "^5.6.1",
46
46
  "react-cropper": "^2.3.3",