@rstreamlabs/react 1.7.15 → 1.7.17
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 -12
- package/package.json +8 -2
package/README.md
CHANGED
|
@@ -18,12 +18,12 @@ The package has a peer dependency on React 18 or 19.
|
|
|
18
18
|
|
|
19
19
|
## Exports
|
|
20
20
|
|
|
21
|
-
| Import path
|
|
22
|
-
|
|
|
23
|
-
| `@rstreamlabs/react`
|
|
24
|
-
| `@rstreamlabs/react/hooks`
|
|
25
|
-
| `@rstreamlabs/react/providers`
|
|
26
|
-
| `@rstreamlabs/react/components` | `WebTTYTerminal`.
|
|
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
27
|
|
|
28
28
|
## Live Tunnel State
|
|
29
29
|
|
|
@@ -35,9 +35,21 @@ React state.
|
|
|
35
35
|
|
|
36
36
|
import { useRstream } from "@rstreamlabs/react/hooks";
|
|
37
37
|
|
|
38
|
-
|
|
38
|
+
async function createWatchToken() {
|
|
39
|
+
const response = await fetch("/api/rstream/watch-token", {
|
|
40
|
+
method: "POST",
|
|
41
|
+
cache: "no-store",
|
|
42
|
+
});
|
|
43
|
+
if (!response.ok) {
|
|
44
|
+
throw new Error("Failed to create watch token.");
|
|
45
|
+
}
|
|
46
|
+
const { token } = await response.json();
|
|
47
|
+
return token;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export function TunnelInventory() {
|
|
39
51
|
const { state, error, tunnels } = useRstream({
|
|
40
|
-
auth:
|
|
52
|
+
auth: createWatchToken,
|
|
41
53
|
engine: "project-endpoint.cluster.example.rstream.test:443",
|
|
42
54
|
transport: "sse",
|
|
43
55
|
});
|
|
@@ -66,16 +78,28 @@ Use `RstreamProvider` when several components need the same watch stream.
|
|
|
66
78
|
import { RstreamProvider } from "@rstreamlabs/react/providers";
|
|
67
79
|
import { useRstreamContext } from "@rstreamlabs/react/providers";
|
|
68
80
|
|
|
81
|
+
async function createWatchToken() {
|
|
82
|
+
const response = await fetch("/api/rstream/watch-token", {
|
|
83
|
+
method: "POST",
|
|
84
|
+
cache: "no-store",
|
|
85
|
+
});
|
|
86
|
+
if (!response.ok) {
|
|
87
|
+
throw new Error("Failed to create watch token.");
|
|
88
|
+
}
|
|
89
|
+
const { token } = await response.json();
|
|
90
|
+
return token;
|
|
91
|
+
}
|
|
92
|
+
|
|
69
93
|
function TunnelsTable() {
|
|
70
94
|
const { tunnels } = useRstreamContext();
|
|
71
95
|
return <pre>{JSON.stringify(tunnels, null, 2)}</pre>;
|
|
72
96
|
}
|
|
73
97
|
|
|
74
|
-
export function Dashboard(
|
|
98
|
+
export function Dashboard() {
|
|
75
99
|
return (
|
|
76
100
|
<RstreamProvider
|
|
77
101
|
options={{
|
|
78
|
-
auth:
|
|
102
|
+
auth: createWatchToken,
|
|
79
103
|
engine: "project-endpoint.cluster.example.rstream.test:443",
|
|
80
104
|
}}
|
|
81
105
|
>
|
|
@@ -114,8 +138,11 @@ state synchronized with the remote session.
|
|
|
114
138
|
|
|
115
139
|
## Security Notes
|
|
116
140
|
|
|
117
|
-
Browser
|
|
118
|
-
|
|
141
|
+
Browser watch streams should receive a fresh short-lived watch token from a
|
|
142
|
+
backend endpoint for each connection attempt. The token is sent to the engine as
|
|
143
|
+
`rstream.token` on `/api/sse` or `/api/websocket`, so it must be an `auth` or
|
|
144
|
+
`app` token with bounded lifetime and tunnel list-only grants. Do not embed
|
|
145
|
+
personal access tokens or application client secrets in React code.
|
|
119
146
|
|
|
120
147
|
## Development
|
|
121
148
|
|
package/package.json
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rstreamlabs/react",
|
|
3
|
-
"version": "1.7.
|
|
3
|
+
"version": "1.7.17",
|
|
4
4
|
"description": "React hooks and components for building rstream-enabled UIs.",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "https://github.com/rstreamlabs/rstream-js",
|
|
8
|
+
"directory": "packages/react"
|
|
9
|
+
},
|
|
5
10
|
"license": "Apache-2.0",
|
|
6
11
|
"main": "./dist/index.js",
|
|
7
12
|
"module": "./dist/index.mjs",
|
|
@@ -50,7 +55,8 @@
|
|
|
50
55
|
"typescript": "5.9.3"
|
|
51
56
|
},
|
|
52
57
|
"dependencies": {
|
|
53
|
-
"@rstreamlabs/
|
|
58
|
+
"@rstreamlabs/rstream": "2.1.5",
|
|
59
|
+
"@rstreamlabs/tunnels": "2.0.0",
|
|
54
60
|
"@rstreamlabs/webtty": "1.6.5",
|
|
55
61
|
"@xterm/addon-fit": "^0.11.0",
|
|
56
62
|
"@xterm/addon-unicode11": "^0.9.0",
|