@project-chip/matter-node.js-examples 0.7.5-alpha.0-20240222-8696097f → 0.8.0-alpha.1-20240308-033110a3

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.
Files changed (74) hide show
  1. package/README.md +44 -0
  2. package/dist/esm/examples/BridgedDeviceNode.js +147 -0
  3. package/dist/esm/examples/BridgedDeviceNode.js.map +7 -0
  4. package/dist/esm/examples/{BridgedDevicesNode.js → BridgedDevicesNodeLegacy.js} +2 -2
  5. package/dist/esm/examples/BridgedDevicesNodeLegacy.js.map +7 -0
  6. package/dist/esm/examples/ComposedDeviceNode.js +116 -127
  7. package/dist/esm/examples/ComposedDeviceNode.js.map +3 -3
  8. package/dist/esm/examples/ComposedDeviceNodeLegacy.js +138 -0
  9. package/dist/esm/examples/ComposedDeviceNodeLegacy.js.map +7 -0
  10. package/dist/esm/examples/ControllerNode.js +24 -20
  11. package/dist/esm/examples/ControllerNode.js.map +2 -2
  12. package/dist/esm/examples/ControllerNodeLegacy.js +227 -0
  13. package/dist/esm/examples/ControllerNodeLegacy.js.map +7 -0
  14. package/dist/esm/examples/DeviceNode.js +118 -159
  15. package/dist/esm/examples/DeviceNode.js.map +2 -2
  16. package/dist/esm/examples/DeviceNodeFull.js +253 -0
  17. package/dist/esm/examples/DeviceNodeFull.js.map +7 -0
  18. package/dist/esm/examples/DeviceNodeFullLegacy.js +171 -0
  19. package/dist/esm/examples/DeviceNodeFullLegacy.js.map +7 -0
  20. package/dist/esm/examples/IlluminatedRollerShade.js +85 -0
  21. package/dist/esm/examples/IlluminatedRollerShade.js.map +7 -0
  22. package/dist/esm/examples/LightDevice.js +34 -0
  23. package/dist/esm/examples/LightDevice.js.map +7 -0
  24. package/dist/esm/examples/MultiDeviceNode.js +133 -134
  25. package/dist/esm/examples/MultiDeviceNode.js.map +3 -3
  26. package/dist/esm/examples/MultiDeviceNodeLegacy.js +146 -0
  27. package/dist/esm/examples/MultiDeviceNodeLegacy.js.map +7 -0
  28. package/dist/esm/examples/SensorDeviceNode.js +167 -0
  29. package/dist/esm/examples/SensorDeviceNode.js.map +7 -0
  30. package/dist/esm/examples/cluster/DummyThreadNetworkCommissioningServer.js +115 -0
  31. package/dist/esm/examples/cluster/DummyThreadNetworkCommissioningServer.js.map +7 -0
  32. package/dist/esm/examples/cluster/DummyWifiNetworkCommissioningServer.js +115 -0
  33. package/dist/esm/examples/cluster/DummyWifiNetworkCommissioningServer.js.map +7 -0
  34. package/dist/esm/examples/cluster/{DummyWifiNetworkCommissioningClusterServer.js → DummyWifiNetworkCommissioningServerLegacy.js} +16 -14
  35. package/dist/esm/examples/cluster/DummyWifiNetworkCommissioningServerLegacy.js.map +7 -0
  36. package/dist/esm/examples/cluster/MyFancyOwnFunctionality.js +110 -0
  37. package/dist/esm/examples/cluster/MyFancyOwnFunctionality.js.map +7 -0
  38. package/dist/esm/tutorial/example01.js +5 -0
  39. package/dist/esm/tutorial/example01.js.map +7 -0
  40. package/dist/esm/tutorial/example02.js +7 -0
  41. package/dist/esm/tutorial/example02.js.map +7 -0
  42. package/dist/esm/tutorial/example03.js +15 -0
  43. package/dist/esm/tutorial/example03.js.map +7 -0
  44. package/dist/esm/tutorial/example04.js +10 -0
  45. package/dist/esm/tutorial/example04.js.map +7 -0
  46. package/dist/esm/tutorial/example05.js +14 -0
  47. package/dist/esm/tutorial/example05.js.map +7 -0
  48. package/package.json +9 -6
  49. package/src/examples/BridgedDeviceNode.ts +260 -0
  50. package/src/examples/{BridgedDevicesNode.ts → BridgedDevicesNodeLegacy.ts} +6 -1
  51. package/src/examples/ComposedDeviceNode.ts +173 -223
  52. package/src/examples/ComposedDeviceNodeLegacy.ts +252 -0
  53. package/src/examples/ControllerNode.ts +28 -22
  54. package/src/examples/ControllerNodeLegacy.ts +354 -0
  55. package/src/examples/DeviceNode.ts +173 -273
  56. package/src/examples/DeviceNodeFull.ts +440 -0
  57. package/src/examples/DeviceNodeFullLegacy.ts +307 -0
  58. package/src/examples/IlluminatedRollerShade.ts +130 -0
  59. package/src/examples/LightDevice.ts +60 -0
  60. package/src/examples/MultiDeviceNode.ts +184 -236
  61. package/src/examples/MultiDeviceNodeLegacy.ts +267 -0
  62. package/src/examples/SensorDeviceNode.ts +236 -0
  63. package/src/examples/cluster/DummyThreadNetworkCommissioningServer.ts +156 -0
  64. package/src/examples/cluster/DummyWifiNetworkCommissioningServer.ts +153 -0
  65. package/src/examples/cluster/{DummyWifiNetworkCommissioningClusterServer.ts → DummyWifiNetworkCommissioningServerLegacy.ts} +16 -13
  66. package/src/examples/cluster/MyFancyOwnFunctionality.ts +185 -0
  67. package/src/tsconfig.json +9 -1
  68. package/src/tutorial/example01.ts +6 -0
  69. package/src/tutorial/example02.ts +9 -0
  70. package/src/tutorial/example03.ts +19 -0
  71. package/src/tutorial/example04.ts +13 -0
  72. package/src/tutorial/example05.ts +19 -0
  73. package/dist/esm/examples/BridgedDevicesNode.js.map +0 -7
  74. package/dist/esm/examples/cluster/DummyWifiNetworkCommissioningClusterServer.js.map +0 -7
@@ -0,0 +1,153 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2022-2024 Matter.js Authors
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+
7
+ import { GeneralCommissioningBehavior } from "@project-chip/matter.js/behavior/definitions/general-commissioning";
8
+ import {
9
+ AddOrUpdateWiFiNetworkRequest,
10
+ ConnectNetworkRequest,
11
+ NetworkCommissioningBehavior,
12
+ RemoveNetworkRequest,
13
+ ReorderNetworkRequest,
14
+ ScanNetworksRequest,
15
+ } from "@project-chip/matter.js/behavior/definitions/network-commissioning";
16
+ import { NetworkCommissioning } from "@project-chip/matter.js/cluster";
17
+ import { ByteArray } from "@project-chip/matter.js/util";
18
+
19
+ const firstNetworkId = new ByteArray(32);
20
+
21
+ /**
22
+ * This represents a Dummy version of a Wifi Network Commissioning Cluster Server without real Wifi related logic, beside
23
+ * returning some values provided as CLI parameters. This dummy implementation is only there for tests/as showcase for BLE
24
+ * commissioning of a device.
25
+ */
26
+ export class DummyWifiNetworkCommissioningServer extends NetworkCommissioningBehavior.with(
27
+ NetworkCommissioning.Feature.WiFiNetworkInterface,
28
+ ) {
29
+ override scanNetworks({ ssid, breadcrumb }: ScanNetworksRequest) {
30
+ console.log(`---> scanNetworks called on NetworkCommissioning cluster: ${ssid?.toHex()} ${breadcrumb}`);
31
+
32
+ // Simulate successful scan
33
+ if (breadcrumb !== undefined) {
34
+ const generalCommissioningCluster = this.agent.get(GeneralCommissioningBehavior);
35
+ generalCommissioningCluster.state.breadcrumb = breadcrumb;
36
+ }
37
+
38
+ const networkingStatus = NetworkCommissioning.NetworkCommissioningStatus.Success;
39
+ this.state.lastNetworkingStatus = networkingStatus;
40
+
41
+ return {
42
+ networkingStatus,
43
+ wiFiScanResults: [
44
+ {
45
+ security: {
46
+ unencrypted: false,
47
+ wep: false,
48
+ wpaPersonal: false,
49
+ wpa2Personal: true,
50
+ wpa3Personal: true,
51
+ },
52
+ ssid: ssid || ByteArray.fromString(this.endpoint.env.vars.get("ble.wifi.scanSsid") ?? "TestSSID"), // Set a valid existing local Wi-Fi SSID here
53
+ bssid: ByteArray.fromString(
54
+ this.endpoint.env.vars.get("ble.wifi.scanBssid") ?? "00:00:00:00:00:00",
55
+ ),
56
+ channel: 1,
57
+ },
58
+ ],
59
+ };
60
+ }
61
+
62
+ override addOrUpdateWiFiNetwork({ ssid, credentials, breadcrumb }: AddOrUpdateWiFiNetworkRequest) {
63
+ console.log(
64
+ `---> addOrUpdateWiFiNetwork called on NetworkCommissioning cluster: ${ssid.toHex()} ${credentials.toHex()} ${breadcrumb}`,
65
+ );
66
+
67
+ this.session.context.assertFailSafeArmed("Failsafe timer needs to be armed to add or update networks.");
68
+
69
+ // Simulate successful add or update
70
+ if (breadcrumb !== undefined) {
71
+ const generalCommissioningCluster = this.agent.get(GeneralCommissioningBehavior);
72
+ generalCommissioningCluster.state.breadcrumb = breadcrumb;
73
+ }
74
+
75
+ const networkingStatus = NetworkCommissioning.NetworkCommissioningStatus.Success;
76
+ this.state.lastNetworkingStatus = networkingStatus;
77
+ this.state.lastNetworkId = firstNetworkId;
78
+
79
+ return {
80
+ networkingStatus,
81
+ networkIndex: 0,
82
+ };
83
+ }
84
+
85
+ override removeNetwork({ networkId, breadcrumb }: RemoveNetworkRequest) {
86
+ console.log(`---> removeNetwork called on NetworkCommissioning cluster: ${networkId.toHex()} ${breadcrumb}`);
87
+
88
+ this.session.context.assertFailSafeArmed("Failsafe timer needs to be armed to add or update networks.");
89
+
90
+ // Simulate successful add or update
91
+ if (breadcrumb !== undefined) {
92
+ const generalCommissioningCluster = this.agent.get(GeneralCommissioningBehavior);
93
+ generalCommissioningCluster.state.breadcrumb = breadcrumb;
94
+ }
95
+
96
+ const networkingStatus = NetworkCommissioning.NetworkCommissioningStatus.Success;
97
+ this.state.lastNetworkingStatus = networkingStatus;
98
+ this.state.lastNetworkId = firstNetworkId;
99
+
100
+ return {
101
+ networkingStatus,
102
+ networkIndex: 0,
103
+ };
104
+ }
105
+
106
+ override async connectNetwork({ networkId, breadcrumb }: ConnectNetworkRequest) {
107
+ console.log(`---> connectNetwork called on NetworkCommissioning cluster: ${networkId.toHex()} ${breadcrumb}`);
108
+
109
+ this.session.context.assertFailSafeArmed("Failsafe timer needs to be armed to add or update networks.");
110
+
111
+ // Simulate successful connection
112
+ if (breadcrumb !== undefined) {
113
+ const generalCommissioningCluster = this.agent.get(GeneralCommissioningBehavior);
114
+ generalCommissioningCluster.state.breadcrumb = breadcrumb;
115
+ }
116
+
117
+ this.state.networks[0].connected = true;
118
+
119
+ const networkingStatus = NetworkCommissioning.NetworkCommissioningStatus.Success;
120
+ this.state.lastNetworkingStatus = networkingStatus;
121
+ this.state.lastNetworkId = firstNetworkId;
122
+ this.state.lastConnectErrorValue = null;
123
+
124
+ // Announce operational in IP network
125
+ const device = this.session.context;
126
+ await device.startAnnouncement();
127
+
128
+ return {
129
+ networkingStatus,
130
+ errorValue: null,
131
+ };
132
+ }
133
+
134
+ override reorderNetwork({ networkId, networkIndex, breadcrumb }: ReorderNetworkRequest) {
135
+ console.log(
136
+ `---> reorderNetwork called on NetworkCommissioning cluster: ${networkId.toHex()} ${networkIndex} ${breadcrumb}`,
137
+ );
138
+
139
+ // Simulate successful connection
140
+ if (breadcrumb !== undefined) {
141
+ const generalCommissioningCluster = this.agent.get(GeneralCommissioningBehavior);
142
+ generalCommissioningCluster.state.breadcrumb = breadcrumb;
143
+ }
144
+
145
+ const networkingStatus = NetworkCommissioning.NetworkCommissioningStatus.Success;
146
+ this.state.lastNetworkingStatus = networkingStatus;
147
+
148
+ return {
149
+ networkingStatus,
150
+ networkIndex: 0,
151
+ };
152
+ }
153
+ }
@@ -1,16 +1,17 @@
1
1
  /**
2
2
  * @license
3
- * Copyright 2022 The node-matter Authors
3
+ * Copyright 2022-2024 Matter.js Authors
4
4
  * SPDX-License-Identifier: Apache-2.0
5
5
  */
6
6
 
7
+ import { getParameter } from "@project-chip/matter-node.js/util";
7
8
  import {
8
9
  ClusterServer,
9
10
  ClusterServerObjForCluster,
10
11
  GeneralCommissioningCluster,
11
12
  NetworkCommissioning,
12
- } from "@project-chip/matter-node.js/cluster";
13
- import { ByteArray, getParameter } from "@project-chip/matter-node.js/util";
13
+ } from "@project-chip/matter.js/cluster";
14
+ import { ByteArray } from "@project-chip/matter.js/util";
14
15
 
15
16
  const firstNetworkId = new ByteArray(32);
16
17
 
@@ -21,7 +22,7 @@ const WifiNetworkCluster = NetworkCommissioning.Cluster.with(NetworkCommissionin
21
22
  * returning some values provided as CLI parameters. This dummy implementation is only there for tests/as showcase for BLE
22
23
  * commissioning of a device.
23
24
  */
24
- export default ClusterServer(
25
+ const Server: ClusterServerObjForCluster<typeof WifiNetworkCluster> = ClusterServer(
25
26
  NetworkCommissioning.Cluster.with(NetworkCommissioning.Feature.WiFiNetworkInterface),
26
27
  {
27
28
  maxNetworks: 1,
@@ -74,7 +75,7 @@ export default ClusterServer(
74
75
  `---> addOrUpdateWiFiNetwork called on NetworkCommissioning cluster: ${ssid.toHex()} ${credentials.toHex()} ${breadcrumb}`,
75
76
  );
76
77
 
77
- session.getContext().assertFailSafeArmed("Failsafe timer needs to be armed to add or update networks.");
78
+ session.context.assertFailSafeArmed("Failsafe timer needs to be armed to add or update networks.");
78
79
 
79
80
  // Simulate successful add or update
80
81
  if (breadcrumb !== undefined) {
@@ -87,7 +88,7 @@ export default ClusterServer(
87
88
  lastNetworkId?.setLocal(firstNetworkId);
88
89
 
89
90
  return {
90
- networkingStatus: NetworkCommissioning.NetworkCommissioningStatus.Success,
91
+ networkingStatus,
91
92
  networkIndex: 0,
92
93
  };
93
94
  },
@@ -101,7 +102,7 @@ export default ClusterServer(
101
102
  `---> removeNetwork called on NetworkCommissioning cluster: ${networkId.toHex()} ${breadcrumb}`,
102
103
  );
103
104
 
104
- session.getContext().assertFailSafeArmed("Failsafe timer needs to be armed to add or update networks.");
105
+ session.context.assertFailSafeArmed("Failsafe timer needs to be armed to add or update networks.");
105
106
 
106
107
  // Simulate successful add or update
107
108
  if (breadcrumb !== undefined) {
@@ -114,7 +115,7 @@ export default ClusterServer(
114
115
  lastNetworkId?.setLocal(firstNetworkId);
115
116
 
116
117
  return {
117
- networkingStatus: NetworkCommissioning.NetworkCommissioningStatus.Success,
118
+ networkingStatus,
118
119
  networkIndex: 0,
119
120
  };
120
121
  },
@@ -128,7 +129,7 @@ export default ClusterServer(
128
129
  `---> connectNetwork called on NetworkCommissioning cluster: ${networkId.toHex()} ${breadcrumb}`,
129
130
  );
130
131
 
131
- session.getContext().assertFailSafeArmed("Failsafe timer needs to be armed to add or update networks.");
132
+ session.context.assertFailSafeArmed("Failsafe timer needs to be armed to add or update networks.");
132
133
 
133
134
  // Simulate successful connection
134
135
  if (breadcrumb !== undefined) {
@@ -146,11 +147,11 @@ export default ClusterServer(
146
147
  lastConnectErrorValue?.setLocal(null);
147
148
 
148
149
  // Announce operational in IP network
149
- const device = session.getContext();
150
+ const device = session.context;
150
151
  await device.startAnnouncement();
151
152
 
152
153
  return {
153
- networkingStatus: NetworkCommissioning.NetworkCommissioningStatus.Success,
154
+ networkingStatus,
154
155
  errorValue: null,
155
156
  };
156
157
  },
@@ -173,9 +174,11 @@ export default ClusterServer(
173
174
  lastNetworkingStatus?.setLocal(networkingStatus);
174
175
 
175
176
  return {
176
- networkingStatus: NetworkCommissioning.NetworkCommissioningStatus.Success,
177
+ networkingStatus,
177
178
  networkIndex: 0,
178
179
  };
179
180
  },
180
181
  },
181
- ) as ClusterServerObjForCluster<typeof WifiNetworkCluster>;
182
+ );
183
+
184
+ export default Server;
@@ -0,0 +1,185 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2022-2024 Matter.js Authors
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+
7
+ import { ClusterBehavior } from "@project-chip/matter.js/behavior/cluster";
8
+ import {
9
+ Attribute,
10
+ ClusterRegistry,
11
+ Command,
12
+ Event,
13
+ EventPriority,
14
+ MutableCluster,
15
+ } from "@project-chip/matter.js/cluster";
16
+ import { ClusterId, VendorId } from "@project-chip/matter.js/datatype";
17
+ import {
18
+ AttributeElement,
19
+ ClusterElement,
20
+ ClusterModel,
21
+ CommandElement,
22
+ EventElement,
23
+ FieldElement,
24
+ } from "@project-chip/matter.js/model";
25
+ import { TlvField, TlvInt16, TlvNullable, TlvObject, TlvString, TypeFromSchema } from "@project-chip/matter.js/tlv";
26
+ import { Identity, MaybePromise } from "@project-chip/matter.js/util";
27
+
28
+ /** Define the Cluster ID, custom clusters use a special extended formt that also contains the Vendor Id */
29
+ const myFancyClusterId = ClusterId.buildVendorSpecific(VendorId(0xfff4), 0xfc00);
30
+
31
+ /**
32
+ * Defines the Cluster on Tlv Schema level in a special namespace structure to match the official cluster
33
+ * structures of matter.js.
34
+ * All places that contains "MyFancy..." belong to the custom cluster details, all rest can be left statically like the
35
+ * given names.
36
+ * For more examples and usages of features in such clusters and how the code should look then check the standard
37
+ * cluster Tlv definitions in packages/matter.js/cluster/definitions/*
38
+ */
39
+ export namespace MyFancyOwnFunctionality {
40
+ /**
41
+ * Input to the MyFancyOwnFunctionality myFancyCommand command
42
+ */
43
+ export const TlvMyFancyCommandRequest = TlvObject({ value: TlvField(0, TlvString) });
44
+
45
+ /**
46
+ * Response of the MyFancyOwnFunctionality myFancyCommand command
47
+ */
48
+ export const TlvMyFancyCommandResponse = TlvObject({ response: TlvField(0, TlvString) });
49
+
50
+ /**
51
+ * Event for the MyFancyOwnFunctionality myFancyEvent event
52
+ */
53
+ export const TlvMyFancyEvent = TlvObject({ eventValue: TlvField(0, TlvString) });
54
+
55
+ /**
56
+ * @see {@link Cluster}
57
+ */
58
+ export const ClusterInstance = MutableCluster({
59
+ id: myFancyClusterId,
60
+ name: "MyFancyOwnFunctionality",
61
+ revision: 1,
62
+
63
+ attributes: {
64
+ /** My fancy attribute */
65
+ myFancyValue: Attribute(0x0, TlvNullable(TlvInt16)),
66
+ },
67
+
68
+ commands: {
69
+ /** My fancy command */
70
+ myFancyCommand: Command(0x1, TlvMyFancyCommandRequest, 0x2, TlvMyFancyCommandResponse),
71
+ },
72
+
73
+ events: {
74
+ /** My fancy event */
75
+ myFancyEvent: Event(0x5, EventPriority.Info, TlvMyFancyEvent),
76
+ },
77
+ });
78
+
79
+ /**
80
+ * My Fancy Cluster
81
+ *
82
+ * This cluster provides an interface to some fancy custom functions.
83
+ */
84
+ export interface Cluster extends Identity<typeof ClusterInstance> {}
85
+
86
+ export const Cluster: Cluster = ClusterInstance;
87
+
88
+ export const Complete = Cluster;
89
+ }
90
+
91
+ export type MyFancyOwnFunctionalityCluster = MyFancyOwnFunctionality.Cluster;
92
+ export const MyFancyOwnFunctionalityCluster = MyFancyOwnFunctionality.Cluster;
93
+ ClusterRegistry.register(MyFancyOwnFunctionality.Complete);
94
+
95
+ /**
96
+ * matter.js Model Schema for the cluster, need to match with the Tlv Schema above.
97
+ * See more details in packages/matter.js/behavior/definitions/*
98
+ */
99
+ const MyFancySchema = ClusterElement({
100
+ name: "MyFancyOwnFunctionality",
101
+ id: myFancyClusterId,
102
+ classification: "application",
103
+ description: "My Fancy Functionality",
104
+
105
+ children: [
106
+ AttributeElement({ name: "ClusterRevision", id: 0xfffd, type: "ClusterRevision", default: 1 }),
107
+
108
+ AttributeElement({
109
+ name: "MyFancyValue",
110
+ id: 0x0,
111
+ type: "int16",
112
+ access: "R V",
113
+ conformance: "M",
114
+ quality: "X",
115
+ }),
116
+
117
+ CommandElement({
118
+ name: "MyFancyCommand",
119
+ id: 0x1,
120
+ access: "O",
121
+ conformance: "M",
122
+ direction: "request",
123
+ response: "MyFancyCommandResponse",
124
+
125
+ children: [FieldElement({ name: "value", id: 0x0, type: "string", conformance: "M" })],
126
+ }),
127
+ CommandElement({
128
+ name: "MyFancyCommandResponse",
129
+ id: 0x2,
130
+ conformance: "M",
131
+ direction: "request",
132
+
133
+ children: [FieldElement({ name: "response", id: 0x0, type: "string", conformance: "M" })],
134
+ }),
135
+
136
+ EventElement({
137
+ name: "MyFancyEvent",
138
+ id: 0x5,
139
+ access: "V",
140
+ conformance: "O",
141
+ priority: "info",
142
+ children: [
143
+ FieldElement({
144
+ name: "EventValue",
145
+ id: 0x0,
146
+ type: "string",
147
+ conformance: "M",
148
+ }),
149
+ ],
150
+ }),
151
+ ],
152
+ });
153
+
154
+ /**
155
+ * Interface definitions - exposes the Implementation interface for the cluster and some types to be used in the
156
+ * cluster implementations.
157
+ */
158
+ export type MyFancyCommandRequest = TypeFromSchema<typeof MyFancyOwnFunctionality.TlvMyFancyCommandRequest>;
159
+ export type MyFancyCommandResponse = TypeFromSchema<typeof MyFancyOwnFunctionality.TlvMyFancyCommandResponse>;
160
+ export type MyFancyEvent = TypeFromSchema<typeof MyFancyOwnFunctionality.TlvMyFancyEvent>;
161
+
162
+ export namespace MyFancyOwnFunctionalityInterface {
163
+ export interface Base {
164
+ myFancyCommand(request: MyFancyCommandRequest): MaybePromise<MyFancyCommandResponse>;
165
+ }
166
+ }
167
+
168
+ export type MyFancyOwnFunctionalityInterface = {
169
+ components: [{ flags: {}; methods: MyFancyOwnFunctionalityInterface.Base }];
170
+ };
171
+
172
+ /**
173
+ * Behavior definition for the cluster command handler implementation
174
+ */
175
+ export const MyFancyOwnFunctionalityBehavior = ClusterBehavior.withInterface<MyFancyOwnFunctionalityInterface>().for(
176
+ MyFancyOwnFunctionality.Cluster,
177
+ new ClusterModel(MyFancySchema),
178
+ );
179
+
180
+ type MyFancyOwnFunctionalityBehaviorType = InstanceType<typeof MyFancyOwnFunctionalityBehavior>;
181
+ export interface TemperatureMeasurementBehavior extends MyFancyOwnFunctionalityBehaviorType {}
182
+ type StateType = InstanceType<typeof MyFancyOwnFunctionalityBehavior.State>;
183
+ export namespace MyFancyOwnFunctionalityBehavior {
184
+ export interface State extends StateType {}
185
+ }
package/src/tsconfig.json CHANGED
@@ -2,7 +2,15 @@
2
2
  "extends": "../../matter.js-tools/tsconfig.base.json",
3
3
  "compilerOptions": {
4
4
  "outDir": "../dist/esm",
5
- "types": ["node"]
5
+ "types": ["node"],
6
+
7
+ // See https://github.com/microsoft/TypeScript/issues/47663#issuecomment-1519138189
8
+ // r.e. error TS2742
9
+ // Probably referencing matter.js project directly would also solve but there's no reason for us to emit
10
+ // declarations anyway
11
+ "declaration": false,
12
+ "composite": false,
13
+ "declarationMap": false,
6
14
  },
7
15
  "references": [{ "path": "../../matter-node.js/src" }, { "path": "../../matter-node-ble.js/src" }]
8
16
  }
@@ -0,0 +1,6 @@
1
+ import "@project-chip/matter-node.js";
2
+ import { ServerNode } from "@project-chip/matter.js/node";
3
+
4
+ const node = await ServerNode.create();
5
+
6
+ await node.run();
@@ -0,0 +1,9 @@
1
+ import "@project-chip/matter-node.js";
2
+ import { OnOffLightDevice } from "@project-chip/matter.js/devices/OnOffLightDevice";
3
+ import { ServerNode } from "@project-chip/matter.js/node";
4
+
5
+ const node = await ServerNode.create();
6
+
7
+ await node.add(OnOffLightDevice);
8
+
9
+ await node.run();
@@ -0,0 +1,19 @@
1
+ import "@project-chip/matter-node.js";
2
+ import { OnOffLightDevice, OnOffLightRequirements } from "@project-chip/matter.js/devices/OnOffLightDevice";
3
+ import { ServerNode } from "@project-chip/matter.js/node";
4
+
5
+ class MyOnOffServer extends OnOffLightRequirements.OnOffServer {
6
+ override on() {
7
+ console.log("Turning on");
8
+ }
9
+
10
+ override off() {
11
+ console.log("Turning off");
12
+ }
13
+ }
14
+
15
+ const node = await ServerNode.create();
16
+
17
+ await node.add(OnOffLightDevice.with(MyOnOffServer));
18
+
19
+ await node.run();
@@ -0,0 +1,13 @@
1
+ import "@project-chip/matter-node.js";
2
+ import { OnOffLightDevice } from "@project-chip/matter.js/devices/OnOffLightDevice";
3
+ import { ServerNode } from "@project-chip/matter.js/node";
4
+
5
+ const node = await ServerNode.create();
6
+
7
+ const light = await node.add(OnOffLightDevice);
8
+
9
+ light.events.onOff.onOff$Change.on(newValue => {
10
+ console.log(`Light is ${newValue ? "on" : "off"}`);
11
+ });
12
+
13
+ await node.run();
@@ -0,0 +1,19 @@
1
+ import "@project-chip/matter-node.js";
2
+ import { OnOffLightDevice } from "@project-chip/matter.js/devices/OnOffLightDevice";
3
+ import { ServerNode } from "@project-chip/matter.js/node";
4
+
5
+ const node = await ServerNode.create();
6
+
7
+ const light = await node.add(OnOffLightDevice);
8
+
9
+ await node.bringOnline();
10
+
11
+ await light.act(async agent => {
12
+ await agent.onOff.toggle();
13
+ console.log("On/off state after first toggle", agent.onOff.state);
14
+
15
+ await agent.onOff.toggle();
16
+ console.log("On/off state after second toggle", agent.onOff.state);
17
+ });
18
+
19
+ await node.close();
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/examples/BridgedDevicesNode.ts"],
4
- "sourcesContent": ["#!/usr/bin/env node\n/**\n * @license\n * Copyright 2022 The node-matter Authors\n * SPDX-License-Identifier: Apache-2.0\n */\n\n/**\n * This example shows how to create a device bridge that exposed multiple devices.\n * It can be used as CLI script and starting point for your own device node implementation.\n */\n\n/**\n * Import needed modules from @project-chip/matter-node.js\n */\n// Include this first to auto-register Crypto, Network and Time Node.js implementations\nimport { CommissioningServer, MatterServer } from \"@project-chip/matter-node.js\";\n\nimport { VendorId } from \"@project-chip/matter-node.js/datatype\";\nimport { Aggregator, DeviceTypes, OnOffLightDevice, OnOffPluginUnitDevice } from \"@project-chip/matter-node.js/device\";\nimport { Format, Level, Logger } from \"@project-chip/matter-node.js/log\";\nimport { QrCode } from \"@project-chip/matter-node.js/schema\";\nimport { StorageBackendDisk, StorageManager } from \"@project-chip/matter-node.js/storage\";\nimport { Time } from \"@project-chip/matter-node.js/time\";\nimport {\n commandExecutor,\n getIntParameter,\n getParameter,\n hasParameter,\n requireMinNodeVersion,\n} from \"@project-chip/matter-node.js/util\";\n\nconst logger = Logger.get(\"Device\");\n\nrequireMinNodeVersion(16);\n\n/** Configure logging */\nswitch (getParameter(\"loglevel\")) {\n case \"fatal\":\n Logger.defaultLogLevel = Level.FATAL;\n break;\n case \"error\":\n Logger.defaultLogLevel = Level.ERROR;\n break;\n case \"warn\":\n Logger.defaultLogLevel = Level.WARN;\n break;\n case \"info\":\n Logger.defaultLogLevel = Level.INFO;\n break;\n}\n\nswitch (getParameter(\"logformat\")) {\n case \"plain\":\n Logger.format = Format.PLAIN;\n break;\n case \"html\":\n Logger.format = Format.HTML;\n break;\n default:\n if (process.stdin?.isTTY) Logger.format = Format.ANSI;\n}\n\nconst storageLocation = getParameter(\"store\") ?? \".device-node\";\nconst storage = new StorageBackendDisk(storageLocation, hasParameter(\"clearstorage\"));\nlogger.info(`Storage location: ${storageLocation} (Directory)`);\nlogger.info(\n 'Use the parameter \"-store NAME\" to specify a different storage location, use -clearstorage to start with an empty storage.',\n);\n\nclass BridgedDevice {\n private matterServer: MatterServer | undefined;\n\n async start() {\n logger.info(`node-matter`);\n\n /**\n * Initialize the storage system.\n *\n * The storage manager is then also used by the Matter server, so this code block in general is required,\n * but you can choose a different storage backend as long as it implements the required API.\n */\n\n const storageManager = new StorageManager(storage);\n await storageManager.initialize();\n\n /**\n * Collect all needed data\n *\n * This block makes sure to collect all needed data from cli or storage. Replace this with where ever your data\n * come from.\n *\n * Note: This example also uses the initialized storage system to store the device parameter data for convenience\n * and easy reuse. When you also do that be careful to not overlap with Matter-Server own contexts\n * (so maybe better not ;-)).\n */\n\n const deviceStorage = storageManager.createContext(\"Device\");\n\n const deviceName = \"Matter Bridge device\";\n const deviceType = DeviceTypes.AGGREGATOR.code;\n const vendorName = \"matter-node.js\";\n const passcode = getIntParameter(\"passcode\") ?? deviceStorage.get(\"passcode\", 20202021);\n const discriminator = getIntParameter(\"discriminator\") ?? deviceStorage.get(\"discriminator\", 3840);\n // product name / id and vendor id should match what is in the device certificate\n const vendorId = getIntParameter(\"vendorid\") ?? deviceStorage.get(\"vendorid\", 0xfff1);\n const productName = `node-matter OnOff-Bridge`;\n const productId = getIntParameter(\"productid\") ?? deviceStorage.get(\"productid\", 0x8000);\n\n const netInterface = getParameter(\"netinterface\");\n const port = getIntParameter(\"port\") ?? 5540;\n\n const uniqueId = getIntParameter(\"uniqueid\") ?? deviceStorage.get(\"uniqueid\", Time.nowMs());\n\n deviceStorage.set(\"passcode\", passcode);\n deviceStorage.set(\"discriminator\", discriminator);\n deviceStorage.set(\"vendorid\", vendorId);\n deviceStorage.set(\"productid\", productId);\n deviceStorage.set(\"uniqueid\", uniqueId);\n\n /**\n * Create Matter Server and CommissioningServer Node\n *\n * To allow the device to be announced, found, paired and operated we need a MatterServer instance and add a\n * commissioningServer to it and add the just created device instance to it.\n * The CommissioningServer node defines the port where the server listens for the UDP packages of the Matter protocol\n * and initializes deice specific certificates and such.\n *\n * The below logic also adds command handlers for commands of clusters that normally are handled internally\n * like testEventTrigger (General Diagnostic Cluster) that can be implemented with the logic when these commands\n * are called.\n */\n\n this.matterServer = new MatterServer(storageManager, { mdnsInterface: netInterface });\n\n const commissioningServer = new CommissioningServer({\n port,\n deviceName,\n deviceType,\n passcode,\n discriminator,\n basicInformation: {\n vendorName,\n vendorId: VendorId(vendorId),\n nodeLabel: productName,\n productName,\n productLabel: productName,\n productId,\n serialNumber: `node-matter-${uniqueId}`,\n },\n });\n\n /**\n * Create Device instance and add needed Listener\n *\n * Create an instance of the matter device class you want to use.\n * This example uses the OnOffLightDevice or OnOffPluginUnitDevice depending on the value of the type parameter.\n * To execute the on/off scripts defined as parameters a listener for the onOff attribute is registered via the\n * device specific API.\n *\n * The below logic also adds command handlers for commands of clusters that normally are handled device internally\n * like identify that can be implemented with the logic when these commands are called.\n */\n\n const aggregator = new Aggregator();\n\n const numDevices = getIntParameter(\"num\") || 2;\n for (let i = 1; i <= numDevices; i++) {\n const onOffDevice =\n getParameter(`type${i}`) === \"socket\" ? new OnOffPluginUnitDevice() : new OnOffLightDevice();\n\n onOffDevice.addOnOffListener(on => commandExecutor(on ? `on${i}` : `off${i}`)?.());\n onOffDevice.addCommandHandler(\"identify\", async ({ request: { identifyTime } }) =>\n console.log(\n `Identify called for OnOffDevice ${onOffDevice.name} with id: ${i} and identifyTime: ${identifyTime}`,\n ),\n );\n\n const name = `OnOff ${onOffDevice instanceof OnOffPluginUnitDevice ? \"Socket\" : \"Light\"} ${i}`;\n aggregator.addBridgedDevice(onOffDevice, {\n nodeLabel: name,\n productName: name,\n productLabel: name,\n serialNumber: `node-matter-${uniqueId}-${i}`,\n reachable: true,\n });\n }\n\n commissioningServer.addDevice(aggregator);\n\n await this.matterServer.addCommissioningServer(commissioningServer);\n\n /**\n * Start the Matter Server\n *\n * After everything was plugged together we can start the server. When not delayed announcement is set for the\n * CommissioningServer node then this command also starts the announcement of the device into the network.\n */\n\n await this.matterServer.start();\n\n /**\n * Print Pairing Information\n *\n * If the device is not already commissioned (this info is stored in the storage system) then get and print the\n * pairing details. This includes the QR code that can be scanned by the Matter app to pair the device.\n */\n\n logger.info(\"Listening\");\n if (!commissioningServer.isCommissioned()) {\n const pairingData = commissioningServer.getPairingCode();\n const { qrPairingCode, manualPairingCode } = pairingData;\n\n console.log(QrCode.get(qrPairingCode));\n console.log(\n `QR Code URL: https://project-chip.github.io/connectedhomeip/qrcode.html?data=${qrPairingCode}`,\n );\n console.log(`Manual pairing code: ${manualPairingCode}`);\n } else {\n console.log(\"Device is already commissioned. Waiting for controllers to connect ...\");\n }\n }\n\n async stop() {\n await this.matterServer?.close();\n }\n}\n\nconst device = new BridgedDevice();\ndevice\n .start()\n .then(() => {\n /* done */\n })\n .catch(err => console.error(err));\n\nprocess.on(\"SIGINT\", () => {\n // Clean up on CTRL-C\n device\n .stop()\n .then(() => {\n // Pragmatic way to make sure the storage is correctly closed before the process ends.\n storage\n .close()\n .then(() => process.exit(0))\n .catch(err => console.error(err));\n })\n .catch(err => console.error(err));\n});\n"],
5
- "mappings": ";AACA;AAAA;AAAA;AAAA;AAAA;AAeA,SAAS,qBAAqB,oBAAoB;AAElD,SAAS,gBAAgB;AACzB,SAAS,YAAY,aAAa,kBAAkB,6BAA6B;AACjF,SAAS,QAAQ,OAAO,cAAc;AACtC,SAAS,cAAc;AACvB,SAAS,oBAAoB,sBAAsB;AACnD,SAAS,YAAY;AACrB;AAAA,EACI;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACG;AAEP,MAAM,SAAS,OAAO,IAAI,QAAQ;AAElC,sBAAsB,EAAE;AAGxB,QAAQ,aAAa,UAAU,GAAG;AAAA,EAC9B,KAAK;AACD,WAAO,kBAAkB,MAAM;AAC/B;AAAA,EACJ,KAAK;AACD,WAAO,kBAAkB,MAAM;AAC/B;AAAA,EACJ,KAAK;AACD,WAAO,kBAAkB,MAAM;AAC/B;AAAA,EACJ,KAAK;AACD,WAAO,kBAAkB,MAAM;AAC/B;AACR;AAEA,QAAQ,aAAa,WAAW,GAAG;AAAA,EAC/B,KAAK;AACD,WAAO,SAAS,OAAO;AACvB;AAAA,EACJ,KAAK;AACD,WAAO,SAAS,OAAO;AACvB;AAAA,EACJ;AACI,QAAI,QAAQ,OAAO;AAAO,aAAO,SAAS,OAAO;AACzD;AAE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MAAM,OAAO;AACT,UAAM,KAAK,cAAc,MAAM;AAAA,EACnC;AACJ;AAEA,MAAM,SAAS,IAAI,cAAc;AACjC,OACK,MAAM,EACN,KAAK,MAAM;AAEZ,CAAC,EACA,MAAM,SAAO,QAAQ,MAAM,GAAG,CAAC;AAEpC,QAAQ,GAAG,UAAU,MAAM;AAEvB,SACK,KAAK,EACL,KAAK,MAAM;AAER,YACK,MAAM,EACN,KAAK,MAAM,QAAQ,KAAK,CAAC,CAAC,EAC1B,MAAM,SAAO,QAAQ,MAAM,GAAG,CAAC;AAAA,EACxC,CAAC,EACA,MAAM,SAAO,QAAQ,MAAM,GAAG,CAAC;AACxC,CAAC;",
6
- "names": []
7
- }
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../../src/examples/cluster/DummyWifiNetworkCommissioningClusterServer.ts"],
4
- "sourcesContent": ["/**\n * @license\n * Copyright 2022 The node-matter Authors\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport {\n ClusterServer,\n ClusterServerObjForCluster,\n GeneralCommissioningCluster,\n NetworkCommissioning,\n} from \"@project-chip/matter-node.js/cluster\";\nimport { ByteArray, getParameter } from \"@project-chip/matter-node.js/util\";\n\nconst firstNetworkId = new ByteArray(32);\n\nconst WifiNetworkCluster = NetworkCommissioning.Cluster.with(NetworkCommissioning.Feature.WiFiNetworkInterface);\n\n/**\n * This represents a Dummy version of a Wifi Network Commissioning Cluster Server without real Wifi related logic, beside\n * returning some values provided as CLI parameters. This dummy implementation is only there for tests/as showcase for BLE\n * commissioning of a device.\n */\nexport default ClusterServer(\n NetworkCommissioning.Cluster.with(NetworkCommissioning.Feature.WiFiNetworkInterface),\n {\n maxNetworks: 1,\n interfaceEnabled: true,\n lastConnectErrorValue: 0,\n lastNetworkId: null,\n lastNetworkingStatus: null,\n networks: [{ networkId: firstNetworkId, connected: false }],\n scanMaxTimeSeconds: 3,\n connectMaxTimeSeconds: 3,\n },\n {\n scanNetworks: async ({ request: { ssid, breadcrumb }, attributes: { lastNetworkingStatus }, endpoint }) => {\n console.log(`---> scanNetworks called on NetworkCommissioning cluster: ${ssid?.toHex()} ${breadcrumb}`);\n\n // Simulate successful scan\n if (breadcrumb !== undefined) {\n const generalCommissioningCluster = endpoint.getClusterServer(GeneralCommissioningCluster);\n generalCommissioningCluster?.setBreadcrumbAttribute(breadcrumb);\n }\n\n const networkingStatus = NetworkCommissioning.NetworkCommissioningStatus.Success;\n lastNetworkingStatus?.setLocal(networkingStatus);\n\n return {\n networkingStatus,\n wiFiScanResults: [\n {\n security: {\n unencrypted: false,\n wep: false,\n wpaPersonal: false,\n wpa2Personal: true,\n wpa3Personal: true,\n },\n ssid: ssid || ByteArray.fromString(getParameter(\"ble-wifi-scan-ssid\") ?? \"TestSSID\"), // Set a valid existing local Wi-Fi SSID here\n bssid: ByteArray.fromString(getParameter(\"ble-wifi-scan-bssid\") ?? \"00:00:00:00:00:00\"),\n channel: 1,\n },\n ],\n };\n },\n addOrUpdateWiFiNetwork: async ({\n request: { ssid, credentials, breadcrumb },\n attributes: { lastNetworkingStatus, lastNetworkId },\n endpoint,\n session,\n }) => {\n console.log(\n `---> addOrUpdateWiFiNetwork called on NetworkCommissioning cluster: ${ssid.toHex()} ${credentials.toHex()} ${breadcrumb}`,\n );\n\n session.getContext().assertFailSafeArmed(\"Failsafe timer needs to be armed to add or update networks.\");\n\n // Simulate successful add or update\n if (breadcrumb !== undefined) {\n const generalCommissioningCluster = endpoint.getClusterServer(GeneralCommissioningCluster);\n generalCommissioningCluster?.setBreadcrumbAttribute(breadcrumb);\n }\n\n const networkingStatus = NetworkCommissioning.NetworkCommissioningStatus.Success;\n lastNetworkingStatus?.setLocal(networkingStatus);\n lastNetworkId?.setLocal(firstNetworkId);\n\n return {\n networkingStatus: NetworkCommissioning.NetworkCommissioningStatus.Success,\n networkIndex: 0,\n };\n },\n removeNetwork: async ({\n request: { networkId, breadcrumb },\n attributes: { lastNetworkingStatus, lastNetworkId },\n endpoint,\n session,\n }) => {\n console.log(\n `---> removeNetwork called on NetworkCommissioning cluster: ${networkId.toHex()} ${breadcrumb}`,\n );\n\n session.getContext().assertFailSafeArmed(\"Failsafe timer needs to be armed to add or update networks.\");\n\n // Simulate successful add or update\n if (breadcrumb !== undefined) {\n const generalCommissioningCluster = endpoint.getClusterServer(GeneralCommissioningCluster);\n generalCommissioningCluster?.setBreadcrumbAttribute(breadcrumb);\n }\n\n const networkingStatus = NetworkCommissioning.NetworkCommissioningStatus.Success;\n lastNetworkingStatus?.setLocal(networkingStatus);\n lastNetworkId?.setLocal(firstNetworkId);\n\n return {\n networkingStatus: NetworkCommissioning.NetworkCommissioningStatus.Success,\n networkIndex: 0,\n };\n },\n connectNetwork: async ({\n request: { networkId, breadcrumb },\n attributes: { lastNetworkingStatus, lastNetworkId, lastConnectErrorValue, networks },\n endpoint,\n session,\n }) => {\n console.log(\n `---> connectNetwork called on NetworkCommissioning cluster: ${networkId.toHex()} ${breadcrumb}`,\n );\n\n session.getContext().assertFailSafeArmed(\"Failsafe timer needs to be armed to add or update networks.\");\n\n // Simulate successful connection\n if (breadcrumb !== undefined) {\n const generalCommissioningCluster = endpoint.getClusterServer(GeneralCommissioningCluster);\n generalCommissioningCluster?.setBreadcrumbAttribute(breadcrumb);\n }\n\n const networkList = networks.getLocal();\n networkList[0].connected = true;\n networks.setLocal(networkList);\n\n const networkingStatus = NetworkCommissioning.NetworkCommissioningStatus.Success;\n lastNetworkingStatus?.setLocal(networkingStatus);\n lastNetworkId?.setLocal(firstNetworkId);\n lastConnectErrorValue?.setLocal(null);\n\n // Announce operational in IP network\n const device = session.getContext();\n await device.startAnnouncement();\n\n return {\n networkingStatus: NetworkCommissioning.NetworkCommissioningStatus.Success,\n errorValue: null,\n };\n },\n reorderNetwork: async ({\n request: { networkId, networkIndex, breadcrumb },\n attributes: { lastNetworkingStatus },\n endpoint,\n }) => {\n console.log(\n `---> reorderNetwork called on NetworkCommissioning cluster: ${networkId.toHex()} ${networkIndex} ${breadcrumb}`,\n );\n\n // Simulate successful connection\n if (breadcrumb !== undefined) {\n const generalCommissioningCluster = endpoint.getClusterServer(GeneralCommissioningCluster);\n generalCommissioningCluster?.setBreadcrumbAttribute(breadcrumb);\n }\n\n const networkingStatus = NetworkCommissioning.NetworkCommissioningStatus.Success;\n lastNetworkingStatus?.setLocal(networkingStatus);\n\n return {\n networkingStatus: NetworkCommissioning.NetworkCommissioningStatus.Success,\n networkIndex: 0,\n };\n },\n },\n) as ClusterServerObjForCluster<typeof WifiNetworkCluster>;\n"],
5
- "mappings": "AAAA;AAAA;AAAA;AAAA;AAAA;AAMA;AAAA,EACI;AAAA,EAEA;AAAA,EACA;AAAA,OACG;AACP,SAAS,WAAW,oBAAoB;AAExC,MAAM,iBAAiB,IAAI,UAAU,EAAE;AAEvC,MAAM,qBAAqB,qBAAqB,QAAQ,KAAK,qBAAqB,QAAQ,oBAAoB;AAO9G,IAAO,qDAAQ;AAAA,EACX,qBAAqB,QAAQ,KAAK,qBAAqB,QAAQ,oBAAoB;AAAA,EACnF;AAAA,IACI,aAAa;AAAA,IACb,kBAAkB;AAAA,IAClB,uBAAuB;AAAA,IACvB,eAAe;AAAA,IACf,sBAAsB;AAAA,IACtB,UAAU,CAAC,EAAE,WAAW,gBAAgB,WAAW,MAAM,CAAC;AAAA,IAC1D,oBAAoB;AAAA,IACpB,uBAAuB;AAAA,EAC3B;AAAA,EACA;AAAA,IACI,cAAc,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,GAAG,YAAY,EAAE,qBAAqB,GAAG,SAAS,MAAM;AACvG,cAAQ,IAAI,6DAA6D,MAAM,MAAM,CAAC,IAAI,UAAU,EAAE;AAGtG,UAAI,eAAe,QAAW;AAC1B,cAAM,8BAA8B,SAAS,iBAAiB,2BAA2B;AACzF,qCAA6B,uBAAuB,UAAU;AAAA,MAClE;AAEA,YAAM,mBAAmB,qBAAqB,2BAA2B;AACzE,4BAAsB,SAAS,gBAAgB;AAE/C,aAAO;AAAA,QACH;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