|
|
@@ -23,9 +23,6 @@ function initPage8() {
|
|
|
sshFit = new FitAddon.FitAddon();
|
|
|
sshTerm.loadAddon(sshFit);
|
|
|
sshTerm.open(el);
|
|
|
- sshTerm.focus();
|
|
|
-
|
|
|
- connectSSH();
|
|
|
|
|
|
sshTerm.onData(data => {
|
|
|
if (sshWS?.readyState === WebSocket.OPEN) {
|
|
|
@@ -36,6 +33,8 @@ function initPage8() {
|
|
|
}
|
|
|
});
|
|
|
|
|
|
+ connectSSH();
|
|
|
+
|
|
|
window.addEventListener("resize", resizeSSH);
|
|
|
|
|
|
resizeSSH();
|
|
|
@@ -46,7 +45,10 @@ function connectSSH() {
|
|
|
"ws://" + location.host + "/api/ssh/ws"
|
|
|
);
|
|
|
|
|
|
- sshWS.onopen = resizeSSH;
|
|
|
+ sshWS.onopen = () => {
|
|
|
+ resizeSSH();
|
|
|
+ sshTerm?.focus();
|
|
|
+ };
|
|
|
|
|
|
sshWS.onmessage = e => {
|
|
|
sshTerm?.write(e.data);
|
|
|
@@ -54,8 +56,9 @@ function connectSSH() {
|
|
|
|
|
|
sshWS.onclose = () => {
|
|
|
sshWS = null;
|
|
|
- sshTerm.write(
|
|
|
- "\r\n\x1b[33m[Connection closed]\x1b[0m\r\n"
|
|
|
+
|
|
|
+ sshTerm?.write(
|
|
|
+ "\r\n\x1b[33m[Connection closed]\x1b[0m\r\n"
|
|
|
);
|
|
|
};
|
|
|
}
|
|
|
@@ -66,8 +69,12 @@ function resizeSSH() {
|
|
|
}
|
|
|
|
|
|
clearTimeout(sshResizeTimer);
|
|
|
+ sshResizeTimer = null;
|
|
|
|
|
|
sshResizeTimer = setTimeout(() => {
|
|
|
+ if (!sshTerm || !sshFit) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
|
|
|
sshFit.fit();
|
|
|
|
|
|
@@ -79,7 +86,7 @@ function resizeSSH() {
|
|
|
}));
|
|
|
}
|
|
|
|
|
|
- }, 100);
|
|
|
+ },100);
|
|
|
}
|
|
|
|
|
|
function exitPage8() {
|
|
|
@@ -90,8 +97,11 @@ function exitPage8() {
|
|
|
|
|
|
clearTimeout(sshResizeTimer);
|
|
|
|
|
|
- sshWS?.close();
|
|
|
- sshWS = null;
|
|
|
+ if (sshWS) {
|
|
|
+ sshWS.onclose = null;
|
|
|
+ sshWS.close();
|
|
|
+ sshWS = null;
|
|
|
+ }
|
|
|
|
|
|
sshTerm?.dispose();
|
|
|
sshTerm = null;
|