@rstreamlabs/webtty 1.6.4 → 1.6.5

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 +120 -1
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -1,3 +1,122 @@
1
1
  # `@rstreamlabs/webtty`
2
2
 
3
- Client-side implementation of the rstream WebTTY protocol.
3
+ Browser-side client for the rstream WebTTY protocol.
4
+
5
+ Use this package when you need to connect a web application to a WebTTY server
6
+ over WebSocket. It handles the protobuf session handshake, stdin/stdout/stderr
7
+ streams, remote process completion, terminal resize events, and heartbeats.
8
+
9
+ For a ready-made React terminal, use
10
+ [`@rstreamlabs/react`](../react/README.md).
11
+
12
+ ## Install
13
+
14
+ ```sh
15
+ npm install @rstreamlabs/webtty
16
+ ```
17
+
18
+ ## Connect to a WebTTY Session
19
+
20
+ ```ts
21
+ import { WebTTY } from "@rstreamlabs/webtty";
22
+
23
+ const decoder = new TextDecoder();
24
+
25
+ const webtty = new WebTTY(
26
+ {
27
+ url: "wss://host.example.t.rstream.io?rstream.token=<token>",
28
+ },
29
+ {
30
+ cmdArgs: ["uname", "-a"],
31
+ interactive: false,
32
+ },
33
+ {
34
+ onConnect: () => {
35
+ console.log("connected");
36
+ },
37
+ onStdout: (chunk) => {
38
+ console.log(decoder.decode(chunk));
39
+ },
40
+ onComplete: (exitCode) => {
41
+ console.log("completed", exitCode);
42
+ },
43
+ onError: (message) => {
44
+ console.error(message);
45
+ },
46
+ },
47
+ );
48
+
49
+ webtty.connect();
50
+ ```
51
+
52
+ ## Interactive Sessions
53
+
54
+ For an interactive terminal, write encoded input to stdin and forward terminal
55
+ resize events.
56
+
57
+ ```ts
58
+ const encoder = new TextEncoder();
59
+
60
+ const webtty = new WebTTY(
61
+ { url: "wss://host.example.t.rstream.io?rstream.token=<token>" },
62
+ { allocateTty: true, interactive: true },
63
+ );
64
+
65
+ webtty.connect();
66
+
67
+ // After onConnect fires:
68
+ webtty.writeStdin(encoder.encode("whoami\n"));
69
+ webtty.resize(40, 120);
70
+ ```
71
+
72
+ Call `closeStdin()` to send EOF, or `disconnect()` to terminate the client
73
+ session.
74
+
75
+ ## Configuration
76
+
77
+ Client-level options:
78
+
79
+ | Option | Purpose |
80
+ | --- | --- |
81
+ | `url` | WebSocket endpoint for the WebTTY server. |
82
+ | `sendHeartbeat` | Send heartbeat messages. Defaults to `true`. |
83
+ | `heartbeatIntervalMs` | Heartbeat interval in milliseconds. Defaults to `5000`. |
84
+
85
+ Execution options:
86
+
87
+ | Option | Purpose |
88
+ | --- | --- |
89
+ | `cmdArgs` | Command arguments requested for the remote session. |
90
+ | `envVars` | Environment variables requested for the remote session. |
91
+ | `allocateTty` | Ask the server for a TTY. Defaults to `true`. |
92
+ | `interactive` | Enable stdin. Defaults to `true`. |
93
+ | `username` | Optional user name or numeric user ID. |
94
+ | `workdir` | Optional working directory. |
95
+
96
+ The remote WebTTY server decides which execution options are accepted. Treat
97
+ these values as requests, not local privilege boundaries.
98
+
99
+ ## Events
100
+
101
+ | Event | Purpose |
102
+ | --- | --- |
103
+ | `onConnect` | Called after the server acknowledges the session. |
104
+ | `onStdout` / `onStderr` | Called with stream chunks from the remote process. |
105
+ | `onStdoutEos` / `onStderrEos` | Called when the corresponding stream reaches EOS. |
106
+ | `onComplete` | Called with the remote process exit code. |
107
+ | `onError` | Called for server errors, protocol errors, or connection failures. |
108
+
109
+ ## Security Notes
110
+
111
+ Browser WebTTY sessions should use short-lived tokens scoped to the specific
112
+ tunnel and path. Do not embed personal access tokens or application credentials
113
+ in frontend code.
114
+
115
+ ## Development
116
+
117
+ ```sh
118
+ npm --workspace @rstreamlabs/webtty run test
119
+ npm --workspace @rstreamlabs/webtty run type-check
120
+ npm --workspace @rstreamlabs/webtty run lint
121
+ npm --workspace @rstreamlabs/webtty run build
122
+ ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rstreamlabs/webtty",
3
- "version": "1.6.4",
3
+ "version": "1.6.5",
4
4
  "description": "Client-side implementation of the rstream WebTTY protocol.",
5
5
  "license": "Apache-2.0",
6
6
  "main": "./dist/index.js",