@rstreamlabs/react 1.4.0 → 1.6.1

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.
@@ -0,0 +1,191 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/providers/index.ts
31
+ var providers_exports = {};
32
+ __export(providers_exports, {
33
+ RstreamProvider: () => RstreamProvider,
34
+ useRstreamContext: () => useRstreamContext
35
+ });
36
+ module.exports = __toCommonJS(providers_exports);
37
+
38
+ // src/hooks/use-rstream.ts
39
+ var import_rstream = require("@rstreamlabs/rstream");
40
+ var React = __toESM(require("react"));
41
+ function hasAuth(options) {
42
+ return !!options && !!options.auth;
43
+ }
44
+ function useRstream(options) {
45
+ const [state, setState] = React.useState("disconnected");
46
+ const [error, setError] = React.useState(null);
47
+ const { reconnectTimeout = 1e3, errorTimeout = 5e3 } = options || {};
48
+ const [clients, setClients] = React.useState([]);
49
+ const [tunnels, setTunnels] = React.useState([]);
50
+ React.useEffect(() => {
51
+ if (!hasAuth(options)) return;
52
+ let active = true;
53
+ let watch = null;
54
+ let timeout = null;
55
+ const schedule = () => {
56
+ if (!active) return;
57
+ if (timeout) return;
58
+ setState("connecting");
59
+ timeout = setTimeout(() => {
60
+ if (!active) return;
61
+ timeout = null;
62
+ run();
63
+ }, reconnectTimeout);
64
+ };
65
+ const run = async () => {
66
+ if (!hasAuth(options)) return;
67
+ setState("connecting");
68
+ watch = new import_rstream.Watch(options, {
69
+ onEvent: (event) => {
70
+ if (!active) return;
71
+ if (event.type.startsWith("client")) {
72
+ setClients((previous) => {
73
+ if (event.type === "client.created") {
74
+ return [...previous, event.object];
75
+ } else if (event.type === "client.updated") {
76
+ return previous.map((client) => {
77
+ if (client.id === event.object.id) {
78
+ return event.object;
79
+ }
80
+ return client;
81
+ });
82
+ } else if (event.type === "client.deleted") {
83
+ return previous.filter(
84
+ (client) => client.id !== event.object.id
85
+ );
86
+ }
87
+ return previous;
88
+ });
89
+ } else if (event.type.startsWith("tunnel")) {
90
+ setTunnels((previous) => {
91
+ if (event.type === "tunnel.created") {
92
+ return [...previous, event.object];
93
+ } else if (event.type === "tunnel.updated") {
94
+ return previous.map((tunnel) => {
95
+ if (tunnel.id === event.object.id) {
96
+ return event.object;
97
+ }
98
+ return tunnel;
99
+ });
100
+ } else if (event.type === "tunnel.deleted") {
101
+ return previous.filter(
102
+ (tunnel) => tunnel.id !== event.object.id
103
+ );
104
+ }
105
+ return previous;
106
+ });
107
+ }
108
+ },
109
+ onConnect: () => {
110
+ if (!active) return;
111
+ setState("connected");
112
+ },
113
+ onClose: () => {
114
+ if (!active) return;
115
+ watch = null;
116
+ schedule();
117
+ }
118
+ });
119
+ try {
120
+ await watch.connect();
121
+ } catch {
122
+ schedule();
123
+ }
124
+ };
125
+ run();
126
+ return () => {
127
+ active = false;
128
+ if (watch) {
129
+ watch.disconnect();
130
+ watch = null;
131
+ }
132
+ if (timeout) {
133
+ clearTimeout(timeout);
134
+ timeout = null;
135
+ }
136
+ };
137
+ }, [options, reconnectTimeout]);
138
+ React.useEffect(() => {
139
+ if (options?.auth) {
140
+ if (error && error.type === "danger") return;
141
+ if (state !== "connected") {
142
+ const timeout = setTimeout(() => {
143
+ setError({
144
+ message: "Failed to fetch rstream ressources. Retrying...",
145
+ type: "warning"
146
+ });
147
+ }, errorTimeout);
148
+ return () => {
149
+ clearTimeout(timeout);
150
+ };
151
+ } else if (state === "connected") {
152
+ setError(null);
153
+ }
154
+ } else {
155
+ setError(null);
156
+ }
157
+ }, [options, state, error, errorTimeout]);
158
+ React.useEffect(() => {
159
+ if (options?.auth === void 0 || state !== "connected") {
160
+ setClients([]);
161
+ setTunnels([]);
162
+ }
163
+ }, [options, state]);
164
+ return { error, tunnels, clients };
165
+ }
166
+
167
+ // src/providers/rstream.tsx
168
+ var React2 = __toESM(require("react"));
169
+ var import_jsx_runtime = require("react/jsx-runtime");
170
+ var RstreamContext = React2.createContext(
171
+ void 0
172
+ );
173
+ function useRstreamContext() {
174
+ const ctx = React2.useContext(RstreamContext);
175
+ if (!ctx)
176
+ throw new Error("useRstreamContext must be used within a RstreamProvider");
177
+ return ctx;
178
+ }
179
+ function RstreamProvider({ options, children }) {
180
+ const { error, tunnels, clients } = useRstream(options);
181
+ const value = React2.useMemo(
182
+ () => ({ error, tunnels, clients }),
183
+ [error, tunnels, clients]
184
+ );
185
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(RstreamContext.Provider, { value, children });
186
+ }
187
+ // Annotate the CommonJS export names for ESM import in node:
188
+ 0 && (module.exports = {
189
+ RstreamProvider,
190
+ useRstreamContext
191
+ });
@@ -0,0 +1,9 @@
1
+ import {
2
+ RstreamProvider,
3
+ useRstreamContext
4
+ } from "../chunk-TAYPWKHF.mjs";
5
+ import "../chunk-2WDUPTYY.mjs";
6
+ export {
7
+ RstreamProvider,
8
+ useRstreamContext
9
+ };
package/package.json CHANGED
@@ -1,11 +1,33 @@
1
1
  {
2
2
  "name": "@rstreamlabs/react",
3
- "version": "1.4.0",
3
+ "version": "1.6.1",
4
4
  "description": "React hooks and components for building rstream-enabled UIs.",
5
5
  "license": "Apache-2.0",
6
6
  "main": "./dist/index.js",
7
7
  "module": "./dist/index.mjs",
8
8
  "types": "./dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./dist/index.d.ts",
12
+ "import": "./dist/index.mjs",
13
+ "require": "./dist/index.js"
14
+ },
15
+ "./components": {
16
+ "types": "./dist/components/index.d.ts",
17
+ "import": "./dist/components/index.mjs",
18
+ "require": "./dist/components/index.js"
19
+ },
20
+ "./hooks": {
21
+ "types": "./dist/hooks/index.d.ts",
22
+ "import": "./dist/hooks/index.mjs",
23
+ "require": "./dist/hooks/index.js"
24
+ },
25
+ "./providers": {
26
+ "types": "./dist/providers/index.d.ts",
27
+ "import": "./dist/providers/index.mjs",
28
+ "require": "./dist/providers/index.js"
29
+ }
30
+ },
9
31
  "files": [
10
32
  "dist",
11
33
  "README.md"
@@ -18,24 +40,25 @@
18
40
  "type-check": "tsc --noEmit"
19
41
  },
20
42
  "devDependencies": {
21
- "@turbo/gen": "^2.5.8",
22
- "@types/node": "^24.6.0",
23
- "@types/react-dom": "19.1.9",
24
- "@types/react": "19.1.16",
43
+ "@turbo/gen": "^2.7.4",
44
+ "@types/node": "^25.0.9",
45
+ "@types/react-dom": "19.2.3",
46
+ "@types/react": "19.2.8",
25
47
  "eslint-config": "*",
48
+ "tsup": "^8.5.1",
26
49
  "typescript-config": "*",
27
- "typescript": "5.9.2"
50
+ "typescript": "5.9.3"
28
51
  },
29
52
  "dependencies": {
30
- "@rstreamlabs/rstream": "1.4.0",
31
- "@rstreamlabs/webtty": "1.4.0",
32
- "@xterm/addon-fit": "^0.10.0",
33
- "@xterm/addon-unicode11": "^0.8.0",
34
- "@xterm/addon-web-links": "^0.11.0",
35
- "@xterm/addon-webgl": "^0.18.0",
36
- "@xterm/xterm": "^5.5.0",
37
- "react": "^19.1.1",
38
- "react-dom": "^19.1.1"
53
+ "@rstreamlabs/rstream": "1.6.1",
54
+ "@rstreamlabs/webtty": "1.6.1",
55
+ "@xterm/addon-fit": "^0.11.0",
56
+ "@xterm/addon-unicode11": "^0.9.0",
57
+ "@xterm/addon-web-links": "^0.12.0",
58
+ "@xterm/addon-webgl": "^0.19.0",
59
+ "@xterm/xterm": "^6.0.0",
60
+ "react": "^19.2.3",
61
+ "react-dom": "^19.2.3"
39
62
  },
40
63
  "peerDependencies": {
41
64
  "@types/react": "*",