mirror of
https://github.com/Dokploy/dokploy
synced 2025-06-26 18:27:59 +00:00
refactor: update logs listener
This commit is contained in:
@@ -20,9 +20,9 @@ export const DockerLogsId: React.FC<Props> = ({
|
|||||||
const [lines, setLines] = React.useState<number>(40);
|
const [lines, setLines] = React.useState<number>(40);
|
||||||
const wsRef = useRef<WebSocket | null>(null); // Ref to hold WebSocket instance
|
const wsRef = useRef<WebSocket | null>(null); // Ref to hold WebSocket instance
|
||||||
|
|
||||||
const createTerminal = (): Terminal => {
|
useEffect(() => {
|
||||||
if (containerId === "select-a-containe") {
|
if (containerId === "select-a-containe") {
|
||||||
return new Terminal();
|
return;
|
||||||
}
|
}
|
||||||
const container = document.getElementById(id);
|
const container = document.getElementById(id);
|
||||||
if (container) {
|
if (container) {
|
||||||
@@ -72,16 +72,9 @@ export const DockerLogsId: React.FC<Props> = ({
|
|||||||
termi.write(`Connection closed!\nReason: ${e.reason}\n`);
|
termi.write(`Connection closed!\nReason: ${e.reason}\n`);
|
||||||
wsRef.current = null;
|
wsRef.current = null;
|
||||||
};
|
};
|
||||||
|
|
||||||
return termi;
|
|
||||||
};
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
createTerminal();
|
|
||||||
|
|
||||||
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;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -62,7 +62,7 @@ export const setupDockerContainerLogsWebSocketServer = (
|
|||||||
}
|
}
|
||||||
stream
|
stream
|
||||||
.on("close", () => {
|
.on("close", () => {
|
||||||
console.log("Connection closed ✅");
|
console.log("Connection closed ✅ Container Logs");
|
||||||
client.end();
|
client.end();
|
||||||
ws.close();
|
ws.close();
|
||||||
})
|
})
|
||||||
@@ -86,7 +86,7 @@ export const setupDockerContainerLogsWebSocketServer = (
|
|||||||
privateKey: server.sshKey?.privateKey,
|
privateKey: server.sshKey?.privateKey,
|
||||||
});
|
});
|
||||||
ws.on("close", () => {
|
ws.on("close", () => {
|
||||||
console.log("Connection closed ✅, From WS");
|
console.log("Connection closed ✅, From Container Logs WS");
|
||||||
client.end();
|
client.end();
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -105,8 +105,8 @@ export const setupDeploymentLogsWebSocketServer = (
|
|||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
// const errorMessage = error?.message as unknown as string;
|
// const errorMessage = error?.message as unknown as string;
|
||||||
ws.send(errorMessage);
|
// ws.send(errorMessage);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user