@rstreamlabs/react 1.3.0 → 1.5.0

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,80 @@
1
+ import { WatchConfig } from '@rstreamlabs/rstream';
2
+
3
+ /**
4
+ * Configuration for the UseRstream hook.
5
+ */
6
+ interface UseRstreamOptions extends Partial<WatchConfig> {
7
+ /**
8
+ * Timeout (in milliseconds) to wait before attempting to reconnect
9
+ * after the SSE connection is closed.
10
+ *
11
+ * @default 1000
12
+ */
13
+ reconnectTimeout?: number;
14
+ /**
15
+ * Timeout (in milliseconds) to wait before showing an error message
16
+ * when the connection is not yet established.
17
+ *
18
+ * @default 5000
19
+ */
20
+ errorTimeout?: number;
21
+ }
22
+ /**
23
+ * A React hook to subscribe to rstream resources.
24
+ *
25
+ * This hook fetches the list of clients and tunnels from the rstream API.
26
+ * It handles automatic reconnection and displays a warning if the connection
27
+ * is not established within the timeout.
28
+ *
29
+ * @param options - The configuration options for the hook.
30
+ * @returns An object with the current error (if any), and arrays of tunnels and clients.
31
+ */
32
+ declare function useRstream(options?: UseRstreamOptions): {
33
+ error: {
34
+ message: string;
35
+ type: "warning" | "danger";
36
+ } | null;
37
+ tunnels: {
38
+ status: "online" | "offline";
39
+ client_id: string;
40
+ user_id: string;
41
+ id: string;
42
+ type?: "bytestream" | "datagram" | undefined;
43
+ name?: string | undefined;
44
+ creation_date?: Date | undefined;
45
+ publish?: boolean | undefined;
46
+ protocol?: "tls" | "dtls" | "quic" | "http" | undefined;
47
+ labels?: Record<string, string | undefined> | undefined;
48
+ geo_ip?: string[] | undefined;
49
+ trusted_ips?: string[] | undefined;
50
+ host?: string | undefined;
51
+ tls_mode?: "passthrough" | "terminated" | undefined;
52
+ tls_alpns?: string[] | undefined;
53
+ tls_min_version?: string | undefined;
54
+ tls_ciphers?: string[] | undefined;
55
+ mtls?: boolean | undefined;
56
+ mtls_ca_cert_pem?: string | undefined;
57
+ http_version?: "http/1.1" | "h2c" | "h3" | undefined;
58
+ http_use_tls?: boolean | undefined;
59
+ token_auth?: boolean | undefined;
60
+ sso?: boolean | undefined;
61
+ sso_providers?: string[] | undefined;
62
+ email_whitelist?: string[] | undefined;
63
+ email_blacklist?: string[] | undefined;
64
+ challenge?: boolean | undefined;
65
+ }[];
66
+ clients: {
67
+ status: "online" | "offline";
68
+ user_id: string;
69
+ id: string;
70
+ labels?: Record<string, string | undefined> | undefined;
71
+ details?: {
72
+ agent?: string | undefined;
73
+ os?: string | undefined;
74
+ version?: string | undefined;
75
+ protocol_version?: string | undefined;
76
+ } | undefined;
77
+ }[];
78
+ };
79
+
80
+ export { type UseRstreamOptions, useRstream };
@@ -0,0 +1,168 @@
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/hooks/index.ts
31
+ var hooks_exports = {};
32
+ __export(hooks_exports, {
33
+ useRstream: () => useRstream
34
+ });
35
+ module.exports = __toCommonJS(hooks_exports);
36
+
37
+ // src/hooks/use-rstream.ts
38
+ var import_rstream = require("@rstreamlabs/rstream");
39
+ var React = __toESM(require("react"));
40
+ function hasAuth(options) {
41
+ return !!options && !!options.auth;
42
+ }
43
+ function useRstream(options) {
44
+ const [state, setState] = React.useState("disconnected");
45
+ const [error, setError] = React.useState(null);
46
+ const { reconnectTimeout = 1e3, errorTimeout = 5e3 } = options || {};
47
+ const [clients, setClients] = React.useState([]);
48
+ const [tunnels, setTunnels] = React.useState([]);
49
+ React.useEffect(() => {
50
+ if (!hasAuth(options)) return;
51
+ let active = true;
52
+ let watch = null;
53
+ let timeout = null;
54
+ const schedule = () => {
55
+ if (!active) return;
56
+ if (timeout) return;
57
+ setState("connecting");
58
+ timeout = setTimeout(() => {
59
+ if (!active) return;
60
+ timeout = null;
61
+ run();
62
+ }, reconnectTimeout);
63
+ };
64
+ const run = async () => {
65
+ if (!hasAuth(options)) return;
66
+ setState("connecting");
67
+ watch = new import_rstream.Watch(options, {
68
+ onEvent: (event) => {
69
+ if (!active) return;
70
+ if (event.type.startsWith("client")) {
71
+ setClients((previous) => {
72
+ if (event.type === "client.created") {
73
+ return [...previous, event.object];
74
+ } else if (event.type === "client.updated") {
75
+ return previous.map((client) => {
76
+ if (client.id === event.object.id) {
77
+ return event.object;
78
+ }
79
+ return client;
80
+ });
81
+ } else if (event.type === "client.deleted") {
82
+ return previous.filter(
83
+ (client) => client.id !== event.object.id
84
+ );
85
+ }
86
+ return previous;
87
+ });
88
+ } else if (event.type.startsWith("tunnel")) {
89
+ setTunnels((previous) => {
90
+ if (event.type === "tunnel.created") {
91
+ return [...previous, event.object];
92
+ } else if (event.type === "tunnel.updated") {
93
+ return previous.map((tunnel) => {
94
+ if (tunnel.id === event.object.id) {
95
+ return event.object;
96
+ }
97
+ return tunnel;
98
+ });
99
+ } else if (event.type === "tunnel.deleted") {
100
+ return previous.filter(
101
+ (tunnel) => tunnel.id !== event.object.id
102
+ );
103
+ }
104
+ return previous;
105
+ });
106
+ }
107
+ },
108
+ onConnect: () => {
109
+ if (!active) return;
110
+ setState("connected");
111
+ },
112
+ onClose: () => {
113
+ if (!active) return;
114
+ watch = null;
115
+ schedule();
116
+ }
117
+ });
118
+ try {
119
+ await watch.connect();
120
+ } catch {
121
+ schedule();
122
+ }
123
+ };
124
+ run();
125
+ return () => {
126
+ active = false;
127
+ if (watch) {
128
+ watch.disconnect();
129
+ watch = null;
130
+ }
131
+ if (timeout) {
132
+ clearTimeout(timeout);
133
+ timeout = null;
134
+ }
135
+ };
136
+ }, [options, reconnectTimeout]);
137
+ React.useEffect(() => {
138
+ if (options?.auth) {
139
+ if (error && error.type === "danger") return;
140
+ if (state !== "connected") {
141
+ const timeout = setTimeout(() => {
142
+ setError({
143
+ message: "Failed to fetch rstream ressources. Retrying...",
144
+ type: "warning"
145
+ });
146
+ }, errorTimeout);
147
+ return () => {
148
+ clearTimeout(timeout);
149
+ };
150
+ } else if (state === "connected") {
151
+ setError(null);
152
+ }
153
+ } else {
154
+ setError(null);
155
+ }
156
+ }, [options, state, error, errorTimeout]);
157
+ React.useEffect(() => {
158
+ if (options?.auth === void 0 || state !== "connected") {
159
+ setClients([]);
160
+ setTunnels([]);
161
+ }
162
+ }, [options, state]);
163
+ return { error, tunnels, clients };
164
+ }
165
+ // Annotate the CommonJS export names for ESM import in node:
166
+ 0 && (module.exports = {
167
+ useRstream
168
+ });
@@ -0,0 +1,7 @@
1
+ import "../chunk-2JFL7TS5.mjs";
2
+ import {
3
+ useRstream
4
+ } from "../chunk-2WDUPTYY.mjs";
5
+ export {
6
+ useRstream
7
+ };
package/dist/index.d.mts CHANGED
@@ -1,103 +1,8 @@
1
- import * as react_jsx_runtime from 'react/jsx-runtime';
2
- import { ITerminalOptions, Terminal } from '@xterm/xterm';
3
- import { WebTTYClientConfig, WebTTYExecutionConfig, WebTTYEvents } from '@rstreamlabs/webtty';
4
- import { RstreamAuth } from '@rstreamlabs/rstream';
5
-
6
- interface WebTTYTerminalProps extends WebTTYClientConfig, WebTTYExecutionConfig, WebTTYEvents {
7
- /**
8
- * xterm.js TerminalOptions override
9
- */
10
- terminalOptions?: ITerminalOptions;
11
- /**
12
- * Called once the xterm Terminal is created (before connect).
13
- * Can be used to add your own add-ons or manipulate the Terminal instance.
14
- */
15
- onTerminalCreated?: (terminal: Terminal) => void;
16
- }
17
- /**
18
- * A React component that binds a WebTTY session to an xterm.js instance.
19
- */
20
- declare function WebTTYTerminal(props: WebTTYTerminalProps): react_jsx_runtime.JSX.Element;
21
-
22
- /**
23
- * Configuration for the UseRstream hook.
24
- */
25
- interface UseRstreamOptions {
26
- /**
27
- * Short-term authentication token provider.
28
- */
29
- auth?: RstreamAuth;
30
- /**
31
- * Timeout (in milliseconds) to wait before attempting to reconnect
32
- * after the SSE connection is closed.
33
- *
34
- * @default 1000
35
- */
36
- reconnectTimeout?: number;
37
- /**
38
- * Timeout (in milliseconds) to wait before showing an error message
39
- * when the connection is not yet established.
40
- *
41
- * @default 5000
42
- */
43
- errorTimeout?: number;
44
- }
45
- /**
46
- * A React hook to subscribe to rstream resources.
47
- *
48
- * This hook fetches the list of clients and tunnels from the rstream API.
49
- * It handles automatic reconnection and displays a warning if the connection
50
- * is not established within the timeout.
51
- *
52
- * @param options - The configuration options for the hook.
53
- * @returns An object with the current error (if any), and arrays of tunnels and clients.
54
- */
55
- declare function useRstream(options?: UseRstreamOptions): {
56
- error: {
57
- message: string;
58
- type: "warning" | "danger";
59
- } | null;
60
- tunnels: {
61
- type?: "bytestream" | "datagram" | undefined;
62
- status?: "online" | "offline" | undefined;
63
- client_id?: string | undefined;
64
- user_id?: string | undefined;
65
- id?: string | undefined;
66
- name?: string | undefined;
67
- creation_date?: Date | undefined;
68
- publish?: boolean | undefined;
69
- protocol?: "tls" | "dtls" | "quic" | "http" | undefined;
70
- labels?: Record<string, string | undefined> | undefined;
71
- geo_ip?: string[] | undefined;
72
- trusted_ips?: string[] | undefined;
73
- host?: string | undefined;
74
- tls_mode?: "passthrough" | "terminated" | undefined;
75
- tls_alpns?: string[] | undefined;
76
- tls_min_version?: string | undefined;
77
- tls_ciphers?: string[] | undefined;
78
- mtls?: boolean | undefined;
79
- mtls_ca_cert_pem?: string | undefined;
80
- http_version?: "http/1.1" | "h2c" | "h3" | undefined;
81
- http_use_tls?: boolean | undefined;
82
- token_auth?: boolean | undefined;
83
- sso?: boolean | undefined;
84
- sso_providers?: string[] | undefined;
85
- email_whitelist?: string[] | undefined;
86
- email_blacklist?: string[] | undefined;
87
- challenge?: boolean | undefined;
88
- }[];
89
- clients: {
90
- status: "online" | "offline";
91
- user_id: string;
92
- id: string;
93
- labels?: Record<string, string | undefined> | undefined;
94
- details?: {
95
- agent?: string | undefined;
96
- os?: string | undefined;
97
- version?: string | undefined;
98
- protocol_version?: string | undefined;
99
- } | undefined;
100
- }[];
101
- };
102
-
103
- export { type UseRstreamOptions, WebTTYTerminal, type WebTTYTerminalProps, useRstream };
1
+ export { WebTTYTerminal, WebTTYTerminalProps } from './components/index.mjs';
2
+ export { UseRstreamOptions, useRstream } from './hooks/index.mjs';
3
+ export { RstreamProvider, useRstreamContext } from './providers/index.mjs';
4
+ import 'react/jsx-runtime';
5
+ import '@xterm/xterm';
6
+ import '@rstreamlabs/webtty';
7
+ import '@rstreamlabs/rstream';
8
+ import 'react';
package/dist/index.d.ts CHANGED
@@ -1,103 +1,8 @@
1
- import * as react_jsx_runtime from 'react/jsx-runtime';
2
- import { ITerminalOptions, Terminal } from '@xterm/xterm';
3
- import { WebTTYClientConfig, WebTTYExecutionConfig, WebTTYEvents } from '@rstreamlabs/webtty';
4
- import { RstreamAuth } from '@rstreamlabs/rstream';
5
-
6
- interface WebTTYTerminalProps extends WebTTYClientConfig, WebTTYExecutionConfig, WebTTYEvents {
7
- /**
8
- * xterm.js TerminalOptions override
9
- */
10
- terminalOptions?: ITerminalOptions;
11
- /**
12
- * Called once the xterm Terminal is created (before connect).
13
- * Can be used to add your own add-ons or manipulate the Terminal instance.
14
- */
15
- onTerminalCreated?: (terminal: Terminal) => void;
16
- }
17
- /**
18
- * A React component that binds a WebTTY session to an xterm.js instance.
19
- */
20
- declare function WebTTYTerminal(props: WebTTYTerminalProps): react_jsx_runtime.JSX.Element;
21
-
22
- /**
23
- * Configuration for the UseRstream hook.
24
- */
25
- interface UseRstreamOptions {
26
- /**
27
- * Short-term authentication token provider.
28
- */
29
- auth?: RstreamAuth;
30
- /**
31
- * Timeout (in milliseconds) to wait before attempting to reconnect
32
- * after the SSE connection is closed.
33
- *
34
- * @default 1000
35
- */
36
- reconnectTimeout?: number;
37
- /**
38
- * Timeout (in milliseconds) to wait before showing an error message
39
- * when the connection is not yet established.
40
- *
41
- * @default 5000
42
- */
43
- errorTimeout?: number;
44
- }
45
- /**
46
- * A React hook to subscribe to rstream resources.
47
- *
48
- * This hook fetches the list of clients and tunnels from the rstream API.
49
- * It handles automatic reconnection and displays a warning if the connection
50
- * is not established within the timeout.
51
- *
52
- * @param options - The configuration options for the hook.
53
- * @returns An object with the current error (if any), and arrays of tunnels and clients.
54
- */
55
- declare function useRstream(options?: UseRstreamOptions): {
56
- error: {
57
- message: string;
58
- type: "warning" | "danger";
59
- } | null;
60
- tunnels: {
61
- type?: "bytestream" | "datagram" | undefined;
62
- status?: "online" | "offline" | undefined;
63
- client_id?: string | undefined;
64
- user_id?: string | undefined;
65
- id?: string | undefined;
66
- name?: string | undefined;
67
- creation_date?: Date | undefined;
68
- publish?: boolean | undefined;
69
- protocol?: "tls" | "dtls" | "quic" | "http" | undefined;
70
- labels?: Record<string, string | undefined> | undefined;
71
- geo_ip?: string[] | undefined;
72
- trusted_ips?: string[] | undefined;
73
- host?: string | undefined;
74
- tls_mode?: "passthrough" | "terminated" | undefined;
75
- tls_alpns?: string[] | undefined;
76
- tls_min_version?: string | undefined;
77
- tls_ciphers?: string[] | undefined;
78
- mtls?: boolean | undefined;
79
- mtls_ca_cert_pem?: string | undefined;
80
- http_version?: "http/1.1" | "h2c" | "h3" | undefined;
81
- http_use_tls?: boolean | undefined;
82
- token_auth?: boolean | undefined;
83
- sso?: boolean | undefined;
84
- sso_providers?: string[] | undefined;
85
- email_whitelist?: string[] | undefined;
86
- email_blacklist?: string[] | undefined;
87
- challenge?: boolean | undefined;
88
- }[];
89
- clients: {
90
- status: "online" | "offline";
91
- user_id: string;
92
- id: string;
93
- labels?: Record<string, string | undefined> | undefined;
94
- details?: {
95
- agent?: string | undefined;
96
- os?: string | undefined;
97
- version?: string | undefined;
98
- protocol_version?: string | undefined;
99
- } | undefined;
100
- }[];
101
- };
102
-
103
- export { type UseRstreamOptions, WebTTYTerminal, type WebTTYTerminalProps, useRstream };
1
+ export { WebTTYTerminal, WebTTYTerminalProps } from './components/index.js';
2
+ export { UseRstreamOptions, useRstream } from './hooks/index.js';
3
+ export { RstreamProvider, useRstreamContext } from './providers/index.js';
4
+ import 'react/jsx-runtime';
5
+ import '@xterm/xterm';
6
+ import '@rstreamlabs/webtty';
7
+ import '@rstreamlabs/rstream';
8
+ import 'react';