@camera.ui/transport 0.0.11 → 0.0.13

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.
@@ -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
@@ -165,6 +179,10 @@ function createNatsTransport(options = {}) {
165
179
  proxy.setServers(newServers);
166
180
  }
167
181
  function health() {
182
+ if (status.up && proxy?.isStale) return {
183
+ up: false,
184
+ lastError: "staleConnection"
185
+ };
168
186
  return status;
169
187
  }
170
188
  function on(event, handler) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@camera.ui/transport",
3
- "version": "0.0.11",
3
+ "version": "0.0.13",
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",
@@ -56,7 +56,7 @@
56
56
  },
57
57
  "dependencies": {
58
58
  "@camera.ui/logger": ">=0.0.3",
59
- "@camera.ui/rpc": ">=1.0.4",
59
+ "@camera.ui/rpc": ">=1.0.6",
60
60
  "axios": ">=1.18.1",
61
61
  "socket.io-client": ">=4.8.3"
62
62
  },