@rstreamlabs/react 1.7.4 → 1.7.6
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/dist/{chunk-HTAKPV7E.mjs → chunk-5MUU3P7J.mjs} +84 -70
- package/dist/{chunk-CCMP5O6Z.mjs → chunk-DFYVJASW.mjs} +1 -1
- package/dist/{chunk-CTKB6CWW.mjs → chunk-G47GUMJ6.mjs} +64 -29
- package/dist/components/index.d.mts +0 -3
- package/dist/components/index.d.ts +0 -3
- package/dist/components/index.js +83 -67
- package/dist/components/index.mjs +1 -1
- package/dist/hooks/index.d.mts +6 -6
- package/dist/hooks/index.d.ts +6 -6
- package/dist/hooks/index.js +64 -29
- package/dist/hooks/index.mjs +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +147 -96
- package/dist/index.mjs +3 -3
- package/dist/providers/index.d.mts +6 -6
- package/dist/providers/index.d.ts +6 -6
- package/dist/providers/index.js +64 -29
- package/dist/providers/index.mjs +2 -2
- package/package.json +8 -8
|
@@ -1,20 +1,19 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
2
|
import { UseRstreamOptions, useRstream } from '../hooks/index.mjs';
|
|
3
3
|
import * as React from 'react';
|
|
4
|
-
import '@rstreamlabs/
|
|
4
|
+
import '@rstreamlabs/tunnels';
|
|
5
5
|
|
|
6
6
|
type RstreamContextValue = ReturnType<typeof useRstream>;
|
|
7
7
|
declare function useRstreamContext(): {
|
|
8
|
-
state: "
|
|
8
|
+
state: "connecting" | "connected" | "disconnected";
|
|
9
9
|
error: {
|
|
10
10
|
message: string;
|
|
11
11
|
type: "warning" | "danger";
|
|
12
12
|
} | null;
|
|
13
13
|
tunnels: {
|
|
14
|
-
status: "online" | "offline";
|
|
15
14
|
client_id: string;
|
|
15
|
+
status: "online" | "offline";
|
|
16
16
|
id: string;
|
|
17
|
-
type?: "bytestream" | "datagram" | undefined;
|
|
18
17
|
user_id?: string | undefined;
|
|
19
18
|
workspace_id?: string | undefined;
|
|
20
19
|
project_id?: string | undefined;
|
|
@@ -24,6 +23,7 @@ declare function useRstreamContext(): {
|
|
|
24
23
|
region?: string | undefined;
|
|
25
24
|
creation_date?: string | Date | undefined;
|
|
26
25
|
name?: string | undefined;
|
|
26
|
+
type?: "bytestream" | "datagram" | undefined;
|
|
27
27
|
publish?: boolean | undefined;
|
|
28
28
|
protocol?: "tls" | "dtls" | "quic" | "http" | undefined;
|
|
29
29
|
labels?: Record<string, string> | undefined;
|
|
@@ -43,8 +43,8 @@ declare function useRstreamContext(): {
|
|
|
43
43
|
challenge_mode?: boolean | undefined;
|
|
44
44
|
}[];
|
|
45
45
|
clients: {
|
|
46
|
-
status: "online" | "offline";
|
|
47
46
|
id: string;
|
|
47
|
+
status: "online" | "offline";
|
|
48
48
|
user_id?: string | undefined;
|
|
49
49
|
workspace_id?: string | undefined;
|
|
50
50
|
project_id?: string | undefined;
|
|
@@ -52,13 +52,13 @@ declare function useRstreamContext(): {
|
|
|
52
52
|
plan?: string | undefined;
|
|
53
53
|
provider?: string | undefined;
|
|
54
54
|
region?: string | undefined;
|
|
55
|
-
labels?: Record<string, string> | undefined;
|
|
56
55
|
agent?: string | undefined;
|
|
57
56
|
channel?: string | undefined;
|
|
58
57
|
version?: string | undefined;
|
|
59
58
|
os?: string | undefined;
|
|
60
59
|
arch?: string | undefined;
|
|
61
60
|
protocol_version?: string | undefined;
|
|
61
|
+
labels?: Record<string, string> | undefined;
|
|
62
62
|
}[];
|
|
63
63
|
};
|
|
64
64
|
interface RstreamProviderProps {
|
|
@@ -1,20 +1,19 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
2
|
import { UseRstreamOptions, useRstream } from '../hooks/index.js';
|
|
3
3
|
import * as React from 'react';
|
|
4
|
-
import '@rstreamlabs/
|
|
4
|
+
import '@rstreamlabs/tunnels';
|
|
5
5
|
|
|
6
6
|
type RstreamContextValue = ReturnType<typeof useRstream>;
|
|
7
7
|
declare function useRstreamContext(): {
|
|
8
|
-
state: "
|
|
8
|
+
state: "connecting" | "connected" | "disconnected";
|
|
9
9
|
error: {
|
|
10
10
|
message: string;
|
|
11
11
|
type: "warning" | "danger";
|
|
12
12
|
} | null;
|
|
13
13
|
tunnels: {
|
|
14
|
-
status: "online" | "offline";
|
|
15
14
|
client_id: string;
|
|
15
|
+
status: "online" | "offline";
|
|
16
16
|
id: string;
|
|
17
|
-
type?: "bytestream" | "datagram" | undefined;
|
|
18
17
|
user_id?: string | undefined;
|
|
19
18
|
workspace_id?: string | undefined;
|
|
20
19
|
project_id?: string | undefined;
|
|
@@ -24,6 +23,7 @@ declare function useRstreamContext(): {
|
|
|
24
23
|
region?: string | undefined;
|
|
25
24
|
creation_date?: string | Date | undefined;
|
|
26
25
|
name?: string | undefined;
|
|
26
|
+
type?: "bytestream" | "datagram" | undefined;
|
|
27
27
|
publish?: boolean | undefined;
|
|
28
28
|
protocol?: "tls" | "dtls" | "quic" | "http" | undefined;
|
|
29
29
|
labels?: Record<string, string> | undefined;
|
|
@@ -43,8 +43,8 @@ declare function useRstreamContext(): {
|
|
|
43
43
|
challenge_mode?: boolean | undefined;
|
|
44
44
|
}[];
|
|
45
45
|
clients: {
|
|
46
|
-
status: "online" | "offline";
|
|
47
46
|
id: string;
|
|
47
|
+
status: "online" | "offline";
|
|
48
48
|
user_id?: string | undefined;
|
|
49
49
|
workspace_id?: string | undefined;
|
|
50
50
|
project_id?: string | undefined;
|
|
@@ -52,13 +52,13 @@ declare function useRstreamContext(): {
|
|
|
52
52
|
plan?: string | undefined;
|
|
53
53
|
provider?: string | undefined;
|
|
54
54
|
region?: string | undefined;
|
|
55
|
-
labels?: Record<string, string> | undefined;
|
|
56
55
|
agent?: string | undefined;
|
|
57
56
|
channel?: string | undefined;
|
|
58
57
|
version?: string | undefined;
|
|
59
58
|
os?: string | undefined;
|
|
60
59
|
arch?: string | undefined;
|
|
61
60
|
protocol_version?: string | undefined;
|
|
61
|
+
labels?: Record<string, string> | undefined;
|
|
62
62
|
}[];
|
|
63
63
|
};
|
|
64
64
|
interface RstreamProviderProps {
|
package/dist/providers/index.js
CHANGED
|
@@ -36,38 +36,73 @@ __export(providers_exports, {
|
|
|
36
36
|
module.exports = __toCommonJS(providers_exports);
|
|
37
37
|
|
|
38
38
|
// src/hooks/use-rstream.ts
|
|
39
|
-
var
|
|
39
|
+
var import_tunnels = require("@rstreamlabs/tunnels");
|
|
40
40
|
var React = __toESM(require("react"));
|
|
41
41
|
function hasAuth(options) {
|
|
42
42
|
return !!options && !!options.auth;
|
|
43
43
|
}
|
|
44
|
+
function credentialsKey(credentials) {
|
|
45
|
+
if (!credentials) {
|
|
46
|
+
return "";
|
|
47
|
+
}
|
|
48
|
+
if ("token" in credentials) {
|
|
49
|
+
return `token:${credentials.token}`;
|
|
50
|
+
}
|
|
51
|
+
return `client:${credentials.clientId}:${credentials.clientSecret}`;
|
|
52
|
+
}
|
|
53
|
+
function watchConnectionKey(options) {
|
|
54
|
+
if (!hasAuth(options)) {
|
|
55
|
+
return "disabled";
|
|
56
|
+
}
|
|
57
|
+
return JSON.stringify({
|
|
58
|
+
apiUrl: options.apiUrl ?? null,
|
|
59
|
+
auth: typeof options.auth === "function" ? "function" : `token:${options.auth}`,
|
|
60
|
+
controlPlaneCredentials: credentialsKey(options.controlPlaneCredentials),
|
|
61
|
+
engine: options.engine ?? null,
|
|
62
|
+
projectEndpoint: options.projectEndpoint ?? null,
|
|
63
|
+
transport: options.transport ?? "sse"
|
|
64
|
+
});
|
|
65
|
+
}
|
|
44
66
|
function useRstream(options) {
|
|
45
67
|
const [state, setState] = React.useState("disconnected");
|
|
46
68
|
const [error, setError] = React.useState(null);
|
|
47
69
|
const { reconnectTimeout = 1e3, errorTimeout = 5e3 } = options || {};
|
|
48
70
|
const [clients, setClients] = React.useState([]);
|
|
49
71
|
const [tunnels, setTunnels] = React.useState([]);
|
|
72
|
+
const authEnabled = hasAuth(options);
|
|
73
|
+
const connectionKey = watchConnectionKey(options);
|
|
74
|
+
const optionsRef = React.useRef(options);
|
|
75
|
+
React.useEffect(() => {
|
|
76
|
+
optionsRef.current = options;
|
|
77
|
+
}, [options]);
|
|
78
|
+
const getWatchOptions = React.useEffectEvent(() => {
|
|
79
|
+
const current = optionsRef.current;
|
|
80
|
+
return hasAuth(current) ? current : void 0;
|
|
81
|
+
});
|
|
50
82
|
React.useEffect(() => {
|
|
51
|
-
if (!
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
83
|
+
if (!authEnabled) return;
|
|
84
|
+
const runtime = {
|
|
85
|
+
active: true,
|
|
86
|
+
timeout: null,
|
|
87
|
+
watch: null
|
|
88
|
+
};
|
|
55
89
|
const schedule = () => {
|
|
56
|
-
if (!active) return;
|
|
57
|
-
if (timeout) return;
|
|
90
|
+
if (!runtime.active) return;
|
|
91
|
+
if (runtime.timeout) return;
|
|
58
92
|
setState("connecting");
|
|
59
|
-
timeout = setTimeout(() => {
|
|
60
|
-
if (!active) return;
|
|
61
|
-
timeout = null;
|
|
93
|
+
runtime.timeout = setTimeout(() => {
|
|
94
|
+
if (!runtime.active) return;
|
|
95
|
+
runtime.timeout = null;
|
|
62
96
|
run();
|
|
63
97
|
}, reconnectTimeout);
|
|
64
98
|
};
|
|
65
99
|
const run = async () => {
|
|
66
|
-
|
|
100
|
+
const watchOptions = getWatchOptions();
|
|
101
|
+
if (!watchOptions) return;
|
|
67
102
|
setState("connecting");
|
|
68
|
-
watch = new
|
|
103
|
+
runtime.watch = new import_tunnels.Watch(watchOptions, {
|
|
69
104
|
onEvent: (event) => {
|
|
70
|
-
if (!active) return;
|
|
105
|
+
if (!runtime.active) return;
|
|
71
106
|
if (event.type === "state.initial") {
|
|
72
107
|
setClients(event.object.clients);
|
|
73
108
|
setTunnels(event.object.tunnels);
|
|
@@ -110,36 +145,36 @@ function useRstream(options) {
|
|
|
110
145
|
}
|
|
111
146
|
},
|
|
112
147
|
onConnect: () => {
|
|
113
|
-
if (!active) return;
|
|
148
|
+
if (!runtime.active) return;
|
|
114
149
|
setState("connected");
|
|
115
150
|
},
|
|
116
151
|
onClose: () => {
|
|
117
|
-
if (!active) return;
|
|
118
|
-
watch = null;
|
|
152
|
+
if (!runtime.active) return;
|
|
153
|
+
runtime.watch = null;
|
|
119
154
|
schedule();
|
|
120
155
|
}
|
|
121
156
|
});
|
|
122
157
|
try {
|
|
123
|
-
await watch.connect();
|
|
158
|
+
await runtime.watch.connect();
|
|
124
159
|
} catch {
|
|
125
160
|
schedule();
|
|
126
161
|
}
|
|
127
162
|
};
|
|
128
163
|
run();
|
|
129
164
|
return () => {
|
|
130
|
-
active = false;
|
|
131
|
-
if (watch) {
|
|
132
|
-
watch.disconnect();
|
|
133
|
-
watch = null;
|
|
165
|
+
runtime.active = false;
|
|
166
|
+
if (runtime.watch) {
|
|
167
|
+
runtime.watch.disconnect();
|
|
168
|
+
runtime.watch = null;
|
|
134
169
|
}
|
|
135
|
-
if (timeout) {
|
|
136
|
-
clearTimeout(timeout);
|
|
137
|
-
timeout = null;
|
|
170
|
+
if (runtime.timeout) {
|
|
171
|
+
clearTimeout(runtime.timeout);
|
|
172
|
+
runtime.timeout = null;
|
|
138
173
|
}
|
|
139
174
|
};
|
|
140
|
-
}, [
|
|
175
|
+
}, [authEnabled, connectionKey, reconnectTimeout]);
|
|
141
176
|
React.useEffect(() => {
|
|
142
|
-
if (
|
|
177
|
+
if (authEnabled) {
|
|
143
178
|
if (error && error.type === "danger") return;
|
|
144
179
|
if (state !== "connected") {
|
|
145
180
|
const timeout = setTimeout(() => {
|
|
@@ -157,13 +192,13 @@ function useRstream(options) {
|
|
|
157
192
|
} else {
|
|
158
193
|
setError(null);
|
|
159
194
|
}
|
|
160
|
-
}, [
|
|
195
|
+
}, [authEnabled, state, error, errorTimeout]);
|
|
161
196
|
React.useEffect(() => {
|
|
162
|
-
if (
|
|
197
|
+
if (!authEnabled || state !== "connected") {
|
|
163
198
|
setClients([]);
|
|
164
199
|
setTunnels([]);
|
|
165
200
|
}
|
|
166
|
-
}, [
|
|
201
|
+
}, [authEnabled, connectionKey, state]);
|
|
167
202
|
return { state, error, tunnels, clients };
|
|
168
203
|
}
|
|
169
204
|
|
package/dist/providers/index.mjs
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rstreamlabs/react",
|
|
3
|
-
"version": "1.7.
|
|
3
|
+
"version": "1.7.6",
|
|
4
4
|
"description": "React hooks and components for building rstream-enabled UIs.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -40,25 +40,25 @@
|
|
|
40
40
|
"type-check": "tsc --noEmit"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
|
-
"@turbo/gen": "^2.
|
|
44
|
-
"@types/node": "^25.
|
|
43
|
+
"@turbo/gen": "^2.9.5",
|
|
44
|
+
"@types/node": "^25.5.2",
|
|
45
45
|
"@types/react-dom": "19.2.3",
|
|
46
|
-
"@types/react": "19.2.
|
|
46
|
+
"@types/react": "19.2.14",
|
|
47
47
|
"eslint-config": "*",
|
|
48
48
|
"tsup": "^8.5.1",
|
|
49
49
|
"typescript-config": "*",
|
|
50
50
|
"typescript": "5.9.3"
|
|
51
51
|
},
|
|
52
52
|
"dependencies": {
|
|
53
|
-
"@rstreamlabs/
|
|
54
|
-
"@rstreamlabs/webtty": "1.6.
|
|
53
|
+
"@rstreamlabs/tunnels": "1.0.1",
|
|
54
|
+
"@rstreamlabs/webtty": "1.6.3",
|
|
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",
|
|
58
58
|
"@xterm/addon-webgl": "^0.19.0",
|
|
59
59
|
"@xterm/xterm": "^6.0.0",
|
|
60
|
-
"react": "^19.2.
|
|
61
|
-
"react
|
|
60
|
+
"react-dom": "^19.2.5",
|
|
61
|
+
"react": "^19.2.5"
|
|
62
62
|
},
|
|
63
63
|
"peerDependencies": {
|
|
64
64
|
"@types/react": "*",
|