@rstreamlabs/react 1.7.14 → 1.7.15

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.
Files changed (2) hide show
  1. package/README.md +124 -1
  2. package/package.json +3 -3
package/README.md CHANGED
@@ -1,3 +1,126 @@
1
1
  # `@rstreamlabs/react`
2
2
 
3
- React hooks and components for building rstream-enabled UIs.
3
+ React hooks, providers, and terminal components for rstream-enabled UIs.
4
+
5
+ Use this package in browser applications and dashboards that need live tunnel
6
+ state or embedded WebTTY sessions. It builds on
7
+ [`@rstreamlabs/tunnels`](../tunnels/README.md) for watch streams and
8
+ [`@rstreamlabs/webtty`](../webtty/README.md) for the browser-side WebTTY
9
+ protocol.
10
+
11
+ ## Install
12
+
13
+ ```sh
14
+ npm install @rstreamlabs/react
15
+ ```
16
+
17
+ The package has a peer dependency on React 18 or 19.
18
+
19
+ ## Exports
20
+
21
+ | Import path | Contents |
22
+ | --- | --- |
23
+ | `@rstreamlabs/react` | Hooks, providers, and components. |
24
+ | `@rstreamlabs/react/hooks` | `useRstream`. |
25
+ | `@rstreamlabs/react/providers` | `RstreamProvider`, `useRstreamContext`. |
26
+ | `@rstreamlabs/react/components` | `WebTTYTerminal`. |
27
+
28
+ ## Live Tunnel State
29
+
30
+ `useRstream()` wraps the engine watch stream and keeps tunnel/client arrays in
31
+ React state.
32
+
33
+ ```tsx
34
+ "use client";
35
+
36
+ import { useRstream } from "@rstreamlabs/react/hooks";
37
+
38
+ export function TunnelInventory({ token }: { token: string }) {
39
+ const { state, error, tunnels } = useRstream({
40
+ auth: token,
41
+ engine: "project-endpoint.cluster.example.rstream.test:443",
42
+ transport: "sse",
43
+ });
44
+
45
+ if (error) return <p>{error.message}</p>;
46
+ return (
47
+ <ul data-state={state}>
48
+ {tunnels.map((tunnel) => (
49
+ <li key={tunnel.id}>{tunnel.name ?? tunnel.id}</li>
50
+ ))}
51
+ </ul>
52
+ );
53
+ }
54
+ ```
55
+
56
+ The hook reconnects automatically and clears state when authentication is not
57
+ configured.
58
+
59
+ ## Shared Provider
60
+
61
+ Use `RstreamProvider` when several components need the same watch stream.
62
+
63
+ ```tsx
64
+ "use client";
65
+
66
+ import { RstreamProvider } from "@rstreamlabs/react/providers";
67
+ import { useRstreamContext } from "@rstreamlabs/react/providers";
68
+
69
+ function TunnelsTable() {
70
+ const { tunnels } = useRstreamContext();
71
+ return <pre>{JSON.stringify(tunnels, null, 2)}</pre>;
72
+ }
73
+
74
+ export function Dashboard({ token }: { token: string }) {
75
+ return (
76
+ <RstreamProvider
77
+ options={{
78
+ auth: token,
79
+ engine: "project-endpoint.cluster.example.rstream.test:443",
80
+ }}
81
+ >
82
+ <TunnelsTable />
83
+ </RstreamProvider>
84
+ );
85
+ }
86
+ ```
87
+
88
+ ## WebTTY Terminal
89
+
90
+ `WebTTYTerminal` binds a WebTTY WebSocket endpoint to an xterm.js terminal. Use
91
+ it after a backend has issued a short-lived token scoped to the terminal
92
+ session.
93
+
94
+ ```tsx
95
+ "use client";
96
+
97
+ import { WebTTYTerminal } from "@rstreamlabs/react/components";
98
+
99
+ export function Terminal({ token }: { token: string }) {
100
+ return (
101
+ <WebTTYTerminal
102
+ url={`wss://host.example.t.rstream.io?rstream.token=${encodeURIComponent(token)}`}
103
+ terminalOptions={{ cursorBlink: true }}
104
+ onComplete={(exitCode) => console.log("completed", exitCode)}
105
+ onError={(message) => console.error(message)}
106
+ />
107
+ );
108
+ }
109
+ ```
110
+
111
+ The component loads xterm.js add-ons for fit, Unicode, web links, and WebGL
112
+ rendering. It forwards WebTTY stdout/stderr events and keeps terminal resize
113
+ state synchronized with the remote session.
114
+
115
+ ## Security Notes
116
+
117
+ Browser applications should receive short-lived tokens from a backend endpoint.
118
+ Do not embed personal access tokens or application client secrets in React code.
119
+
120
+ ## Development
121
+
122
+ ```sh
123
+ npm --workspace @rstreamlabs/react run type-check
124
+ npm --workspace @rstreamlabs/react run lint
125
+ npm --workspace @rstreamlabs/react run build
126
+ ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rstreamlabs/react",
3
- "version": "1.7.14",
3
+ "version": "1.7.15",
4
4
  "description": "React hooks and components for building rstream-enabled UIs.",
5
5
  "license": "Apache-2.0",
6
6
  "main": "./dist/index.js",
@@ -50,8 +50,8 @@
50
50
  "typescript": "5.9.3"
51
51
  },
52
52
  "dependencies": {
53
- "@rstreamlabs/tunnels": "1.0.9",
54
- "@rstreamlabs/webtty": "1.6.4",
53
+ "@rstreamlabs/tunnels": "1.0.10",
54
+ "@rstreamlabs/webtty": "1.6.5",
55
55
  "@xterm/addon-fit": "^0.11.0",
56
56
  "@xterm/addon-unicode11": "^0.9.0",
57
57
  "@xterm/addon-web-links": "^0.12.0",