@rstreamlabs/react 2.1.1 → 2.1.4
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 +39 -56
- package/dist/{chunk-AHLVBJB3.mjs → chunk-MAO57HME.mjs} +1 -1
- package/dist/{chunk-L4AWANNU.mjs → chunk-TUNL7LFU.mjs} +1 -1
- package/dist/hooks/index.js +2 -2
- package/dist/hooks/index.mjs +1 -1
- package/dist/index.js +2 -2
- package/dist/index.mjs +2 -2
- package/dist/providers/index.js +2 -2
- package/dist/providers/index.mjs +2 -2
- package/package.json +13 -13
package/README.md
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
# `@rstreamlabs/react`
|
|
2
2
|
|
|
3
|
-
React hooks, providers
|
|
3
|
+
rstream connects services and devices through outbound tunnels and exposes their live state through engine APIs. This package brings that state and remote terminal access into a React application through hooks, providers and components.
|
|
4
4
|
|
|
5
5
|
Use this package in browser applications and dashboards that need live tunnel
|
|
6
6
|
state or embedded WebTTY sessions. It builds on
|
|
7
|
-
[`@rstreamlabs/tunnels`](
|
|
8
|
-
[`@rstreamlabs/webtty`](
|
|
7
|
+
[`@rstreamlabs/tunnels`](https://github.com/rstreamlabs/rstream-js/blob/main/packages/tunnels/README.md) for watch streams and
|
|
8
|
+
[`@rstreamlabs/webtty`](https://github.com/rstreamlabs/rstream-js/blob/main/packages/webtty/README.md) for the browser-side WebTTY
|
|
9
9
|
protocol.
|
|
10
10
|
|
|
11
11
|
## Install
|
|
@@ -14,7 +14,7 @@ protocol.
|
|
|
14
14
|
npm install @rstreamlabs/react
|
|
15
15
|
```
|
|
16
16
|
|
|
17
|
-
The package
|
|
17
|
+
The package requires React 19.2.8 or newer within React 19. It uses the application's React instance; React 18, 19.0 and 19.1 are not supported.
|
|
18
18
|
|
|
19
19
|
## Exports
|
|
20
20
|
|
|
@@ -27,92 +27,75 @@ The package has a peer dependency on React 18 or 19.
|
|
|
27
27
|
|
|
28
28
|
## Live Tunnel State
|
|
29
29
|
|
|
30
|
-
|
|
31
|
-
|
|
30
|
+
Use [the browser token route](https://github.com/rstreamlabs/rstream-js/blob/main/docs/browser/000-watch.md#connect-a-browser)
|
|
31
|
+
to get an authorized Engine and short-lived watch token. For this example,
|
|
32
|
+
install `zod` alongside the React SDK. Pass in the Engine returned by the
|
|
33
|
+
initial bootstrap. Use the token callback for subsequent connections.
|
|
32
34
|
|
|
33
35
|
```tsx
|
|
34
36
|
"use client";
|
|
35
37
|
|
|
36
38
|
import { useRstream } from "@rstreamlabs/react/hooks";
|
|
39
|
+
import { useCallback } from "react";
|
|
40
|
+
import { z } from "zod";
|
|
37
41
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
42
|
+
const credentials = z.object({ token: z.string(), engine: z.string() });
|
|
43
|
+
|
|
44
|
+
async function watchToken(engine: string) {
|
|
45
|
+
const response = await fetch("/api/rstream/watch", {
|
|
46
|
+
credentials: "same-origin",
|
|
41
47
|
cache: "no-store",
|
|
42
48
|
});
|
|
43
|
-
if (!response.ok)
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
return token;
|
|
49
|
+
if (!response.ok) throw new Error("Watch access was refused");
|
|
50
|
+
const issued = credentials.parse(await response.json());
|
|
51
|
+
if (issued.engine !== engine) throw new Error("The selected Engine changed");
|
|
52
|
+
return issued.token;
|
|
48
53
|
}
|
|
49
54
|
|
|
50
|
-
export function TunnelInventory() {
|
|
55
|
+
export function TunnelInventory({ engine }: { engine: string }) {
|
|
56
|
+
const auth = useCallback(() => watchToken(engine), [engine]);
|
|
51
57
|
const { state, error, tunnels } = useRstream({
|
|
52
|
-
auth
|
|
53
|
-
engine
|
|
58
|
+
auth,
|
|
59
|
+
engine,
|
|
54
60
|
transport: "sse",
|
|
55
61
|
});
|
|
56
62
|
|
|
57
63
|
if (error) return <p>{error.message}</p>;
|
|
58
64
|
return (
|
|
59
65
|
<ul data-state={state}>
|
|
60
|
-
{tunnels
|
|
61
|
-
.
|
|
62
|
-
|
|
63
|
-
<li key={tunnel.id}>{tunnel.name ?? tunnel.id}</li>
|
|
64
|
-
))}
|
|
66
|
+
{tunnels.flatMap((tunnel) =>
|
|
67
|
+
tunnel.id ? [<li key={tunnel.id}>{tunnel.name ?? tunnel.id}</li>] : [],
|
|
68
|
+
)}
|
|
65
69
|
</ul>
|
|
66
70
|
);
|
|
67
71
|
}
|
|
68
72
|
```
|
|
69
73
|
|
|
70
|
-
The hook reconnects
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
be absent under field selection. Select `id` for keyed, actionable rows, or
|
|
75
|
-
render anonymous projections without assuming an identifier exists. A denied
|
|
76
|
-
category is empty and does not prevent the other category from updating.
|
|
77
|
-
Every incoming snapshot replaces both arrays. Previously visible data is
|
|
78
|
-
hidden while reconnecting or switching authentication.
|
|
74
|
+
The hook reconnects and obtains fresh credentials. Use a stable callback
|
|
75
|
+
for the same Engine and remount the view when the selected project changes.
|
|
76
|
+
Watch items are field projections. Select `id` for rows the viewer can
|
|
77
|
+
act on. Each new snapshot replaces the current view.
|
|
79
78
|
|
|
80
79
|
## Shared Provider
|
|
81
80
|
|
|
82
|
-
Use `RstreamProvider` when several components
|
|
81
|
+
Use `RstreamProvider` when several components share one subscription.
|
|
82
|
+
Pass the same options and read the view with `useRstreamContext()`.
|
|
83
83
|
|
|
84
84
|
```tsx
|
|
85
|
-
"use client";
|
|
86
|
-
|
|
87
85
|
import { RstreamProvider } from "@rstreamlabs/react/providers";
|
|
88
86
|
import { useRstreamContext } from "@rstreamlabs/react/providers";
|
|
87
|
+
import { useCallback } from "react";
|
|
89
88
|
|
|
90
|
-
|
|
91
|
-
const response = await fetch("/api/rstream/watch-token", {
|
|
92
|
-
method: "POST",
|
|
93
|
-
cache: "no-store",
|
|
94
|
-
});
|
|
95
|
-
if (!response.ok) {
|
|
96
|
-
throw new Error("Failed to create watch token.");
|
|
97
|
-
}
|
|
98
|
-
const { token } = await response.json();
|
|
99
|
-
return token;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
function TunnelsTable() {
|
|
89
|
+
function TunnelCount() {
|
|
103
90
|
const { tunnels } = useRstreamContext();
|
|
104
|
-
return <
|
|
91
|
+
return <p>{tunnels.length} tunnels</p>;
|
|
105
92
|
}
|
|
106
93
|
|
|
107
|
-
export function Dashboard() {
|
|
94
|
+
export function Dashboard({ engine }: { engine: string }) {
|
|
95
|
+
const auth = useCallback(() => watchToken(engine), [engine]);
|
|
108
96
|
return (
|
|
109
|
-
<RstreamProvider
|
|
110
|
-
|
|
111
|
-
auth: createWatchToken,
|
|
112
|
-
engine: "project-endpoint.cluster.example.rstream.test:443",
|
|
113
|
-
}}
|
|
114
|
-
>
|
|
115
|
-
<TunnelsTable />
|
|
97
|
+
<RstreamProvider options={{ engine, auth }}>
|
|
98
|
+
<TunnelCount />
|
|
116
99
|
</RstreamProvider>
|
|
117
100
|
);
|
|
118
101
|
}
|
package/dist/hooks/index.js
CHANGED
|
@@ -35,7 +35,7 @@ __export(hooks_exports, {
|
|
|
35
35
|
module.exports = __toCommonJS(hooks_exports);
|
|
36
36
|
|
|
37
37
|
// src/hooks/use-rstream.ts
|
|
38
|
-
var
|
|
38
|
+
var import_watch = require("@rstreamlabs/tunnels/watch");
|
|
39
39
|
var React = __toESM(require("react"));
|
|
40
40
|
function hasAuth(options) {
|
|
41
41
|
return !!options && !!options.auth;
|
|
@@ -100,7 +100,7 @@ function useRstream(options) {
|
|
|
100
100
|
const watchOptions = getWatchOptions();
|
|
101
101
|
if (!watchOptions) return;
|
|
102
102
|
setState("connecting");
|
|
103
|
-
runtime.watch = new
|
|
103
|
+
runtime.watch = new import_watch.Watch(watchOptions, {
|
|
104
104
|
onEvent: (event) => {
|
|
105
105
|
if (!runtime.active) return;
|
|
106
106
|
if (event.type === "state.initial") {
|
package/dist/hooks/index.mjs
CHANGED
package/dist/index.js
CHANGED
|
@@ -280,7 +280,7 @@ Process exited with code ${code}.`);
|
|
|
280
280
|
}
|
|
281
281
|
|
|
282
282
|
// src/hooks/use-rstream.ts
|
|
283
|
-
var
|
|
283
|
+
var import_watch = require("@rstreamlabs/tunnels/watch");
|
|
284
284
|
var React2 = __toESM(require("react"));
|
|
285
285
|
function hasAuth(options) {
|
|
286
286
|
return !!options && !!options.auth;
|
|
@@ -345,7 +345,7 @@ function useRstream(options) {
|
|
|
345
345
|
const watchOptions = getWatchOptions();
|
|
346
346
|
if (!watchOptions) return;
|
|
347
347
|
setState("connecting");
|
|
348
|
-
runtime.watch = new
|
|
348
|
+
runtime.watch = new import_watch.Watch(watchOptions, {
|
|
349
349
|
onEvent: (event) => {
|
|
350
350
|
if (!runtime.active) return;
|
|
351
351
|
if (event.type === "state.initial") {
|
package/dist/index.mjs
CHANGED
|
@@ -5,10 +5,10 @@ import "./chunk-2JFL7TS5.mjs";
|
|
|
5
5
|
import {
|
|
6
6
|
RstreamProvider,
|
|
7
7
|
useRstreamContext
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-TUNL7LFU.mjs";
|
|
9
9
|
import {
|
|
10
10
|
useRstream
|
|
11
|
-
} from "./chunk-
|
|
11
|
+
} from "./chunk-MAO57HME.mjs";
|
|
12
12
|
export {
|
|
13
13
|
RstreamProvider,
|
|
14
14
|
WebTTYTerminal,
|
package/dist/providers/index.js
CHANGED
|
@@ -36,7 +36,7 @@ __export(providers_exports, {
|
|
|
36
36
|
module.exports = __toCommonJS(providers_exports);
|
|
37
37
|
|
|
38
38
|
// src/hooks/use-rstream.ts
|
|
39
|
-
var
|
|
39
|
+
var import_watch = require("@rstreamlabs/tunnels/watch");
|
|
40
40
|
var React = __toESM(require("react"));
|
|
41
41
|
function hasAuth(options) {
|
|
42
42
|
return !!options && !!options.auth;
|
|
@@ -101,7 +101,7 @@ function useRstream(options) {
|
|
|
101
101
|
const watchOptions = getWatchOptions();
|
|
102
102
|
if (!watchOptions) return;
|
|
103
103
|
setState("connecting");
|
|
104
|
-
runtime.watch = new
|
|
104
|
+
runtime.watch = new import_watch.Watch(watchOptions, {
|
|
105
105
|
onEvent: (event) => {
|
|
106
106
|
if (!runtime.active) return;
|
|
107
107
|
if (event.type === "state.initial") {
|
package/dist/providers/index.mjs
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rstreamlabs/react",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.4",
|
|
4
4
|
"description": "React hooks and components for building rstream-enabled UIs.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -46,30 +46,30 @@
|
|
|
46
46
|
"test": "node --test test/*.test.cjs"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
|
-
"@turbo/gen": "^2.
|
|
50
|
-
"@types/node": "^26.
|
|
51
|
-
"@types/react": "19.
|
|
52
|
-
"@types/react-dom": "19.
|
|
49
|
+
"@turbo/gen": "^2.11.11",
|
|
50
|
+
"@types/node": "^26.6.6",
|
|
51
|
+
"@types/react": "19.3.0",
|
|
52
|
+
"@types/react-dom": "19.3.0",
|
|
53
53
|
"eslint-config": "*",
|
|
54
54
|
"tsup": "^8.5.1",
|
|
55
55
|
"typescript": "6.0.3",
|
|
56
|
-
"typescript-config": "*"
|
|
56
|
+
"typescript-config": "*",
|
|
57
|
+
"react": "^19.3.1",
|
|
58
|
+
"react-dom": "^19.3.1"
|
|
57
59
|
},
|
|
58
60
|
"dependencies": {
|
|
59
|
-
"@rstreamlabs/rstream": "3.
|
|
60
|
-
"@rstreamlabs/tunnels": "4.
|
|
61
|
-
"@rstreamlabs/webtty": "1.12.
|
|
61
|
+
"@rstreamlabs/rstream": "3.12.2",
|
|
62
|
+
"@rstreamlabs/tunnels": "4.1.2",
|
|
63
|
+
"@rstreamlabs/webtty": "1.12.3",
|
|
62
64
|
"@xterm/addon-fit": "^0.11.0",
|
|
63
65
|
"@xterm/addon-unicode11": "^0.9.0",
|
|
64
66
|
"@xterm/addon-web-links": "^0.12.0",
|
|
65
67
|
"@xterm/addon-webgl": "^0.19.0",
|
|
66
|
-
"@xterm/xterm": "^6.0.0"
|
|
67
|
-
"react": "^18.0 || ^19.0",
|
|
68
|
-
"react-dom": "^19.2.8"
|
|
68
|
+
"@xterm/xterm": "^6.0.0"
|
|
69
69
|
},
|
|
70
70
|
"peerDependencies": {
|
|
71
71
|
"@types/react": "*",
|
|
72
|
-
"react": "^
|
|
72
|
+
"react": "^19.2.8"
|
|
73
73
|
},
|
|
74
74
|
"peerDependenciesMeta": {
|
|
75
75
|
"@types/react": {
|