@camera.ui/transport 0.0.10 → 0.0.12
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/transports/nats.js +14 -0
- package/package.json +3 -3
package/dist/transports/nats.js
CHANGED
|
@@ -7,6 +7,16 @@ var NATS_SPEC = {
|
|
|
7
7
|
phaseGating: true,
|
|
8
8
|
graceMs: 4e3
|
|
9
9
|
};
|
|
10
|
+
function newConnId() {
|
|
11
|
+
const c = globalThis.crypto;
|
|
12
|
+
if (c?.randomUUID) return c.randomUUID();
|
|
13
|
+
if (c?.getRandomValues) {
|
|
14
|
+
const bytes = /* @__PURE__ */ new Uint8Array(16);
|
|
15
|
+
c.getRandomValues(bytes);
|
|
16
|
+
return Array.from(bytes, (b) => b.toString(16).padStart(2, "0")).join("");
|
|
17
|
+
}
|
|
18
|
+
return `${Date.now()}-${Math.random().toString(36).slice(2)}-${Math.random().toString(36).slice(2)}`;
|
|
19
|
+
}
|
|
10
20
|
function createNatsTransport(options = {}) {
|
|
11
21
|
const spec = {
|
|
12
22
|
...NATS_SPEC,
|
|
@@ -30,12 +40,14 @@ function createNatsTransport(options = {}) {
|
|
|
30
40
|
let status = { up: false };
|
|
31
41
|
let statusAbort = null;
|
|
32
42
|
let disposed = false;
|
|
43
|
+
let connId = null;
|
|
33
44
|
function buildServers(target) {
|
|
34
45
|
const url = new URL(target.endpoint.url);
|
|
35
46
|
const wsProtocol = url.protocol === "https:" ? "wss:" : "ws:";
|
|
36
47
|
const port = url.port || (url.protocol === "https:" ? "443" : "80");
|
|
37
48
|
const params = new URLSearchParams({ token: target.tokens.access });
|
|
38
49
|
if (target.tokens.proxySession) params.set("session", target.tokens.proxySession);
|
|
50
|
+
if (connId) params.set("connId", connId);
|
|
39
51
|
return [`${wsProtocol}//${url.hostname}:${port}${proxyPath}?${params.toString()}`];
|
|
40
52
|
}
|
|
41
53
|
function notifyClient() {
|
|
@@ -108,9 +120,11 @@ function createNatsTransport(options = {}) {
|
|
|
108
120
|
proxy = null;
|
|
109
121
|
notifyClient();
|
|
110
122
|
}
|
|
123
|
+
connId = newConnId();
|
|
111
124
|
const next = createRPCClient({
|
|
112
125
|
servers: buildServers(target),
|
|
113
126
|
name: clientName,
|
|
127
|
+
connId,
|
|
114
128
|
auth: {
|
|
115
129
|
user: natsUser,
|
|
116
130
|
password: natsPassword
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@camera.ui/transport",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.12",
|
|
4
4
|
"description": "camera.ui transport layer — framework-agnostic connection kernel, reducer state, pluggable transports (HTTP/WS/Socket.IO/NATS), lifecycle effects and worker bridge",
|
|
5
5
|
"author": "seydx (https://github.com/cameraui/clients)",
|
|
6
6
|
"type": "module",
|
|
@@ -55,8 +55,8 @@
|
|
|
55
55
|
"update": "updates --update ./"
|
|
56
56
|
},
|
|
57
57
|
"dependencies": {
|
|
58
|
-
"@camera.ui/logger": ">=0.0.
|
|
59
|
-
"@camera.ui/rpc": ">=1.0.
|
|
58
|
+
"@camera.ui/logger": ">=0.0.3",
|
|
59
|
+
"@camera.ui/rpc": ">=1.0.5",
|
|
60
60
|
"axios": ">=1.18.1",
|
|
61
61
|
"socket.io-client": ">=4.8.3"
|
|
62
62
|
},
|