unetjs 5.0.1 → 6.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -7,13 +7,13 @@ The library contains helper methods, commonly used [Messages](https://fjage.read
7
7
  ## Installation
8
8
 
9
9
  ```sh
10
- $ npm install unetjs
10
+ $ pnpm install unetjs
11
11
  ...
12
12
  ```
13
13
 
14
14
  ## Documentation
15
15
 
16
- The API documentation of the latest version of unet.js is published at [https://github.com/org-arl/unet-contrib/tree/master/unetsocket/js/docs](https://github.com/org-arl/unet-contrib/tree/master/unetsocket/js/docs)
16
+ The API documentation of the latest version of unet.js is published at [https://github.com/org-arl/unetsockets/tree/master/js/docs](https://github.com/org-arl/unetsockets/tree/master/js/docs)
17
17
 
18
18
  ## Versions
19
19
 
@@ -65,47 +65,15 @@ The UnetSocket API is a high-level API exposed by UnetStack to allow users to co
65
65
 
66
66
  The JavaScript version of the UnetSocket API allows a user to connect to a node in an Unet from a browser/Node.JS-based application and communicate with other nodes in the Unet. The Datagrams received on those nodes could be consumed by other instances of the UnetSocket, either directly on the node, or on a remote [Gateway](https://fjage.readthedocs.io/en/latest/remote.html#interacting-with-agents-using-a-gateway) connected to that node.
67
67
 
68
- ### Caching Parameter Responses
68
+ Socket-level transmission metadata can be configured once and applied to subsequent sends using methods such as `setTTL()`, `setPriority()`, `setReliability()`, `setRoute()`, `setMimeType()`, `setRemoteRecipient()`, `setMailbox()`, and `setMessageClass()`. A specific service provider may also be forced with `setServiceProvider()`.
69
69
 
70
- The UnetSocket API allows a user to cache responses to parameter requests. This is useful in a scenario where the parameters aren't changing very often, and the user wants to reduce the round trip time for parameter requests.
70
+ `send()` now supports three send modes via `setSendMode()`:
71
71
 
72
- > This behaviour used to be enabled by default in unetsocket.js v2.0.0 till v2.0.10. From v3.0.0 onwards, this behaviour is **disabled** by default but a available as an option.
72
+ - `UnetSocket.NON_BLOCKING`: returns `true` once the request has been accepted for sending.
73
+ - `UnetSocket.SEMI_BLOCKING` (default): waits for an `AGREE`, and if reliability is enabled, also waits for a delivery/success notification.
74
+ - `UnetSocket.BLOCKING`: waits for an `AGREE` followed by a transmission, delivery, or failure notification.
73
75
 
74
- You can use the `CachingGateway` class instead of the `Gateway` class to enable this behaviour.
75
-
76
- UnetSocket API acheives this using two mechanism, firstly, it can request ALL of the parameters from an Agent instead of just one, and then cache the responses. This is called the `greedy` mode. The greedy mode is enabled by default but can be disabled by setting the `greedy` property to `false` in the `CachingAgentID` constructor.
77
-
78
- Secondly, the UnetSocket API caches the responses to parameter requests for a limited time. If the user requests the same parameter again, the UnetSocket will return the cached response. The time to cache a response is set by the `cacheTime` property in the `CachingAgentID` constructor.
79
-
80
- > unetsockets.js v5.0.0 and beyond the UnetSocket API was changed to remove the optional parameter `caching` from the `agentForService`, `agentsForService` and `agent` methods. This was done to simplify the API and avoid confusion. The caching behaviour is now enabled by using a different class, `CachingGateway` instead of `Gateway`. The `CachingGateway` class extends the `Gateway` class and adds the caching behaviour.
81
-
82
- ```js
83
- import {UnetMessages, CachingGateway} from 'unetjs'
84
- let gw = new CachingGateway({...});
85
- let nodeinfo = await gw.agentForService(Services.NODE_INFO); // returns a CachingAgentID
86
- let cLoc = nodeinfo.get('location'); // this will request all the Parameters from the Agent, and cache the responses.
87
- ...
88
- cLoc = nodeinfo.get('location', maxage=5000); // this will return the cached response if it was called within 5000ms of the original request.
89
- ...
90
- cLoc = nodeinfo.get('location', maxage=0); // this will force the Gateway to request the parameter again.
91
- ```
92
-
93
- ```js
94
- import {UnetMessages, CachingGateway} from 'unetjs'
95
- let gw = new CachingGateway({...});
96
- let nodeinfo = await gw.agentForService(Services.NODE_INFO); // returns a CachingAgentID
97
- let nonCachingNodeInfo = await gw.agentForService(Services.NODE_INFO, false); // returns an AgentID without caching (original fjage.js functionality).
98
- let cLoc = nonCachingNodeInfo.get('location'); // this will request the `location` parameter from the Agent.
99
- ...
100
- cLoc = nonCachingNodeInfo.get('location'); // this will request the `location` parameter from the Agent again.
101
-
102
- let nonGreedyNodeInfo = await gw.agentForService(Services.NODE_INFO, true, false); // returns an CachingAgentID that's not greedy.
103
- let cLoc = nonGreedyNodeInfo.get('location'); // this will request the `location` parameter from the Agent.
104
- ...
105
- cLoc = nonCachingNodeInfo.get('location'); // this will request the `location` parameter from the cache.
106
- ...
107
- let cLoc = nonGreedyNodeInfo.get('heading'); // this will request the `heading` parameter from the Agent.
108
- ```
76
+ Passing a `DatagramReq` directly to `send()` is still supported for compatibility, but it is deprecated. Prefer setting socket defaults and calling `send(data, to, protocol)` instead.
109
77
 
110
78
  ### Importing/Modules
111
79