vaulterm/frontend/components/containers/interactive-session.tsx

62 lines
1.4 KiB
TypeScript
Raw Normal View History

2024-11-06 14:53:07 +07:00
import React from "react";
import Terminal from "./terminal";
2024-11-06 17:32:39 +00:00
import VNCViewer from "./vncviewer";
import { useAuthStore } from "@/stores/auth";
2024-11-12 04:43:59 +07:00
import { AppServer, useServer } from "@/stores/app";
2024-11-13 22:45:03 +00:00
import { useWebsocketUrl } from "@/hooks/useWebsocket";
import ServerStatsBar from "./server-stats-bar";
2024-11-06 14:53:07 +07:00
type SSHSessionProps = {
type: "ssh";
};
2024-11-06 17:32:39 +00:00
type PVESessionProps = {
type: "pve";
params: {
client: "vnc" | "xtermjs";
};
};
2024-11-07 04:56:19 +07:00
type IncusSessionProps = {
type: "incus";
params: {
client: "vnc" | "xtermjs";
shell?: string;
};
};
2024-11-08 18:53:30 +00:00
export type InteractiveSessionProps = {
label: string;
params: { hostId: string };
} & (SSHSessionProps | PVESessionProps | IncusSessionProps);
2024-11-06 17:32:39 +00:00
const InteractiveSession = ({ type, params }: InteractiveSessionProps) => {
const { token } = useAuthStore();
2024-11-13 22:45:03 +00:00
const ws = useWebsocketUrl({ ...params, sid: token || "" });
const termUrl = ws("term");
const statsUrl = ws("stats");
2024-11-06 14:53:07 +07:00
switch (type) {
case "ssh":
2024-11-13 22:45:03 +00:00
return (
<>
<Terminal url={termUrl} />
<ServerStatsBar url={statsUrl} />
</>
);
2024-11-06 17:32:39 +00:00
case "pve":
2024-11-07 04:56:19 +07:00
case "incus":
2024-11-06 17:32:39 +00:00
return params.client === "vnc" ? (
2024-11-13 22:45:03 +00:00
<VNCViewer url={termUrl} />
2024-11-06 17:32:39 +00:00
) : (
2024-11-13 22:45:03 +00:00
<Terminal url={termUrl} />
2024-11-06 09:50:41 +00:00
);
2024-11-06 14:53:07 +07:00
default:
throw new Error("Unknown interactive session type");
}
};
export default InteractiveSession;