mirror of
https://github.com/Dokploy/dokploy
synced 2025-06-26 18:27:59 +00:00
refactor(dokploy): revert
This commit is contained in:
@@ -18,28 +18,24 @@ export const DockerLogsId: React.FC<Props> = ({
|
|||||||
}) => {
|
}) => {
|
||||||
const [term, setTerm] = React.useState<Terminal>();
|
const [term, setTerm] = React.useState<Terminal>();
|
||||||
const [lines, setLines] = React.useState<number>(40);
|
const [lines, setLines] = React.useState<number>(40);
|
||||||
const wsRef = useRef<WebSocket | null>(null);
|
const wsRef = useRef<WebSocket | null>(null); // Ref to hold WebSocket instance
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (containerId === "select-a-container") {
|
// if (containerId === "select-a-container") {
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
|
|
||||||
if (
|
|
||||||
wsRef.current &&
|
|
||||||
(wsRef.current.readyState === WebSocket.OPEN ||
|
|
||||||
wsRef.current.readyState === WebSocket.CONNECTING)
|
|
||||||
) {
|
|
||||||
wsRef.current.close();
|
|
||||||
wsRef.current = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
const container = document.getElementById(id);
|
const container = document.getElementById(id);
|
||||||
if (container) {
|
if (container) {
|
||||||
container.innerHTML = "";
|
container.innerHTML = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
// Crear nueva instancia de Terminal
|
if (wsRef.current) {
|
||||||
|
console.log(wsRef.current);
|
||||||
|
if (wsRef.current.readyState === WebSocket.OPEN) {
|
||||||
|
wsRef.current.close();
|
||||||
|
}
|
||||||
|
wsRef.current = null;
|
||||||
|
}
|
||||||
const termi = new Terminal({
|
const termi = new Terminal({
|
||||||
cursorBlink: true,
|
cursorBlink: true,
|
||||||
cols: 80,
|
cols: 80,
|
||||||
@@ -49,6 +45,7 @@ export const DockerLogsId: React.FC<Props> = ({
|
|||||||
fontSize: 14,
|
fontSize: 14,
|
||||||
fontFamily:
|
fontFamily:
|
||||||
'ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace',
|
'ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace',
|
||||||
|
|
||||||
convertEol: true,
|
convertEol: true,
|
||||||
theme: {
|
theme: {
|
||||||
cursor: "transparent",
|
cursor: "transparent",
|
||||||
@@ -57,10 +54,10 @@ export const DockerLogsId: React.FC<Props> = ({
|
|||||||
});
|
});
|
||||||
|
|
||||||
const protocol = window.location.protocol === "https:" ? "wss:" : "ws:";
|
const protocol = window.location.protocol === "https:" ? "wss:" : "ws:";
|
||||||
|
|
||||||
const wsUrl = `${protocol}//${window.location.host}/docker-container-logs?containerId=${containerId}&tail=${lines}${serverId ? `&serverId=${serverId}` : ""}`;
|
const wsUrl = `${protocol}//${window.location.host}/docker-container-logs?containerId=${containerId}&tail=${lines}${serverId ? `&serverId=${serverId}` : ""}`;
|
||||||
const ws = new WebSocket(wsUrl);
|
const ws = new WebSocket(wsUrl);
|
||||||
wsRef.current = ws;
|
wsRef.current = ws;
|
||||||
|
|
||||||
const fitAddon = new FitAddon();
|
const fitAddon = new FitAddon();
|
||||||
termi.loadAddon(fitAddon);
|
termi.loadAddon(fitAddon);
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
@@ -79,17 +76,17 @@ export const DockerLogsId: React.FC<Props> = ({
|
|||||||
|
|
||||||
ws.onclose = (e) => {
|
ws.onclose = (e) => {
|
||||||
console.log(e.reason);
|
console.log(e.reason);
|
||||||
|
|
||||||
termi.write(`Connection closed!\nReason: ${e.reason}\n`);
|
termi.write(`Connection closed!\nReason: ${e.reason}\n`);
|
||||||
wsRef.current = null;
|
wsRef.current = null;
|
||||||
};
|
};
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
if (wsRef.current?.readyState === WebSocket.OPEN) {
|
if (wsRef.current?.readyState === WebSocket.OPEN) {
|
||||||
wsRef.current.close();
|
ws.close();
|
||||||
|
wsRef.current = null;
|
||||||
}
|
}
|
||||||
wsRef.current = null;
|
|
||||||
};
|
};
|
||||||
}, [containerId, lines]);
|
}, [lines, containerId]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
term?.clear();
|
term?.clear();
|
||||||
|
|||||||
@@ -5,11 +5,6 @@ import { Client } from "ssh2";
|
|||||||
import { WebSocketServer } from "ws";
|
import { WebSocketServer } from "ws";
|
||||||
import { getShell } from "./utils";
|
import { getShell } from "./utils";
|
||||||
|
|
||||||
function heartbeat() {
|
|
||||||
// @ts-ignore
|
|
||||||
this.isAlive = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
export const setupDockerContainerLogsWebSocketServer = (
|
export const setupDockerContainerLogsWebSocketServer = (
|
||||||
server: http.Server<typeof http.IncomingMessage, typeof http.ServerResponse>,
|
server: http.Server<typeof http.IncomingMessage, typeof http.ServerResponse>,
|
||||||
) => {
|
) => {
|
||||||
@@ -48,11 +43,6 @@ export const setupDockerContainerLogsWebSocketServer = (
|
|||||||
ws.close();
|
ws.close();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// @ts-ignore
|
|
||||||
ws.isAlive = true;
|
|
||||||
ws.on("error", console.error);
|
|
||||||
ws.on("pong", heartbeat);
|
|
||||||
try {
|
try {
|
||||||
if (serverId) {
|
if (serverId) {
|
||||||
const server = await findServerById(serverId);
|
const server = await findServerById(serverId);
|
||||||
@@ -148,18 +138,4 @@ export const setupDockerContainerLogsWebSocketServer = (
|
|||||||
ws.send(errorMessage);
|
ws.send(errorMessage);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
const interval = setInterval(function ping() {
|
|
||||||
for (const ws of wssTerm.clients) {
|
|
||||||
// @ts-ignore
|
|
||||||
if (ws.isAlive === false) return ws.terminate();
|
|
||||||
// @ts-ignore
|
|
||||||
ws.isAlive = false;
|
|
||||||
ws.ping();
|
|
||||||
}
|
|
||||||
}, 30000);
|
|
||||||
|
|
||||||
wssTerm.on("close", function close() {
|
|
||||||
clearInterval(interval);
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user