-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.ts
51 lines (43 loc) · 1.16 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import io from "socket.io-client";
import { Terminal } from "xterm";
import { FitAddon } from "xterm-addon-fit";
import "./main.scss";
const term = new Terminal({ cursorBlink: true });
const terminalContainer = document.getElementById("terminal-container")!;
const fitAddon = new FitAddon();
term.loadAddon(fitAddon);
term.open(terminalContainer);
term.focus();
fitAddon.fit();
const socket = io("http://localhost:8022/", { path: "/ssh" }).open();
window.addEventListener("resize", resize, false);
function resize() {
fitAddon.fit();
socket.emit("resize", {
cols: term.cols,
rows: term.rows,
width: terminalContainer.clientWidth,
height: terminalContainer.clientHeight,
});
}
socket.on("connect", () => {
socket.emit("shell", {
host: "",
port: 22,
username: "",
password: "",
cols: term.cols,
rows: term.rows,
width: terminalContainer.clientWidth,
height: terminalContainer.clientHeight,
});
});
term.onData((data: string) => {
socket.emit("data", data);
});
socket.on("data", (data: ArrayBuffer) => {
term.write(new TextDecoder().decode(data));
});
socket.on("shell_error", (type: string) => {
alert(type);
});