@rstreamlabs/webtty 1.6.3 → 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.
- package/README.md +120 -1
- package/dist/index.js +9 -7
- package/dist/index.mjs +9 -7
- package/package.json +3 -1
package/README.md
CHANGED
|
@@ -1,3 +1,122 @@
|
|
|
1
1
|
# `@rstreamlabs/webtty`
|
|
2
2
|
|
|
3
|
-
|
|
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/dist/index.js
CHANGED
|
@@ -1903,15 +1903,17 @@ var WebTTY = class {
|
|
|
1903
1903
|
*/
|
|
1904
1904
|
constructor(clientConfig, execConfig, events) {
|
|
1905
1905
|
this.clientConfig = {
|
|
1906
|
-
|
|
1907
|
-
|
|
1908
|
-
|
|
1906
|
+
heartbeatIntervalMs: clientConfig.heartbeatIntervalMs ?? 5e3,
|
|
1907
|
+
sendHeartbeat: clientConfig.sendHeartbeat ?? true,
|
|
1908
|
+
url: clientConfig.url
|
|
1909
1909
|
};
|
|
1910
1910
|
this.execConfig = {
|
|
1911
|
-
allocateTty: true,
|
|
1912
|
-
|
|
1913
|
-
envVars: [],
|
|
1914
|
-
|
|
1911
|
+
allocateTty: execConfig?.allocateTty ?? true,
|
|
1912
|
+
cmdArgs: execConfig?.cmdArgs,
|
|
1913
|
+
envVars: execConfig?.envVars ?? [],
|
|
1914
|
+
interactive: execConfig?.interactive ?? true,
|
|
1915
|
+
username: execConfig?.username,
|
|
1916
|
+
workdir: execConfig?.workdir
|
|
1915
1917
|
};
|
|
1916
1918
|
this.events = events || {};
|
|
1917
1919
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -1867,15 +1867,17 @@ var WebTTY = class {
|
|
|
1867
1867
|
*/
|
|
1868
1868
|
constructor(clientConfig, execConfig, events) {
|
|
1869
1869
|
this.clientConfig = {
|
|
1870
|
-
|
|
1871
|
-
|
|
1872
|
-
|
|
1870
|
+
heartbeatIntervalMs: clientConfig.heartbeatIntervalMs ?? 5e3,
|
|
1871
|
+
sendHeartbeat: clientConfig.sendHeartbeat ?? true,
|
|
1872
|
+
url: clientConfig.url
|
|
1873
1873
|
};
|
|
1874
1874
|
this.execConfig = {
|
|
1875
|
-
allocateTty: true,
|
|
1876
|
-
|
|
1877
|
-
envVars: [],
|
|
1878
|
-
|
|
1875
|
+
allocateTty: execConfig?.allocateTty ?? true,
|
|
1876
|
+
cmdArgs: execConfig?.cmdArgs,
|
|
1877
|
+
envVars: execConfig?.envVars ?? [],
|
|
1878
|
+
interactive: execConfig?.interactive ?? true,
|
|
1879
|
+
username: execConfig?.username,
|
|
1880
|
+
workdir: execConfig?.workdir
|
|
1879
1881
|
};
|
|
1880
1882
|
this.events = events || {};
|
|
1881
1883
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rstreamlabs/webtty",
|
|
3
|
-
"version": "1.6.
|
|
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",
|
|
@@ -16,6 +16,8 @@
|
|
|
16
16
|
"clean": "rm -rf .generated && rm -rf dist",
|
|
17
17
|
"generate-proto-files": "bash scripts/generate-proto-files.sh",
|
|
18
18
|
"lint": "eslint \"./**/*.ts*\"",
|
|
19
|
+
"pretest": "npm run generate-proto-files && npm run build",
|
|
20
|
+
"test": "node --test ./test/**/*.test.cjs",
|
|
19
21
|
"type-check": "tsc --noEmit"
|
|
20
22
|
},
|
|
21
23
|
"devDependencies": {
|