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

52 lines
1.0 KiB
TypeScript
Raw Normal View History

2024-11-06 14:53:07 +07:00
import React from "react";
import Terminal from "./terminal";
import { BASE_WS_URL } from "@/lib/api";
2024-11-06 17:32:39 +00:00
import VNCViewer from "./vncviewer";
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) => {
2024-11-07 19:07:41 +00:00
const query = new URLSearchParams(params);
const url = `${BASE_WS_URL}/ws/term?${query}`;
2024-11-06 14:53:07 +07:00
switch (type) {
case "ssh":
2024-11-07 19:07:41 +00:00
return <Terminal url={url} />;
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" ? (
<VNCViewer url={url} />
) : (
2024-11-07 19:07:41 +00:00
<Terminal url={url} />
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;