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 [lines, setLines] = React.useState<number>(40);
|
||||
const wsRef = useRef<WebSocket | null>(null);
|
||||
const wsRef = useRef<WebSocket | null>(null); // Ref to hold WebSocket instance
|
||||
|
||||
useEffect(() => {
|
||||
if (containerId === "select-a-container") {
|
||||
return;
|
||||
}
|
||||
|
||||
if (
|
||||
wsRef.current &&
|
||||
(wsRef.current.readyState === WebSocket.OPEN ||
|
||||
wsRef.current.readyState === WebSocket.CONNECTING)
|
||||
) {
|
||||
wsRef.current.close();
|
||||
wsRef.current = null;
|
||||
}
|
||||
|
||||
// if (containerId === "select-a-container") {
|
||||
// return;
|
||||
// }
|
||||
const container = document.getElementById(id);
|
||||
if (container) {
|
||||
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({
|
||||
cursorBlink: true,
|
||||
cols: 80,
|
||||
@@ -49,6 +45,7 @@ export const DockerLogsId: React.FC<Props> = ({
|
||||
fontSize: 14,
|
||||
fontFamily:
|
||||
'ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace',
|
||||
|
||||
convertEol: true,
|
||||
theme: {
|
||||
cursor: "transparent",
|
||||
@@ -57,10 +54,10 @@ export const DockerLogsId: React.FC<Props> = ({
|
||||
});
|
||||
|
||||
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 ws = new WebSocket(wsUrl);
|
||||
wsRef.current = ws;
|
||||
|
||||
const fitAddon = new FitAddon();
|
||||
termi.loadAddon(fitAddon);
|
||||
// @ts-ignore
|
||||
@@ -79,17 +76,17 @@ export const DockerLogsId: React.FC<Props> = ({
|
||||
|
||||
ws.onclose = (e) => {
|
||||
console.log(e.reason);
|
||||
|
||||
termi.write(`Connection closed!\nReason: ${e.reason}\n`);
|
||||
wsRef.current = null;
|
||||
};
|
||||
|
||||
return () => {
|
||||
if (wsRef.current?.readyState === WebSocket.OPEN) {
|
||||
wsRef.current.close();
|
||||
ws.close();
|
||||
wsRef.current = null;
|
||||
}
|
||||
wsRef.current = null;
|
||||
};
|
||||
}, [containerId, lines]);
|
||||
}, [lines, containerId]);
|
||||
|
||||
useEffect(() => {
|
||||
term?.clear();
|
||||
|
||||
@@ -5,11 +5,6 @@ import { Client } from "ssh2";
|
||||
import { WebSocketServer } from "ws";
|
||||
import { getShell } from "./utils";
|
||||
|
||||
function heartbeat() {
|
||||
// @ts-ignore
|
||||
this.isAlive = true;
|
||||
}
|
||||
|
||||
export const setupDockerContainerLogsWebSocketServer = (
|
||||
server: http.Server<typeof http.IncomingMessage, typeof http.ServerResponse>,
|
||||
) => {
|
||||
@@ -48,11 +43,6 @@ export const setupDockerContainerLogsWebSocketServer = (
|
||||
ws.close();
|
||||
return;
|
||||
}
|
||||
|
||||
// @ts-ignore
|
||||
ws.isAlive = true;
|
||||
ws.on("error", console.error);
|
||||
ws.on("pong", heartbeat);
|
||||
try {
|
||||
if (serverId) {
|
||||
const server = await findServerById(serverId);
|
||||
@@ -148,18 +138,4 @@ export const setupDockerContainerLogsWebSocketServer = (
|
||||
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