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 +8 -40
- package/dist/cjs/unet.cjs +501 -296
- package/dist/esm/unet.js +501 -295
- package/dist/unetjs.js +500 -295
- package/dist/unetjs.js.map +1 -1
- package/dist/unetjs.min.js +1 -1
- package/dist/unetjs.min.js.map +1 -1
- package/package.json +20 -19
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
|
-
$
|
|
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/
|
|
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
|
-
|
|
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
|
-
|
|
70
|
+
`send()` now supports three send modes via `setSendMode()`:
|
|
71
71
|
|
|
72
|
-
|
|
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
|
-
|
|
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
|
|