matterbridge 3.4.3-dev-20251209-e6cb85f → 3.4.3
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 +2 -3
- package/dist/broadcastServer.d.ts +144 -0
- package/dist/broadcastServer.d.ts.map +1 -0
- package/dist/broadcastServer.js +119 -0
- package/dist/broadcastServer.js.map +1 -0
- package/dist/broadcastServerTypes.d.ts +841 -0
- package/dist/broadcastServerTypes.d.ts.map +1 -0
- package/dist/broadcastServerTypes.js +24 -0
- package/dist/broadcastServerTypes.js.map +1 -0
- package/dist/cli.d.ts +30 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +97 -1
- package/dist/cli.js.map +1 -0
- package/dist/cliEmitter.d.ts +50 -0
- package/dist/cliEmitter.d.ts.map +1 -0
- package/dist/cliEmitter.js +37 -0
- package/dist/cliEmitter.js.map +1 -0
- package/dist/cliHistory.d.ts +48 -0
- package/dist/cliHistory.d.ts.map +1 -0
- package/dist/cliHistory.js +38 -0
- package/dist/cliHistory.js.map +1 -0
- package/dist/clusters/export.d.ts +2 -0
- package/dist/clusters/export.d.ts.map +1 -0
- package/dist/clusters/export.js +2 -0
- package/dist/clusters/export.js.map +1 -0
- package/dist/deviceManager.d.ts +135 -0
- package/dist/deviceManager.d.ts.map +1 -0
- package/dist/deviceManager.js +113 -1
- package/dist/deviceManager.js.map +1 -0
- package/dist/devices/airConditioner.d.ts +98 -0
- package/dist/devices/airConditioner.d.ts.map +1 -0
- package/dist/devices/airConditioner.js +57 -0
- package/dist/devices/airConditioner.js.map +1 -0
- package/dist/devices/batteryStorage.d.ts +48 -0
- package/dist/devices/batteryStorage.d.ts.map +1 -0
- package/dist/devices/batteryStorage.js +48 -1
- package/dist/devices/batteryStorage.js.map +1 -0
- package/dist/devices/cooktop.d.ts +61 -0
- package/dist/devices/cooktop.d.ts.map +1 -0
- package/dist/devices/cooktop.js +56 -0
- package/dist/devices/cooktop.js.map +1 -0
- package/dist/devices/dishwasher.d.ts +71 -0
- package/dist/devices/dishwasher.d.ts.map +1 -0
- package/dist/devices/dishwasher.js +57 -0
- package/dist/devices/dishwasher.js.map +1 -0
- package/dist/devices/evse.d.ts +76 -0
- package/dist/devices/evse.d.ts.map +1 -0
- package/dist/devices/evse.js +74 -10
- package/dist/devices/evse.js.map +1 -0
- package/dist/devices/export.d.ts +17 -0
- package/dist/devices/export.d.ts.map +1 -0
- package/dist/devices/export.js +5 -0
- package/dist/devices/export.js.map +1 -0
- package/dist/devices/extractorHood.d.ts +46 -0
- package/dist/devices/extractorHood.d.ts.map +1 -0
- package/dist/devices/extractorHood.js +43 -0
- package/dist/devices/extractorHood.js.map +1 -0
- package/dist/devices/heatPump.d.ts +47 -0
- package/dist/devices/heatPump.d.ts.map +1 -0
- package/dist/devices/heatPump.js +50 -2
- package/dist/devices/heatPump.js.map +1 -0
- package/dist/devices/laundryDryer.d.ts +67 -0
- package/dist/devices/laundryDryer.d.ts.map +1 -0
- package/dist/devices/laundryDryer.js +62 -3
- package/dist/devices/laundryDryer.js.map +1 -0
- package/dist/devices/laundryWasher.d.ts +81 -0
- package/dist/devices/laundryWasher.d.ts.map +1 -0
- package/dist/devices/laundryWasher.js +70 -4
- package/dist/devices/laundryWasher.js.map +1 -0
- package/dist/devices/microwaveOven.d.ts +168 -0
- package/dist/devices/microwaveOven.d.ts.map +1 -0
- package/dist/devices/microwaveOven.js +88 -5
- package/dist/devices/microwaveOven.js.map +1 -0
- package/dist/devices/oven.d.ts +105 -0
- package/dist/devices/oven.d.ts.map +1 -0
- package/dist/devices/oven.js +85 -0
- package/dist/devices/oven.js.map +1 -0
- package/dist/devices/refrigerator.d.ts +118 -0
- package/dist/devices/refrigerator.d.ts.map +1 -0
- package/dist/devices/refrigerator.js +102 -0
- package/dist/devices/refrigerator.js.map +1 -0
- package/dist/devices/roboticVacuumCleaner.d.ts +112 -0
- package/dist/devices/roboticVacuumCleaner.d.ts.map +1 -0
- package/dist/devices/roboticVacuumCleaner.js +100 -9
- package/dist/devices/roboticVacuumCleaner.js.map +1 -0
- package/dist/devices/solarPower.d.ts +40 -0
- package/dist/devices/solarPower.d.ts.map +1 -0
- package/dist/devices/solarPower.js +38 -0
- package/dist/devices/solarPower.js.map +1 -0
- package/dist/devices/speaker.d.ts +87 -0
- package/dist/devices/speaker.d.ts.map +1 -0
- package/dist/devices/speaker.js +84 -0
- package/dist/devices/speaker.js.map +1 -0
- package/dist/devices/temperatureControl.d.ts +166 -0
- package/dist/devices/temperatureControl.d.ts.map +1 -0
- package/dist/devices/temperatureControl.js +24 -3
- package/dist/devices/temperatureControl.js.map +1 -0
- package/dist/devices/waterHeater.d.ts +111 -0
- package/dist/devices/waterHeater.d.ts.map +1 -0
- package/dist/devices/waterHeater.js +82 -2
- package/dist/devices/waterHeater.js.map +1 -0
- package/dist/dgram/coap.d.ts +205 -0
- package/dist/dgram/coap.d.ts.map +1 -0
- package/dist/dgram/coap.js +126 -13
- package/dist/dgram/coap.js.map +1 -0
- package/dist/dgram/dgram.d.ts +141 -0
- package/dist/dgram/dgram.d.ts.map +1 -0
- package/dist/dgram/dgram.js +114 -2
- package/dist/dgram/dgram.js.map +1 -0
- package/dist/dgram/mb_coap.d.ts +24 -0
- package/dist/dgram/mb_coap.d.ts.map +1 -0
- package/dist/dgram/mb_coap.js +41 -3
- package/dist/dgram/mb_coap.js.map +1 -0
- package/dist/dgram/mb_mdns.d.ts +24 -0
- package/dist/dgram/mb_mdns.d.ts.map +1 -0
- package/dist/dgram/mb_mdns.js +80 -15
- package/dist/dgram/mb_mdns.js.map +1 -0
- package/dist/dgram/mdns.d.ts +290 -0
- package/dist/dgram/mdns.d.ts.map +1 -0
- package/dist/dgram/mdns.js +299 -137
- package/dist/dgram/mdns.js.map +1 -0
- package/dist/dgram/multicast.d.ts +67 -0
- package/dist/dgram/multicast.d.ts.map +1 -0
- package/dist/dgram/multicast.js +62 -1
- package/dist/dgram/multicast.js.map +1 -0
- package/dist/dgram/unicast.d.ts +56 -0
- package/dist/dgram/unicast.d.ts.map +1 -0
- package/dist/dgram/unicast.js +54 -0
- package/dist/dgram/unicast.js.map +1 -0
- package/dist/frontend.d.ts +238 -0
- package/dist/frontend.d.ts.map +1 -0
- package/dist/frontend.js +455 -35
- package/dist/frontend.js.map +1 -0
- package/dist/frontendTypes.d.ts +529 -0
- package/dist/frontendTypes.d.ts.map +1 -0
- package/dist/frontendTypes.js +45 -0
- package/dist/frontendTypes.js.map +1 -0
- package/dist/helpers.d.ts +48 -0
- package/dist/helpers.d.ts.map +1 -0
- package/dist/helpers.js +53 -0
- package/dist/helpers.js.map +1 -0
- package/dist/index.d.ts +34 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +25 -0
- package/dist/index.js.map +1 -0
- package/dist/jestutils/export.d.ts +2 -0
- package/dist/jestutils/export.d.ts.map +1 -0
- package/dist/jestutils/export.js +1 -0
- package/dist/jestutils/export.js.map +1 -0
- package/dist/jestutils/jestHelpers.d.ts +345 -0
- package/dist/jestutils/jestHelpers.d.ts.map +1 -0
- package/dist/jestutils/jestHelpers.js +371 -14
- package/dist/jestutils/jestHelpers.js.map +1 -0
- package/dist/logger/export.d.ts +2 -0
- package/dist/logger/export.d.ts.map +1 -0
- package/dist/logger/export.js +1 -0
- package/dist/logger/export.js.map +1 -0
- package/dist/matter/behaviors.d.ts +2 -0
- package/dist/matter/behaviors.d.ts.map +1 -0
- package/dist/matter/behaviors.js +2 -0
- package/dist/matter/behaviors.js.map +1 -0
- package/dist/matter/clusters.d.ts +2 -0
- package/dist/matter/clusters.d.ts.map +1 -0
- package/dist/matter/clusters.js +2 -0
- package/dist/matter/clusters.js.map +1 -0
- package/dist/matter/devices.d.ts +2 -0
- package/dist/matter/devices.d.ts.map +1 -0
- package/dist/matter/devices.js +2 -0
- package/dist/matter/devices.js.map +1 -0
- package/dist/matter/endpoints.d.ts +2 -0
- package/dist/matter/endpoints.d.ts.map +1 -0
- package/dist/matter/endpoints.js +2 -0
- package/dist/matter/endpoints.js.map +1 -0
- package/dist/matter/export.d.ts +5 -0
- package/dist/matter/export.d.ts.map +1 -0
- package/dist/matter/export.js +3 -0
- package/dist/matter/export.js.map +1 -0
- package/dist/matter/types.d.ts +3 -0
- package/dist/matter/types.d.ts.map +1 -0
- package/dist/matter/types.js +3 -0
- package/dist/matter/types.js.map +1 -0
- package/dist/matterNode.d.ts +342 -0
- package/dist/matterNode.d.ts.map +1 -0
- package/dist/matterNode.js +369 -8
- package/dist/matterNode.js.map +1 -0
- package/dist/matterbridge.d.ts +492 -0
- package/dist/matterbridge.d.ts.map +1 -0
- package/dist/matterbridge.js +811 -46
- package/dist/matterbridge.js.map +1 -0
- package/dist/matterbridgeAccessoryPlatform.d.ts +41 -0
- package/dist/matterbridgeAccessoryPlatform.d.ts.map +1 -0
- package/dist/matterbridgeAccessoryPlatform.js +38 -0
- package/dist/matterbridgeAccessoryPlatform.js.map +1 -0
- package/dist/matterbridgeBehaviors.d.ts +2404 -0
- package/dist/matterbridgeBehaviors.d.ts.map +1 -0
- package/dist/matterbridgeBehaviors.js +68 -5
- package/dist/matterbridgeBehaviors.js.map +1 -0
- package/dist/matterbridgeDeviceTypes.d.ts +698 -0
- package/dist/matterbridgeDeviceTypes.d.ts.map +1 -0
- package/dist/matterbridgeDeviceTypes.js +635 -14
- package/dist/matterbridgeDeviceTypes.js.map +1 -0
- package/dist/matterbridgeDynamicPlatform.d.ts +41 -0
- package/dist/matterbridgeDynamicPlatform.d.ts.map +1 -0
- package/dist/matterbridgeDynamicPlatform.js +38 -0
- package/dist/matterbridgeDynamicPlatform.js.map +1 -0
- package/dist/matterbridgeEndpoint.d.ts +1507 -0
- package/dist/matterbridgeEndpoint.d.ts.map +1 -0
- package/dist/matterbridgeEndpoint.js +1444 -53
- package/dist/matterbridgeEndpoint.js.map +1 -0
- package/dist/matterbridgeEndpointHelpers.d.ts +787 -0
- package/dist/matterbridgeEndpointHelpers.d.ts.map +1 -0
- package/dist/matterbridgeEndpointHelpers.js +483 -20
- package/dist/matterbridgeEndpointHelpers.js.map +1 -0
- package/dist/matterbridgeEndpointTypes.d.ts +166 -0
- package/dist/matterbridgeEndpointTypes.d.ts.map +1 -0
- package/dist/matterbridgeEndpointTypes.js +25 -0
- package/dist/matterbridgeEndpointTypes.js.map +1 -0
- package/dist/matterbridgePlatform.d.ts +539 -0
- package/dist/matterbridgePlatform.d.ts.map +1 -0
- package/dist/matterbridgePlatform.js +451 -1
- package/dist/matterbridgePlatform.js.map +1 -0
- package/dist/matterbridgeTypes.d.ts +251 -0
- package/dist/matterbridgeTypes.d.ts.map +1 -0
- package/dist/matterbridgeTypes.js +26 -0
- package/dist/matterbridgeTypes.js.map +1 -0
- package/dist/pluginManager.d.ts +372 -0
- package/dist/pluginManager.d.ts.map +1 -0
- package/dist/pluginManager.js +341 -5
- package/dist/pluginManager.js.map +1 -0
- package/dist/shelly.d.ts +181 -0
- package/dist/shelly.d.ts.map +1 -0
- package/dist/shelly.js +178 -7
- package/dist/shelly.js.map +1 -0
- package/dist/storage/export.d.ts +2 -0
- package/dist/storage/export.d.ts.map +1 -0
- package/dist/storage/export.js +1 -0
- package/dist/storage/export.js.map +1 -0
- package/dist/update.d.ts +84 -0
- package/dist/update.d.ts.map +1 -0
- package/dist/update.js +93 -1
- package/dist/update.js.map +1 -0
- package/dist/utils/colorUtils.d.ts +101 -0
- package/dist/utils/colorUtils.d.ts.map +1 -0
- package/dist/utils/colorUtils.js +97 -2
- package/dist/utils/colorUtils.js.map +1 -0
- package/dist/utils/commandLine.d.ts +66 -0
- package/dist/utils/commandLine.d.ts.map +1 -0
- package/dist/utils/commandLine.js +60 -0
- package/dist/utils/commandLine.js.map +1 -0
- package/dist/utils/copyDirectory.d.ts +35 -0
- package/dist/utils/copyDirectory.d.ts.map +1 -0
- package/dist/utils/copyDirectory.js +37 -0
- package/dist/utils/copyDirectory.js.map +1 -0
- package/dist/utils/createDirectory.d.ts +34 -0
- package/dist/utils/createDirectory.d.ts.map +1 -0
- package/dist/utils/createDirectory.js +33 -0
- package/dist/utils/createDirectory.js.map +1 -0
- package/dist/utils/createZip.d.ts +39 -0
- package/dist/utils/createZip.d.ts.map +1 -0
- package/dist/utils/createZip.js +47 -2
- package/dist/utils/createZip.js.map +1 -0
- package/dist/utils/deepCopy.d.ts +32 -0
- package/dist/utils/deepCopy.d.ts.map +1 -0
- package/dist/utils/deepCopy.js +39 -0
- package/dist/utils/deepCopy.js.map +1 -0
- package/dist/utils/deepEqual.d.ts +54 -0
- package/dist/utils/deepEqual.d.ts.map +1 -0
- package/dist/utils/deepEqual.js +72 -1
- package/dist/utils/deepEqual.js.map +1 -0
- package/dist/utils/error.d.ts +45 -0
- package/dist/utils/error.d.ts.map +1 -0
- package/dist/utils/error.js +42 -0
- package/dist/utils/error.js.map +1 -0
- package/dist/utils/export.d.ts +13 -0
- package/dist/utils/export.d.ts.map +1 -0
- package/dist/utils/export.js +1 -0
- package/dist/utils/export.js.map +1 -0
- package/dist/utils/format.d.ts +53 -0
- package/dist/utils/format.d.ts.map +1 -0
- package/dist/utils/format.js +49 -0
- package/dist/utils/format.js.map +1 -0
- package/dist/utils/hex.d.ts +89 -0
- package/dist/utils/hex.d.ts.map +1 -0
- package/dist/utils/hex.js +124 -0
- package/dist/utils/hex.js.map +1 -0
- package/dist/utils/inspector.d.ts +87 -0
- package/dist/utils/inspector.d.ts.map +1 -0
- package/dist/utils/inspector.js +69 -1
- package/dist/utils/inspector.js.map +1 -0
- package/dist/utils/isvalid.d.ts +103 -0
- package/dist/utils/isvalid.d.ts.map +1 -0
- package/dist/utils/isvalid.js +101 -0
- package/dist/utils/isvalid.js.map +1 -0
- package/dist/utils/network.d.ts +111 -0
- package/dist/utils/network.d.ts.map +1 -0
- package/dist/utils/network.js +96 -5
- package/dist/utils/network.js.map +1 -0
- package/dist/utils/spawn.d.ts +33 -0
- package/dist/utils/spawn.d.ts.map +1 -0
- package/dist/utils/spawn.js +71 -1
- package/dist/utils/spawn.js.map +1 -0
- package/dist/utils/tracker.d.ts +108 -0
- package/dist/utils/tracker.d.ts.map +1 -0
- package/dist/utils/tracker.js +64 -1
- package/dist/utils/tracker.js.map +1 -0
- package/dist/utils/wait.d.ts +54 -0
- package/dist/utils/wait.d.ts.map +1 -0
- package/dist/utils/wait.js +60 -8
- package/dist/utils/wait.js.map +1 -0
- package/dist/workerGlobalPrefix.d.ts +25 -0
- package/dist/workerGlobalPrefix.d.ts.map +1 -0
- package/dist/workerGlobalPrefix.js +37 -5
- package/dist/workerGlobalPrefix.js.map +1 -0
- package/dist/workerTypes.d.ts +52 -0
- package/dist/workerTypes.d.ts.map +1 -0
- package/dist/workerTypes.js +24 -0
- package/dist/workerTypes.js.map +1 -0
- package/dist/workers.d.ts +69 -0
- package/dist/workers.d.ts.map +1 -0
- package/dist/workers.js +68 -4
- package/dist/workers.js.map +1 -0
- package/npm-shrinkwrap.json +2 -2
- package/package.json +2 -1
- package/scripts/data_model.mjs +2058 -0
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @description This file contains the class Coap.
|
|
3
|
+
* @file src/dgram/coap.ts
|
|
4
|
+
* @author Luca Liguori
|
|
5
|
+
* @created 2025-03-22
|
|
6
|
+
* @version 1.0.0
|
|
7
|
+
* @license Apache-2.0
|
|
8
|
+
*
|
|
9
|
+
* Copyright 2025, 2026, 2027 Luca Liguori.
|
|
10
|
+
*
|
|
11
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
12
|
+
* you may not use this file except in compliance with the License.
|
|
13
|
+
* You may obtain a copy of the License at
|
|
14
|
+
*
|
|
15
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
16
|
+
*
|
|
17
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
18
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
19
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
20
|
+
* See the License for the specific language governing permissions and
|
|
21
|
+
* limitations under the License.
|
|
22
|
+
*/
|
|
23
|
+
import dgram from 'node:dgram';
|
|
24
|
+
import { Multicast } from './multicast.js';
|
|
25
|
+
/**
|
|
26
|
+
* Represents a CoAP message.
|
|
27
|
+
*
|
|
28
|
+
* A CoAP message is structured with a fixed header, an optional token, a series of options,
|
|
29
|
+
* and an optional payload. The header consists of version, type, token length, code, and message ID.
|
|
30
|
+
* The token is used to match responses with requests, options provide additional metadata, and
|
|
31
|
+
* the payload carries the message content.
|
|
32
|
+
*/
|
|
33
|
+
export interface CoapMessage {
|
|
34
|
+
/**
|
|
35
|
+
* The CoAP protocol version.
|
|
36
|
+
* Typically, this is 1.
|
|
37
|
+
* (Stored in the top 2 bits of the first header byte.)
|
|
38
|
+
*/
|
|
39
|
+
version: number;
|
|
40
|
+
/**
|
|
41
|
+
* The message type.
|
|
42
|
+
* It indicates whether the message is Confirmable, Non-confirmable, Acknowledgement, or Reset.
|
|
43
|
+
* (Stored in bits 5-4 of the first header byte.)
|
|
44
|
+
* 0: Confirmable (CON)
|
|
45
|
+
* 1: Non-confirmable (NON)
|
|
46
|
+
* 2: Acknowledgement (ACK)
|
|
47
|
+
* 3: Reset (RST)
|
|
48
|
+
*/
|
|
49
|
+
type: number;
|
|
50
|
+
/**
|
|
51
|
+
* The token length.
|
|
52
|
+
* This value (0-8) specifies the length of the token field.
|
|
53
|
+
* (Stored in the lower 4 bits of the first header byte.)
|
|
54
|
+
*/
|
|
55
|
+
tokenLength: number;
|
|
56
|
+
/**
|
|
57
|
+
* The message code.
|
|
58
|
+
* It indicates the method or response code, e.g., GET, POST, or a success/error response.
|
|
59
|
+
* (Stored in the second header byte.)
|
|
60
|
+
* CoAP uses an 8‑bit Code field divided into a 3‑bit class and a 5‑bit detail. The code can be represented as X.XX (e.g. 0.01) and is defined in RFC 7252. Here are the standard CoAP codes:
|
|
61
|
+
* Request Codes (Class 0)
|
|
62
|
+
* 0.01 – 1-GET
|
|
63
|
+
* Retrieve a resource.
|
|
64
|
+
* 0.02 – 2-POST
|
|
65
|
+
* Create a resource or trigger an action.
|
|
66
|
+
* 0.03 – 3-PUT
|
|
67
|
+
* Update or create a resource.
|
|
68
|
+
* 0.04 – 4-DELETE
|
|
69
|
+
* Remove a resource.
|
|
70
|
+
* Success Response Codes (Class 2)
|
|
71
|
+
* 2.00 – Empty / Success
|
|
72
|
+
* Indicates an empty message or a successful request with no payload.
|
|
73
|
+
* 2.01 – Created
|
|
74
|
+
* The request resulted in a new resource being created.
|
|
75
|
+
* 2.02 – Deleted
|
|
76
|
+
* The resource was successfully deleted.
|
|
77
|
+
* 2.03 – Valid
|
|
78
|
+
* The response indicates that the resource is still valid (used with caching).
|
|
79
|
+
* 2.04 – Changed
|
|
80
|
+
* The resource was successfully modified.
|
|
81
|
+
* 2.05 – Content
|
|
82
|
+
* The response contains the requested content.
|
|
83
|
+
* Client Error Response Codes (Class 4)
|
|
84
|
+
* 4.00 – Bad Request
|
|
85
|
+
* The request was malformed.
|
|
86
|
+
* 4.01 – Unauthorized
|
|
87
|
+
* The request requires authentication.
|
|
88
|
+
* 4.02 – Bad Option
|
|
89
|
+
* An option in the request was not understood or is unacceptable.
|
|
90
|
+
* 4.03 – Forbidden
|
|
91
|
+
* The server refuses to fulfill the request.
|
|
92
|
+
* 4.04 – Not Found
|
|
93
|
+
* The requested resource was not found.
|
|
94
|
+
* 4.05 – Method Not Allowed
|
|
95
|
+
* The request method is not supported for the target resource.
|
|
96
|
+
* 4.06 – Not Acceptable
|
|
97
|
+
* The server cannot generate a response matching the list of acceptable values.
|
|
98
|
+
* 4.12 – Precondition Failed
|
|
99
|
+
* A precondition given in the request evaluated to false.
|
|
100
|
+
* 4.13 – Request Entity Too Large
|
|
101
|
+
* The request payload is too large.
|
|
102
|
+
* 4.15 – Unsupported Content-Format
|
|
103
|
+
* The server does not support the content format of the request payload.
|
|
104
|
+
* Server Error Response Codes (Class 5)
|
|
105
|
+
* 5.00 – Internal Server Error
|
|
106
|
+
* The server encountered an unexpected condition.
|
|
107
|
+
* 5.01 – Not Implemented
|
|
108
|
+
* The server does not support the requested method.
|
|
109
|
+
* 5.02 – Bad Gateway
|
|
110
|
+
* The server, while acting as a gateway or proxy, received an invalid response.
|
|
111
|
+
* 5.03 – Service Unavailable
|
|
112
|
+
* The server is currently unable to handle the request.
|
|
113
|
+
* 5.04 – Gateway Timeout
|
|
114
|
+
* The server did not receive a timely response from an upstream server.
|
|
115
|
+
* 5.05 – Proxying Not Supported
|
|
116
|
+
* The server does not support proxying for the requested resource.
|
|
117
|
+
*/
|
|
118
|
+
code: number;
|
|
119
|
+
/**
|
|
120
|
+
* The message identifier.
|
|
121
|
+
* This 16-bit field is used to match messages of type Acknowledgement/Reset with their corresponding requests.
|
|
122
|
+
* (Stored in bytes 2-3 of the header.)
|
|
123
|
+
*/
|
|
124
|
+
messageId: number;
|
|
125
|
+
/**
|
|
126
|
+
* The token.
|
|
127
|
+
* A variable-length sequence (0-8 bytes) that helps match a request with its response.
|
|
128
|
+
*/
|
|
129
|
+
token: Buffer;
|
|
130
|
+
/**
|
|
131
|
+
* An array of options.
|
|
132
|
+
* Options carry additional information such as URI path, content format, etc., and are encoded using a delta mechanism.
|
|
133
|
+
*/
|
|
134
|
+
options: CoapOption[];
|
|
135
|
+
/**
|
|
136
|
+
* The payload.
|
|
137
|
+
* The actual content of the message, if present. It follows a payload marker (0xFF) if non-empty.
|
|
138
|
+
*/
|
|
139
|
+
payload?: Buffer;
|
|
140
|
+
}
|
|
141
|
+
interface CoapOption {
|
|
142
|
+
number: number;
|
|
143
|
+
value: Buffer;
|
|
144
|
+
}
|
|
145
|
+
export declare const COAP_OPTION_URI_PATH = 11;
|
|
146
|
+
export declare const COIOT_OPTION_DEVID = 3332;
|
|
147
|
+
export declare const COIOT_OPTION_VALIDITY = 3412;
|
|
148
|
+
export declare const COIOT_OPTION_SERIAL = 3420;
|
|
149
|
+
export declare const COIOT_REQUEST_STATUS_ID = 56831;
|
|
150
|
+
export declare const COIOT_REQUEST_DESCRIPTION_ID = 56832;
|
|
151
|
+
export declare class Coap extends Multicast {
|
|
152
|
+
constructor(name: string, multicastAddress: string, multicastPort: number, socketType: 'udp4' | 'udp6', reuseAddr?: boolean | undefined, interfaceName?: string, interfaceAddress?: string);
|
|
153
|
+
onCoapMessage(message: CoapMessage, rinfo: dgram.RemoteInfo): void;
|
|
154
|
+
onMessage(msg: Buffer, rinfo: dgram.RemoteInfo): void;
|
|
155
|
+
/**
|
|
156
|
+
* Decodes a CoAP message from a Buffer.
|
|
157
|
+
*
|
|
158
|
+
* @param {Buffer} msg - The Buffer containing the raw CoAP message.
|
|
159
|
+
* @returns {CoapMessage} A parsed CoAP message object.
|
|
160
|
+
* @throws {Error} if the message is malformed.
|
|
161
|
+
*/
|
|
162
|
+
decodeCoapMessage(msg: Buffer): CoapMessage;
|
|
163
|
+
/**
|
|
164
|
+
* Encodes a CoAP message into a Buffer.
|
|
165
|
+
*
|
|
166
|
+
* @param {CoapMessage} msg - The CoAP message to encode.
|
|
167
|
+
* @returns {Buffer} A Buffer representing the encoded CoAP message.
|
|
168
|
+
* @throws {Error} if the message is malformed.
|
|
169
|
+
*/
|
|
170
|
+
encodeCoapMessage(msg: CoapMessage): Buffer;
|
|
171
|
+
/**
|
|
172
|
+
* Converts a CoAP message type numeric value to its string representation.
|
|
173
|
+
*
|
|
174
|
+
* CoAP message types are:
|
|
175
|
+
* - 0: Confirmable (CON)
|
|
176
|
+
* - 1: Non-confirmable (NON)
|
|
177
|
+
* - 2: Acknowledgement (ACK)
|
|
178
|
+
* - 3: Reset (RST)
|
|
179
|
+
*
|
|
180
|
+
* @param {number} type - The numeric CoAP message type.
|
|
181
|
+
* @returns {string} The string representation of the message type.
|
|
182
|
+
*/
|
|
183
|
+
coapTypeToString(type: number): string;
|
|
184
|
+
/**
|
|
185
|
+
* Converts a CoAP code numeric value to its string representation.
|
|
186
|
+
*
|
|
187
|
+
* The CoAP code is split into a 3-bit class and a 5-bit detail.
|
|
188
|
+
* For example:
|
|
189
|
+
* - 0.01: GET
|
|
190
|
+
* - 0.02: POST
|
|
191
|
+
* - 0.03: PUT
|
|
192
|
+
* - 0.04: DELETE
|
|
193
|
+
* - 2.05: Content (success response)
|
|
194
|
+
* - 4.04: Not Found (client error)
|
|
195
|
+
* - 5.00: Internal Server Error (server error)
|
|
196
|
+
*
|
|
197
|
+
* @param {number} code - The numeric CoAP code.
|
|
198
|
+
* @returns {string} The string representation of the code.
|
|
199
|
+
*/
|
|
200
|
+
coapCodeToString(code: number): string;
|
|
201
|
+
sendRequest(messageId: number, options: CoapOption[], payload: Record<string, any> | undefined, token: string | undefined, address: string | undefined, port: number | undefined): void;
|
|
202
|
+
logCoapMessage(msg: CoapMessage): void;
|
|
203
|
+
}
|
|
204
|
+
export {};
|
|
205
|
+
//# sourceMappingURL=coap.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"coap.d.ts","sourceRoot":"","sources":["../../src/dgram/coap.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAGH,OAAO,KAAK,MAAM,YAAY,CAAC;AAM/B,OAAO,EAAoD,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAE7F;;;;;;;GAOG;AACH,MAAM,WAAW,WAAW;IAC1B;;;;OAIG;IACH,OAAO,EAAE,MAAM,CAAC;IAChB;;;;;;;;OAQG;IACH,IAAI,EAAE,MAAM,CAAC;IACb;;;;OAIG;IACH,WAAW,EAAE,MAAM,CAAC;IACpB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA6DG;IACH,IAAI,EAAE,MAAM,CAAC;IACb;;;;OAIG;IACH,SAAS,EAAE,MAAM,CAAC;IAClB;;;OAGG;IACH,KAAK,EAAE,MAAM,CAAC;IACd;;;OAGG;IACH,OAAO,EAAE,UAAU,EAAE,CAAC;IACtB;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,UAAU,UAAU;IAClB,MAA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SAAS,GACvB,IAAI;IAeP,cAAc,CAAC,GAAG,EAAE,WAAW;CAuDhC"}
|
package/dist/dgram/coap.js
CHANGED
|
@@ -1,4 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @description This file contains the class Coap.
|
|
3
|
+
* @file src/dgram/coap.ts
|
|
4
|
+
* @author Luca Liguori
|
|
5
|
+
* @created 2025-03-22
|
|
6
|
+
* @version 1.0.0
|
|
7
|
+
* @license Apache-2.0
|
|
8
|
+
*
|
|
9
|
+
* Copyright 2025, 2026, 2027 Luca Liguori.
|
|
10
|
+
*
|
|
11
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
12
|
+
* you may not use this file except in compliance with the License.
|
|
13
|
+
* You may obtain a copy of the License at
|
|
14
|
+
*
|
|
15
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
16
|
+
*
|
|
17
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
18
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
19
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
20
|
+
* See the License for the specific language governing permissions and
|
|
21
|
+
* limitations under the License.
|
|
22
|
+
*/
|
|
23
|
+
// AnsiLogger imports
|
|
1
24
|
import { BLUE, db, GREEN, MAGENTA, nf } from 'node-ansi-logger';
|
|
25
|
+
// Net imports
|
|
2
26
|
import { COAP_MULTICAST_IPV4_ADDRESS, COAP_MULTICAST_PORT, Multicast } from './multicast.js';
|
|
3
27
|
export const COAP_OPTION_URI_PATH = 11;
|
|
4
28
|
export const COIOT_OPTION_DEVID = 3332;
|
|
@@ -24,16 +48,26 @@ export class Coap extends Multicast {
|
|
|
24
48
|
this.log.error(`Error decoding CoAP message: ${error instanceof Error ? error.message : error}`);
|
|
25
49
|
}
|
|
26
50
|
}
|
|
51
|
+
/**
|
|
52
|
+
* Decodes a CoAP message from a Buffer.
|
|
53
|
+
*
|
|
54
|
+
* @param {Buffer} msg - The Buffer containing the raw CoAP message.
|
|
55
|
+
* @returns {CoapMessage} A parsed CoAP message object.
|
|
56
|
+
* @throws {Error} if the message is malformed.
|
|
57
|
+
*/
|
|
27
58
|
decodeCoapMessage(msg) {
|
|
59
|
+
// A valid CoAP message must have at least 4 bytes for the header.
|
|
28
60
|
if (msg.length < 4) {
|
|
29
61
|
throw new Error('Message too short to be a valid CoAP message');
|
|
30
62
|
}
|
|
31
|
-
|
|
32
|
-
const
|
|
33
|
-
const
|
|
34
|
-
const
|
|
35
|
-
const
|
|
63
|
+
// Parse the 4-byte fixed header.
|
|
64
|
+
const version = (msg[0] & 0xc0) >> 6; // Bits 7-6: Version
|
|
65
|
+
const type = (msg[0] & 0x30) >> 4; // Bits 5-4: Type
|
|
66
|
+
const tokenLength = msg[0] & 0x0f; // Bits 3-0: Token Length
|
|
67
|
+
const code = msg[1]; // 8-bit Code
|
|
68
|
+
const messageId = msg.readUInt16BE(2); // 16-bit Message ID
|
|
36
69
|
let offset = 4;
|
|
70
|
+
// Parse token if present.
|
|
37
71
|
let token = Buffer.alloc(0);
|
|
38
72
|
if (tokenLength > 0) {
|
|
39
73
|
if (msg.length < offset + tokenLength) {
|
|
@@ -42,16 +76,20 @@ export class Coap extends Multicast {
|
|
|
42
76
|
token = msg.slice(offset, offset + tokenLength);
|
|
43
77
|
offset += tokenLength;
|
|
44
78
|
}
|
|
79
|
+
// Parse options.
|
|
45
80
|
const options = [];
|
|
46
81
|
let currentOptionNumber = 0;
|
|
47
82
|
while (offset < msg.length) {
|
|
83
|
+
// Payload marker: 0xFF indicates the beginning of the payload.
|
|
48
84
|
if (msg[offset] === 0xff) {
|
|
49
|
-
offset++;
|
|
85
|
+
offset++; // Skip the marker.
|
|
50
86
|
break;
|
|
51
87
|
}
|
|
88
|
+
// Read the option header byte.
|
|
52
89
|
const optionHeader = msg[offset++];
|
|
53
|
-
let delta = (optionHeader & 0xf0) >> 4;
|
|
54
|
-
let length = optionHeader & 0x0f;
|
|
90
|
+
let delta = (optionHeader & 0xf0) >> 4; // High nibble: option delta.
|
|
91
|
+
let length = optionHeader & 0x0f; // Low nibble: option length.
|
|
92
|
+
// Extended delta handling.
|
|
55
93
|
if (delta === 13) {
|
|
56
94
|
if (offset >= msg.length) {
|
|
57
95
|
throw new Error('Invalid extended option delta');
|
|
@@ -68,6 +106,7 @@ export class Coap extends Multicast {
|
|
|
68
106
|
else if (delta === 15) {
|
|
69
107
|
throw new Error('Reserved option delta value encountered');
|
|
70
108
|
}
|
|
109
|
+
// Extended length handling.
|
|
71
110
|
if (length === 13) {
|
|
72
111
|
if (offset >= msg.length) {
|
|
73
112
|
throw new Error('Invalid extended option length');
|
|
@@ -84,7 +123,9 @@ export class Coap extends Multicast {
|
|
|
84
123
|
else if (length === 15) {
|
|
85
124
|
throw new Error('Reserved option length value encountered');
|
|
86
125
|
}
|
|
126
|
+
// Calculate the actual option number.
|
|
87
127
|
currentOptionNumber += delta;
|
|
128
|
+
// Ensure that the option's value fits in the remaining message.
|
|
88
129
|
if (offset + length > msg.length) {
|
|
89
130
|
throw new Error('Option length exceeds message length');
|
|
90
131
|
}
|
|
@@ -95,6 +136,7 @@ export class Coap extends Multicast {
|
|
|
95
136
|
value: optionValue,
|
|
96
137
|
});
|
|
97
138
|
}
|
|
139
|
+
// Parse payload if any remains.
|
|
98
140
|
const payload = offset < msg.length ? msg.slice(offset) : undefined;
|
|
99
141
|
return {
|
|
100
142
|
version,
|
|
@@ -107,23 +149,38 @@ export class Coap extends Multicast {
|
|
|
107
149
|
payload,
|
|
108
150
|
};
|
|
109
151
|
}
|
|
152
|
+
/**
|
|
153
|
+
* Encodes a CoAP message into a Buffer.
|
|
154
|
+
*
|
|
155
|
+
* @param {CoapMessage} msg - The CoAP message to encode.
|
|
156
|
+
* @returns {Buffer} A Buffer representing the encoded CoAP message.
|
|
157
|
+
* @throws {Error} if the message is malformed.
|
|
158
|
+
*/
|
|
110
159
|
encodeCoapMessage(msg) {
|
|
111
160
|
const parts = [];
|
|
161
|
+
// Determine token length (ensure it's consistent with msg.token)
|
|
112
162
|
const token = msg.token || Buffer.alloc(0);
|
|
113
163
|
const tokenLength = token.length;
|
|
114
164
|
if (tokenLength > 8) {
|
|
115
165
|
throw new Error('Token length cannot exceed 8 bytes');
|
|
116
166
|
}
|
|
167
|
+
// Create header (4 bytes):
|
|
168
|
+
// Byte 0: Version (2 bits), Type (2 bits), Token Length (4 bits)
|
|
169
|
+
// Byte 1: Code (8 bits)
|
|
170
|
+
// Bytes 2-3: Message ID (16 bits)
|
|
117
171
|
const header = Buffer.alloc(4);
|
|
118
172
|
header[0] = ((msg.version & 0x03) << 6) | ((msg.type & 0x03) << 4) | (tokenLength & 0x0f);
|
|
119
173
|
header[1] = msg.code;
|
|
120
174
|
header.writeUInt16BE(msg.messageId, 2);
|
|
121
175
|
parts.push(header);
|
|
176
|
+
// Append token if present.
|
|
122
177
|
if (tokenLength > 0) {
|
|
123
178
|
parts.push(token);
|
|
124
179
|
}
|
|
180
|
+
// Sort options by option number in ascending order.
|
|
125
181
|
const sortedOptions = msg.options.slice().sort((a, b) => a.number - b.number);
|
|
126
182
|
let previousOptionNumber = 0;
|
|
183
|
+
// Encode each option.
|
|
127
184
|
for (const option of sortedOptions) {
|
|
128
185
|
const optionDelta = option.number - previousOptionNumber;
|
|
129
186
|
const optionValueLength = option.value.length;
|
|
@@ -131,6 +188,7 @@ export class Coap extends Multicast {
|
|
|
131
188
|
let deltaExtended = null;
|
|
132
189
|
let lengthNibble;
|
|
133
190
|
let lengthExtended = null;
|
|
191
|
+
// Determine option delta nibble and extended delta field.
|
|
134
192
|
if (optionDelta < 13) {
|
|
135
193
|
deltaNibble = optionDelta;
|
|
136
194
|
}
|
|
@@ -143,6 +201,7 @@ export class Coap extends Multicast {
|
|
|
143
201
|
deltaExtended = Buffer.alloc(2);
|
|
144
202
|
deltaExtended.writeUInt16BE(optionDelta - 269, 0);
|
|
145
203
|
}
|
|
204
|
+
// Determine option length nibble and extended length field.
|
|
146
205
|
if (optionValueLength < 13) {
|
|
147
206
|
lengthNibble = optionValueLength;
|
|
148
207
|
}
|
|
@@ -155,24 +214,42 @@ export class Coap extends Multicast {
|
|
|
155
214
|
lengthExtended = Buffer.alloc(2);
|
|
156
215
|
lengthExtended.writeUInt16BE(optionValueLength - 269, 0);
|
|
157
216
|
}
|
|
217
|
+
// Option header byte: high nibble is delta, low nibble is length.
|
|
158
218
|
const optionHeader = Buffer.alloc(1);
|
|
159
219
|
optionHeader[0] = (deltaNibble << 4) | (lengthNibble & 0x0f);
|
|
160
220
|
parts.push(optionHeader);
|
|
221
|
+
// Append extended delta if needed.
|
|
161
222
|
if (deltaExtended) {
|
|
162
223
|
parts.push(deltaExtended);
|
|
163
224
|
}
|
|
225
|
+
// Append extended length if needed.
|
|
164
226
|
if (lengthExtended) {
|
|
165
227
|
parts.push(lengthExtended);
|
|
166
228
|
}
|
|
229
|
+
// Append the option value.
|
|
167
230
|
parts.push(option.value);
|
|
231
|
+
// Update previous option number.
|
|
168
232
|
previousOptionNumber = option.number;
|
|
169
233
|
}
|
|
234
|
+
// If a payload is present, add the payload marker (0xFF) followed by the payload.
|
|
170
235
|
if (msg.payload && msg.payload.length > 0) {
|
|
171
|
-
parts.push(Buffer.from([0xff]));
|
|
236
|
+
parts.push(Buffer.from([0xff])); // Payload marker.
|
|
172
237
|
parts.push(msg.payload);
|
|
173
238
|
}
|
|
174
239
|
return Buffer.concat(parts);
|
|
175
240
|
}
|
|
241
|
+
/**
|
|
242
|
+
* Converts a CoAP message type numeric value to its string representation.
|
|
243
|
+
*
|
|
244
|
+
* CoAP message types are:
|
|
245
|
+
* - 0: Confirmable (CON)
|
|
246
|
+
* - 1: Non-confirmable (NON)
|
|
247
|
+
* - 2: Acknowledgement (ACK)
|
|
248
|
+
* - 3: Reset (RST)
|
|
249
|
+
*
|
|
250
|
+
* @param {number} type - The numeric CoAP message type.
|
|
251
|
+
* @returns {string} The string representation of the message type.
|
|
252
|
+
*/
|
|
176
253
|
coapTypeToString(type) {
|
|
177
254
|
switch (type) {
|
|
178
255
|
case 0:
|
|
@@ -187,18 +264,37 @@ export class Coap extends Multicast {
|
|
|
187
264
|
return `Unknown Type (${type})`;
|
|
188
265
|
}
|
|
189
266
|
}
|
|
267
|
+
/**
|
|
268
|
+
* Converts a CoAP code numeric value to its string representation.
|
|
269
|
+
*
|
|
270
|
+
* The CoAP code is split into a 3-bit class and a 5-bit detail.
|
|
271
|
+
* For example:
|
|
272
|
+
* - 0.01: GET
|
|
273
|
+
* - 0.02: POST
|
|
274
|
+
* - 0.03: PUT
|
|
275
|
+
* - 0.04: DELETE
|
|
276
|
+
* - 2.05: Content (success response)
|
|
277
|
+
* - 4.04: Not Found (client error)
|
|
278
|
+
* - 5.00: Internal Server Error (server error)
|
|
279
|
+
*
|
|
280
|
+
* @param {number} code - The numeric CoAP code.
|
|
281
|
+
* @returns {string} The string representation of the code.
|
|
282
|
+
*/
|
|
190
283
|
coapCodeToString(code) {
|
|
284
|
+
// Split the code: the upper 3 bits form the class and the lower 5 bits form the detail.
|
|
191
285
|
const cls = code >> 5;
|
|
192
286
|
const detail = code & 0x1f;
|
|
193
287
|
const codeStr = `${cls}.${detail.toString().padStart(2, '0')}`;
|
|
194
288
|
return codeStr;
|
|
195
289
|
}
|
|
196
|
-
sendRequest(messageId, options,
|
|
290
|
+
sendRequest(messageId, options,
|
|
291
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
292
|
+
payload, token, address, port) {
|
|
197
293
|
const coapMessage = {
|
|
198
294
|
version: 1,
|
|
199
|
-
type: 1,
|
|
295
|
+
type: 1, // e.g., Confirmable
|
|
200
296
|
tokenLength: token ? Buffer.from(token).length : 0,
|
|
201
|
-
code: 1,
|
|
297
|
+
code: 1, // e.g., GET
|
|
202
298
|
messageId,
|
|
203
299
|
token: token ? Buffer.from(token) : Buffer.alloc(0),
|
|
204
300
|
options,
|
|
@@ -217,6 +313,10 @@ export class Coap extends Multicast {
|
|
|
217
313
|
this.log.info(`Option: COAP_OPTION_URI_PATH => ${GREEN}${option.value}${nf}`);
|
|
218
314
|
}
|
|
219
315
|
else if (option.number === COIOT_OPTION_DEVID) {
|
|
316
|
+
/*
|
|
317
|
+
* First defined option is COIOT_OPTION_GLOBAL_DEVID. This is a global option and must be present in all CoIoT packages with request or payload.
|
|
318
|
+
* Its value is a string in format <devtype>#<devid>#<version> for example SHSEN-1#4B3F9E#1 The whole option should be less than 50 bytes.
|
|
319
|
+
*/
|
|
220
320
|
const parts = option.value.toString().split('#');
|
|
221
321
|
const deviceModel = parts[0];
|
|
222
322
|
const deviceMac = parts[1];
|
|
@@ -224,10 +324,22 @@ export class Coap extends Multicast {
|
|
|
224
324
|
this.log.info(`Option: COIOT_OPTION_DEVID => ${option.value} => Model: ${GREEN}${deviceModel}${nf}, MAC: ${GREEN}${deviceMac}${nf}, Protocol: ${GREEN}${protocolRevision}${nf}`);
|
|
225
325
|
}
|
|
226
326
|
else if (option.number === COIOT_OPTION_SERIAL) {
|
|
327
|
+
/*
|
|
328
|
+
* This option is mandatory in status response and publishes. It is a uint16_t in network byte order which indicates a change in the status report.
|
|
329
|
+
* When a new status report is handled, all payload processing can be skipped if the serial number does not change from the last processed payload.
|
|
330
|
+
* The value 0 is reserved and should not be sent. This allows easy initialization in the receiving devices.
|
|
331
|
+
*/
|
|
227
332
|
const serial = option.value.readUInt16BE(0);
|
|
228
333
|
this.log.info(`Option: COIOT_OPTION_SERIAL => 0x${option.value.toString('hex')} => serial: ${GREEN}${serial}${nf}`);
|
|
229
334
|
}
|
|
230
335
|
else if (option.number === COIOT_OPTION_VALIDITY) {
|
|
336
|
+
/*
|
|
337
|
+
* COIOT_OPTION_STATUS_VALIDITY is a uint16_t in network byte order (big endian) that states the maximal time between this and the next status publish.
|
|
338
|
+
* This way a device can state its report interval. If a report is not received from this device after the interval has passed the device should be considered offline.
|
|
339
|
+
* The LS bit of this option controls how the value is scaled:
|
|
340
|
+
* - If the LS bit is 0, the value is number of 1/10 of seconds in the validity period, so 2 is 0.2 seconds, 10 is a second, 600 is a minute, 65534 is 109 minutes and 13 seconds.
|
|
341
|
+
* - If the LS bit is 1, the value is number of 4 seconds interval in the whole interval. So 3 is 12 seconds, 11 is 44 seconds and 65535 is more than 3 days.
|
|
342
|
+
*/
|
|
231
343
|
const validity = option.value.readUInt16BE(0);
|
|
232
344
|
let validFor = 0;
|
|
233
345
|
if ((validity & 0x1) === 0) {
|
|
@@ -242,7 +354,7 @@ export class Coap extends Multicast {
|
|
|
242
354
|
this.log.info(`Option: ${option.number} - ${option.value
|
|
243
355
|
.toString('hex')
|
|
244
356
|
.match(/.{1,2}/g)
|
|
245
|
-
?.join(' ')}`);
|
|
357
|
+
?.join(' ')}`); // Split into pairs of hex characters
|
|
246
358
|
});
|
|
247
359
|
if (msg.payload && msg.payload.length > 0)
|
|
248
360
|
this.log.info(`Payload:`, JSON.parse(msg.payload.toString()), '\n');
|
|
@@ -250,3 +362,4 @@ export class Coap extends Multicast {
|
|
|
250
362
|
this.log.info(`No payload`, '\n');
|
|
251
363
|
}
|
|
252
364
|
}
|
|
365
|
+
//# sourceMappingURL=coap.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"coap.js","sourceRoot":"","sources":["../../src/dgram/coap.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAKH,qBAAqB;AACrB,OAAO,EAAE,IAAI,EAAE,EAAE,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE,EAAE,MAAM,kBAAkB,CAAC;AAEhE,cAAc;AACd,OAAO,EAAE,2BAA2B,EAAE,mBAAmB,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AA4H7F,MAAM,CAAC,MAAM,oBAAoB,GAAG,EAAE,CAAC;AACvC,MAAM,CAAC,MAAM,kBAAkB,GAAG,IAAI,CAAC;AACvC,MAAM,CAAC,MAAM,qBAAqB,GAAG,IAAI,CAAC;AAC1C,MAAM,CAAC,MAAM,mBAAmB,GAAG,IAAI,C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MAAM,CAAC,KAAK;qBACvC,QAAQ,CAAC,KAAK,CAAC;qBACf,KAAK,CAAC,SAAS,CAAC;oBACjB,EAAE,IAAI,CAAC,GAAG,CAAC,EAAE,CAChB,CAAC,CAAC,qCAAqC;QAC5C,CAAC,CAAC,CAAC;QACH,IAAI,GAAG,CAAC,OAAO,IAAI,GAAG,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC;YAAE,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC,EAAE,IAAI,CAAC,CAAC;;YAC1G,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,YAAY,EAAE,IAAI,CAAC,CAAC;IACzC,CAAC;CACF"}
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @description This file contains the class Dgram.
|
|
3
|
+
* @file dgram.ts
|
|
4
|
+
* @author Luca Liguori
|
|
5
|
+
* @created 2025-03-22
|
|
6
|
+
* @version 1.0.0
|
|
7
|
+
* @license Apache-2.0
|
|
8
|
+
*
|
|
9
|
+
* Copyright 2025, 2026, 2027 Luca Liguori.
|
|
10
|
+
*
|
|
11
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
12
|
+
* you may not use this file except in compliance with the License.
|
|
13
|
+
* You may obtain a copy of the License at
|
|
14
|
+
*
|
|
15
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
16
|
+
*
|
|
17
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
18
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
19
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
20
|
+
* See the License for the specific language governing permissions and
|
|
21
|
+
* limitations under the License.
|
|
22
|
+
*/
|
|
23
|
+
import dgram from 'node:dgram';
|
|
24
|
+
import EventEmitter from 'node:events';
|
|
25
|
+
import { AddressInfo } from 'node:net';
|
|
26
|
+
import { AnsiLogger } from 'node-ansi-logger';
|
|
27
|
+
/**
|
|
28
|
+
* Represents the Dgram events.
|
|
29
|
+
*/
|
|
30
|
+
interface DgramEvents {
|
|
31
|
+
error: [error: Error];
|
|
32
|
+
close: [];
|
|
33
|
+
connect: [];
|
|
34
|
+
message: [msg: Buffer, rinfo: dgram.RemoteInfo];
|
|
35
|
+
listening: [address: AddressInfo];
|
|
36
|
+
sent: [msg: Buffer, serverAddress: string, serverPort: number];
|
|
37
|
+
ready: [address: AddressInfo];
|
|
38
|
+
bound: [address: AddressInfo];
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* This class implements a dgram socket.
|
|
42
|
+
*/
|
|
43
|
+
export declare class Dgram extends EventEmitter<DgramEvents> {
|
|
44
|
+
log: AnsiLogger;
|
|
45
|
+
socket: dgram.Socket;
|
|
46
|
+
bound: boolean;
|
|
47
|
+
socketType: 'udp4' | 'udp6';
|
|
48
|
+
interfaceName?: string;
|
|
49
|
+
interfaceAddress?: string;
|
|
50
|
+
interfaceNetmask?: string;
|
|
51
|
+
/**
|
|
52
|
+
* Creates an instance of Dgram.
|
|
53
|
+
*
|
|
54
|
+
* @param {string} name - The name of the socket.
|
|
55
|
+
* @param {'udp4' | 'udp6'} socketType - The type of the socket (IPv4 or IPv6).
|
|
56
|
+
* @param {boolean | undefined} reuseAddr - Whether to allow address reuse.
|
|
57
|
+
* @param {string} [interfaceName] - The name of the network interface to bind to.
|
|
58
|
+
* @param {string} [interfaceAddress] - The address of the network interface to bind to.
|
|
59
|
+
*/
|
|
60
|
+
constructor(name: string, socketType: 'udp4' | 'udp6', reuseAddr?: boolean | undefined, interfaceName?: string, interfaceAddress?: string);
|
|
61
|
+
/**
|
|
62
|
+
* Sends a message to the specified server.
|
|
63
|
+
*
|
|
64
|
+
* @param {Buffer} msg - The message buffer to send.
|
|
65
|
+
* @param {string} serverAddress - The IPv4 address of the destination server.
|
|
66
|
+
* @param {number} serverPort - The port of the destination server.
|
|
67
|
+
*/
|
|
68
|
+
send(msg: Buffer, serverAddress: string, serverPort: number): void;
|
|
69
|
+
onError(error: Error): void;
|
|
70
|
+
onClose(): void;
|
|
71
|
+
onConnect(): void;
|
|
72
|
+
onSent(msg: Buffer, serverAddress: string, serverPort: number): void;
|
|
73
|
+
onMessage(msg: Buffer, rinfo: dgram.RemoteInfo): void;
|
|
74
|
+
onListening(address: AddressInfo): void;
|
|
75
|
+
onReady(address: AddressInfo): void;
|
|
76
|
+
/**
|
|
77
|
+
* Retrieves the IPv4 address of the specified network interface or the first external IPv4 interface if no interface is specified.
|
|
78
|
+
* Throws an error if no suitable interface or address is found.
|
|
79
|
+
*
|
|
80
|
+
* @param {string} networkInterface - The name of the network interface to retrieve the IPv4 address from. If not specified, the first external IPv4 interface will be used.
|
|
81
|
+
* @returns {string | undefined} The IPv4 address of the specified network interface or the first external IPv4 interface.
|
|
82
|
+
* @throws {Error} if no suitable interface or address is found.
|
|
83
|
+
*/
|
|
84
|
+
getIpv4InterfaceAddress(networkInterface?: string): string | undefined;
|
|
85
|
+
/**
|
|
86
|
+
* Retrieves the IPv6 address of the specified network interface or the first external IPv6 interface if no interface is specified.
|
|
87
|
+
* Throws an error if no suitable interface or address is found.
|
|
88
|
+
*
|
|
89
|
+
* @param {string} [networkInterface] - The name of the network interface to retrieve the IPv6 address from. If not specified, the first external IPv6 interface will be used.
|
|
90
|
+
* @returns {string | undefined} The IPv6 address of the specified network interface or the first external IPv6 interface.
|
|
91
|
+
* @throws {Error} If no suitable interface or address is found.
|
|
92
|
+
*/
|
|
93
|
+
getIpv6InterfaceAddress(networkInterface?: string): string | undefined;
|
|
94
|
+
/**
|
|
95
|
+
* Retrieves the names of all available network interfaces.
|
|
96
|
+
*
|
|
97
|
+
* @returns {string[]} An array of network interface names.
|
|
98
|
+
*/
|
|
99
|
+
getInterfacesNames(): string[];
|
|
100
|
+
/**
|
|
101
|
+
* Retrieves the scope ID of the first found IPv6 address on the specified network interface or on any interface if none is specified.
|
|
102
|
+
*
|
|
103
|
+
* @param {string} [interfaceName] - The name of the network interface. If not provided, the first found IPv6 address will be used.
|
|
104
|
+
* @returns {string} The scope ID of the first found IPv6 address or an empty string.
|
|
105
|
+
*/
|
|
106
|
+
getIpv6ScopeId(interfaceName?: string): string;
|
|
107
|
+
/**
|
|
108
|
+
* Retrieves the interface name from the scope id of an IPv6 address.
|
|
109
|
+
*
|
|
110
|
+
* @param {number} scopeId - The scope id of the IPv6 address.
|
|
111
|
+
* @returns {string | undefined} The interface name or undefined if not found.
|
|
112
|
+
*/
|
|
113
|
+
getInterfaceNameFromScopeId(scopeId: number): string | undefined;
|
|
114
|
+
/**
|
|
115
|
+
* Retrieves the netmask of the specified interface address.
|
|
116
|
+
*
|
|
117
|
+
* @param {string} interfaceAddress - The interface address for which to retrieve the netmask.
|
|
118
|
+
* @returns {string | undefined} The netmask of the specified interface address or undefined if not found.
|
|
119
|
+
*/
|
|
120
|
+
getNetmask(interfaceAddress: string): string | undefined;
|
|
121
|
+
/**
|
|
122
|
+
* Computes the broadcast address given an IPv4 address and netmask.
|
|
123
|
+
*
|
|
124
|
+
* @param {string | undefined} [ipAddress] - The IPv4 address e.g. "192.168.1.20"
|
|
125
|
+
* @param {string | undefined} [netmask] - The IPv4 netmask e.g. "255.255.255.0"
|
|
126
|
+
* @returns {string | undefined} The computed broadcast address, e.g. "192.168.1.255"
|
|
127
|
+
*/
|
|
128
|
+
getIpv4BroadcastAddress(ipAddress: string | undefined, netmask: string | undefined): string | undefined;
|
|
129
|
+
/**
|
|
130
|
+
* Returns the broadcast IPv6 address.
|
|
131
|
+
*
|
|
132
|
+
* @returns {string} The broadcast IPv6 address, e.g. "ff02::1"
|
|
133
|
+
*/
|
|
134
|
+
getIpv6BroadcastAddress(): string;
|
|
135
|
+
/**
|
|
136
|
+
* Logs all available network interfaces and their details.
|
|
137
|
+
*/
|
|
138
|
+
listNetworkInterfaces(): void;
|
|
139
|
+
}
|
|
140
|
+
export {};
|
|
141
|
+
//# sourceMappingURL=dgram.d.ts.map
|