@enyo-energy/energy-app-sdk 0.0.158 → 0.0.159
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/dist/cjs/packages/energy-app-udp.cjs +25 -0
- package/dist/cjs/packages/energy-app-udp.d.cts +91 -1
- package/dist/cjs/version.cjs +1 -1
- package/dist/cjs/version.d.cts +1 -1
- package/dist/packages/energy-app-udp.d.ts +91 -1
- package/dist/packages/energy-app-udp.js +23 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
|
@@ -1,2 +1,27 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.EnergyAppUdpBindError = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Thrown by {@link EnergyAppUdp.bind} when the underlying socket cannot be
|
|
6
|
+
* bound — for example `EADDRINUSE`, an invalid multicast group address
|
|
7
|
+
* supplied via {@link UdpBindOptions.multicastGroups}, or a failure to join
|
|
8
|
+
* one of the requested groups after the socket starts listening.
|
|
9
|
+
*
|
|
10
|
+
* Implementations should wrap the originating `Error` and preserve its
|
|
11
|
+
* `message` so callers can `instanceof`-check this class while still
|
|
12
|
+
* surfacing the root cause in logs.
|
|
13
|
+
*/
|
|
14
|
+
class EnergyAppUdpBindError extends Error {
|
|
15
|
+
/**
|
|
16
|
+
* Create a new `EnergyAppUdpBindError`.
|
|
17
|
+
*
|
|
18
|
+
* @param message - Human-readable description of the bind failure. Should
|
|
19
|
+
* include the root cause (e.g. the originating `Error`'s
|
|
20
|
+
* `message`) so it is preserved for logging.
|
|
21
|
+
*/
|
|
22
|
+
constructor(message) {
|
|
23
|
+
super(message);
|
|
24
|
+
this.name = 'EnergyAppUdpBindError';
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
exports.EnergyAppUdpBindError = EnergyAppUdpBindError;
|
|
@@ -9,9 +9,37 @@ export interface UdpBindOptions {
|
|
|
9
9
|
* sockets may bind to the same address/port. Maps to the `reuseAddr`
|
|
10
10
|
* option of `node:dgram`'s `createSocket`.
|
|
11
11
|
*
|
|
12
|
+
* Particularly useful in combination with {@link multicastGroups} so
|
|
13
|
+
* that multiple processes on the same host can receive the same
|
|
14
|
+
* multicast stream.
|
|
15
|
+
*
|
|
12
16
|
* Defaults to `false`.
|
|
13
17
|
*/
|
|
14
18
|
reuseAddr?: boolean;
|
|
19
|
+
/**
|
|
20
|
+
* IPv4 multicast group addresses to join after the socket is bound.
|
|
21
|
+
*
|
|
22
|
+
* Each entry must be a dotted-quad IPv4 address in the multicast range
|
|
23
|
+
* `224.0.0.0/4` (i.e. first octet 224–239). The runtime joins every
|
|
24
|
+
* listed group on the socket once the `listening` event fires; if any
|
|
25
|
+
* join fails or any entry is not a valid multicast address, the socket
|
|
26
|
+
* is closed and {@link EnergyAppUdp.bind} rejects with
|
|
27
|
+
* {@link EnergyAppUdpBindError}.
|
|
28
|
+
*
|
|
29
|
+
* Typical use: SMA Speedwire receivers join `239.12.255.254`.
|
|
30
|
+
*
|
|
31
|
+
* Defaults to `undefined` (no multicast membership — unicast bind only).
|
|
32
|
+
*/
|
|
33
|
+
multicastGroups?: string[];
|
|
34
|
+
/**
|
|
35
|
+
* Optional local interface address (IPv4 dotted-quad) to bind the
|
|
36
|
+
* multicast membership(s) to. When omitted, the operating system
|
|
37
|
+
* selects an interface — usually the one carrying the default route.
|
|
38
|
+
*
|
|
39
|
+
* Only meaningful in combination with {@link multicastGroups}. Most
|
|
40
|
+
* callers should leave this `undefined`.
|
|
41
|
+
*/
|
|
42
|
+
multicastInterface?: string;
|
|
15
43
|
}
|
|
16
44
|
/**
|
|
17
45
|
* A single inbound datagram delivered to a handler registered with
|
|
@@ -84,6 +112,31 @@ export interface EnergyAppUdpSocket {
|
|
|
84
112
|
* its `close` event.
|
|
85
113
|
*/
|
|
86
114
|
close(): Promise<void>;
|
|
115
|
+
/**
|
|
116
|
+
* Join an additional IPv4 multicast group on this already-bound socket.
|
|
117
|
+
*
|
|
118
|
+
* The address must be a dotted-quad in the multicast range
|
|
119
|
+
* `224.0.0.0/4`. Implementations forward to the underlying
|
|
120
|
+
* `dgram.Socket.addMembership` call.
|
|
121
|
+
*
|
|
122
|
+
* @param group - IPv4 multicast group address to join.
|
|
123
|
+
* @param interfaceAddress - Optional local interface (IPv4 dotted-quad)
|
|
124
|
+
* to bind the membership to. When omitted,
|
|
125
|
+
* the operating system selects an interface.
|
|
126
|
+
* @throws If the address is not a valid multicast address, the socket
|
|
127
|
+
* has been closed, or the underlying join fails.
|
|
128
|
+
*/
|
|
129
|
+
addMembership(group: string, interfaceAddress?: string): void;
|
|
130
|
+
/**
|
|
131
|
+
* Leave a previously joined IPv4 multicast group.
|
|
132
|
+
*
|
|
133
|
+
* @param group - IPv4 multicast group address to leave.
|
|
134
|
+
* @param interfaceAddress - Optional local interface (IPv4 dotted-quad)
|
|
135
|
+
* the membership was originally bound to.
|
|
136
|
+
* @throws If the address is not a valid multicast address, the socket
|
|
137
|
+
* has been closed, or no matching membership exists.
|
|
138
|
+
*/
|
|
139
|
+
dropMembership(group: string, interfaceAddress?: string): void;
|
|
87
140
|
}
|
|
88
141
|
/**
|
|
89
142
|
* Interface for raw UDP communication in enyo packages.
|
|
@@ -102,17 +155,54 @@ export interface EnergyAppUdpSocket {
|
|
|
102
155
|
* socket.off(handlerId);
|
|
103
156
|
* await socket.close();
|
|
104
157
|
* ```
|
|
158
|
+
*
|
|
159
|
+
* @example Multicast receiver (SMA Speedwire)
|
|
160
|
+
* ```typescript
|
|
161
|
+
* const udp = energyApp.useUdp();
|
|
162
|
+
* const socket = await udp.bind({
|
|
163
|
+
* port: 9522,
|
|
164
|
+
* reuseAddr: true,
|
|
165
|
+
* multicastGroups: ['239.12.255.254'],
|
|
166
|
+
* });
|
|
167
|
+
* socket.onMessage((msg) => {
|
|
168
|
+
* // Inbound SMA Speedwire datagram on 239.12.255.254:9522
|
|
169
|
+
* });
|
|
170
|
+
* ```
|
|
105
171
|
*/
|
|
106
172
|
export interface EnergyAppUdp {
|
|
107
173
|
/**
|
|
108
174
|
* Bind a UDP socket on the requested host/port.
|
|
109
175
|
*
|
|
110
176
|
* Resolves once the underlying socket has emitted its `listening` event.
|
|
177
|
+
* When {@link UdpBindOptions.multicastGroups} is provided, the runtime
|
|
178
|
+
* also joins each listed group before the returned promise resolves.
|
|
111
179
|
*
|
|
112
180
|
* @param options - Bind configuration (see {@link UdpBindOptions}).
|
|
113
181
|
* @returns A bound socket ready to send and receive datagrams.
|
|
114
182
|
* @throws {EnergyAppUdpBindError} If the requested port is already in use
|
|
115
|
-
* (EADDRINUSE)
|
|
183
|
+
* (EADDRINUSE), any entry in {@link UdpBindOptions.multicastGroups}
|
|
184
|
+
* is not a valid IPv4 multicast address, or joining a requested
|
|
185
|
+
* group fails. Other errors propagate as their original Error.
|
|
116
186
|
*/
|
|
117
187
|
bind(options: UdpBindOptions): Promise<EnergyAppUdpSocket>;
|
|
118
188
|
}
|
|
189
|
+
/**
|
|
190
|
+
* Thrown by {@link EnergyAppUdp.bind} when the underlying socket cannot be
|
|
191
|
+
* bound — for example `EADDRINUSE`, an invalid multicast group address
|
|
192
|
+
* supplied via {@link UdpBindOptions.multicastGroups}, or a failure to join
|
|
193
|
+
* one of the requested groups after the socket starts listening.
|
|
194
|
+
*
|
|
195
|
+
* Implementations should wrap the originating `Error` and preserve its
|
|
196
|
+
* `message` so callers can `instanceof`-check this class while still
|
|
197
|
+
* surfacing the root cause in logs.
|
|
198
|
+
*/
|
|
199
|
+
export declare class EnergyAppUdpBindError extends Error {
|
|
200
|
+
/**
|
|
201
|
+
* Create a new `EnergyAppUdpBindError`.
|
|
202
|
+
*
|
|
203
|
+
* @param message - Human-readable description of the bind failure. Should
|
|
204
|
+
* include the root cause (e.g. the originating `Error`'s
|
|
205
|
+
* `message`) so it is preserved for logging.
|
|
206
|
+
*/
|
|
207
|
+
constructor(message: string);
|
|
208
|
+
}
|
package/dist/cjs/version.cjs
CHANGED
|
@@ -9,7 +9,7 @@ exports.getSdkVersion = getSdkVersion;
|
|
|
9
9
|
/**
|
|
10
10
|
* Current version of the enyo Energy App SDK.
|
|
11
11
|
*/
|
|
12
|
-
exports.SDK_VERSION = '0.0.
|
|
12
|
+
exports.SDK_VERSION = '0.0.159';
|
|
13
13
|
/**
|
|
14
14
|
* Gets the current SDK version.
|
|
15
15
|
* @returns The semantic version string of the SDK
|
package/dist/cjs/version.d.cts
CHANGED
|
@@ -9,9 +9,37 @@ export interface UdpBindOptions {
|
|
|
9
9
|
* sockets may bind to the same address/port. Maps to the `reuseAddr`
|
|
10
10
|
* option of `node:dgram`'s `createSocket`.
|
|
11
11
|
*
|
|
12
|
+
* Particularly useful in combination with {@link multicastGroups} so
|
|
13
|
+
* that multiple processes on the same host can receive the same
|
|
14
|
+
* multicast stream.
|
|
15
|
+
*
|
|
12
16
|
* Defaults to `false`.
|
|
13
17
|
*/
|
|
14
18
|
reuseAddr?: boolean;
|
|
19
|
+
/**
|
|
20
|
+
* IPv4 multicast group addresses to join after the socket is bound.
|
|
21
|
+
*
|
|
22
|
+
* Each entry must be a dotted-quad IPv4 address in the multicast range
|
|
23
|
+
* `224.0.0.0/4` (i.e. first octet 224–239). The runtime joins every
|
|
24
|
+
* listed group on the socket once the `listening` event fires; if any
|
|
25
|
+
* join fails or any entry is not a valid multicast address, the socket
|
|
26
|
+
* is closed and {@link EnergyAppUdp.bind} rejects with
|
|
27
|
+
* {@link EnergyAppUdpBindError}.
|
|
28
|
+
*
|
|
29
|
+
* Typical use: SMA Speedwire receivers join `239.12.255.254`.
|
|
30
|
+
*
|
|
31
|
+
* Defaults to `undefined` (no multicast membership — unicast bind only).
|
|
32
|
+
*/
|
|
33
|
+
multicastGroups?: string[];
|
|
34
|
+
/**
|
|
35
|
+
* Optional local interface address (IPv4 dotted-quad) to bind the
|
|
36
|
+
* multicast membership(s) to. When omitted, the operating system
|
|
37
|
+
* selects an interface — usually the one carrying the default route.
|
|
38
|
+
*
|
|
39
|
+
* Only meaningful in combination with {@link multicastGroups}. Most
|
|
40
|
+
* callers should leave this `undefined`.
|
|
41
|
+
*/
|
|
42
|
+
multicastInterface?: string;
|
|
15
43
|
}
|
|
16
44
|
/**
|
|
17
45
|
* A single inbound datagram delivered to a handler registered with
|
|
@@ -84,6 +112,31 @@ export interface EnergyAppUdpSocket {
|
|
|
84
112
|
* its `close` event.
|
|
85
113
|
*/
|
|
86
114
|
close(): Promise<void>;
|
|
115
|
+
/**
|
|
116
|
+
* Join an additional IPv4 multicast group on this already-bound socket.
|
|
117
|
+
*
|
|
118
|
+
* The address must be a dotted-quad in the multicast range
|
|
119
|
+
* `224.0.0.0/4`. Implementations forward to the underlying
|
|
120
|
+
* `dgram.Socket.addMembership` call.
|
|
121
|
+
*
|
|
122
|
+
* @param group - IPv4 multicast group address to join.
|
|
123
|
+
* @param interfaceAddress - Optional local interface (IPv4 dotted-quad)
|
|
124
|
+
* to bind the membership to. When omitted,
|
|
125
|
+
* the operating system selects an interface.
|
|
126
|
+
* @throws If the address is not a valid multicast address, the socket
|
|
127
|
+
* has been closed, or the underlying join fails.
|
|
128
|
+
*/
|
|
129
|
+
addMembership(group: string, interfaceAddress?: string): void;
|
|
130
|
+
/**
|
|
131
|
+
* Leave a previously joined IPv4 multicast group.
|
|
132
|
+
*
|
|
133
|
+
* @param group - IPv4 multicast group address to leave.
|
|
134
|
+
* @param interfaceAddress - Optional local interface (IPv4 dotted-quad)
|
|
135
|
+
* the membership was originally bound to.
|
|
136
|
+
* @throws If the address is not a valid multicast address, the socket
|
|
137
|
+
* has been closed, or no matching membership exists.
|
|
138
|
+
*/
|
|
139
|
+
dropMembership(group: string, interfaceAddress?: string): void;
|
|
87
140
|
}
|
|
88
141
|
/**
|
|
89
142
|
* Interface for raw UDP communication in enyo packages.
|
|
@@ -102,17 +155,54 @@ export interface EnergyAppUdpSocket {
|
|
|
102
155
|
* socket.off(handlerId);
|
|
103
156
|
* await socket.close();
|
|
104
157
|
* ```
|
|
158
|
+
*
|
|
159
|
+
* @example Multicast receiver (SMA Speedwire)
|
|
160
|
+
* ```typescript
|
|
161
|
+
* const udp = energyApp.useUdp();
|
|
162
|
+
* const socket = await udp.bind({
|
|
163
|
+
* port: 9522,
|
|
164
|
+
* reuseAddr: true,
|
|
165
|
+
* multicastGroups: ['239.12.255.254'],
|
|
166
|
+
* });
|
|
167
|
+
* socket.onMessage((msg) => {
|
|
168
|
+
* // Inbound SMA Speedwire datagram on 239.12.255.254:9522
|
|
169
|
+
* });
|
|
170
|
+
* ```
|
|
105
171
|
*/
|
|
106
172
|
export interface EnergyAppUdp {
|
|
107
173
|
/**
|
|
108
174
|
* Bind a UDP socket on the requested host/port.
|
|
109
175
|
*
|
|
110
176
|
* Resolves once the underlying socket has emitted its `listening` event.
|
|
177
|
+
* When {@link UdpBindOptions.multicastGroups} is provided, the runtime
|
|
178
|
+
* also joins each listed group before the returned promise resolves.
|
|
111
179
|
*
|
|
112
180
|
* @param options - Bind configuration (see {@link UdpBindOptions}).
|
|
113
181
|
* @returns A bound socket ready to send and receive datagrams.
|
|
114
182
|
* @throws {EnergyAppUdpBindError} If the requested port is already in use
|
|
115
|
-
* (EADDRINUSE)
|
|
183
|
+
* (EADDRINUSE), any entry in {@link UdpBindOptions.multicastGroups}
|
|
184
|
+
* is not a valid IPv4 multicast address, or joining a requested
|
|
185
|
+
* group fails. Other errors propagate as their original Error.
|
|
116
186
|
*/
|
|
117
187
|
bind(options: UdpBindOptions): Promise<EnergyAppUdpSocket>;
|
|
118
188
|
}
|
|
189
|
+
/**
|
|
190
|
+
* Thrown by {@link EnergyAppUdp.bind} when the underlying socket cannot be
|
|
191
|
+
* bound — for example `EADDRINUSE`, an invalid multicast group address
|
|
192
|
+
* supplied via {@link UdpBindOptions.multicastGroups}, or a failure to join
|
|
193
|
+
* one of the requested groups after the socket starts listening.
|
|
194
|
+
*
|
|
195
|
+
* Implementations should wrap the originating `Error` and preserve its
|
|
196
|
+
* `message` so callers can `instanceof`-check this class while still
|
|
197
|
+
* surfacing the root cause in logs.
|
|
198
|
+
*/
|
|
199
|
+
export declare class EnergyAppUdpBindError extends Error {
|
|
200
|
+
/**
|
|
201
|
+
* Create a new `EnergyAppUdpBindError`.
|
|
202
|
+
*
|
|
203
|
+
* @param message - Human-readable description of the bind failure. Should
|
|
204
|
+
* include the root cause (e.g. the originating `Error`'s
|
|
205
|
+
* `message`) so it is preserved for logging.
|
|
206
|
+
*/
|
|
207
|
+
constructor(message: string);
|
|
208
|
+
}
|
|
@@ -1 +1,23 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Thrown by {@link EnergyAppUdp.bind} when the underlying socket cannot be
|
|
3
|
+
* bound — for example `EADDRINUSE`, an invalid multicast group address
|
|
4
|
+
* supplied via {@link UdpBindOptions.multicastGroups}, or a failure to join
|
|
5
|
+
* one of the requested groups after the socket starts listening.
|
|
6
|
+
*
|
|
7
|
+
* Implementations should wrap the originating `Error` and preserve its
|
|
8
|
+
* `message` so callers can `instanceof`-check this class while still
|
|
9
|
+
* surfacing the root cause in logs.
|
|
10
|
+
*/
|
|
11
|
+
export class EnergyAppUdpBindError extends Error {
|
|
12
|
+
/**
|
|
13
|
+
* Create a new `EnergyAppUdpBindError`.
|
|
14
|
+
*
|
|
15
|
+
* @param message - Human-readable description of the bind failure. Should
|
|
16
|
+
* include the root cause (e.g. the originating `Error`'s
|
|
17
|
+
* `message`) so it is preserved for logging.
|
|
18
|
+
*/
|
|
19
|
+
constructor(message) {
|
|
20
|
+
super(message);
|
|
21
|
+
this.name = 'EnergyAppUdpBindError';
|
|
22
|
+
}
|
|
23
|
+
}
|
package/dist/version.d.ts
CHANGED
package/dist/version.js
CHANGED