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

46 lines
962 B
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
params: {
2024-11-06 14:53:07 +07:00
serverId: string;
};
};
2024-11-06 17:32:39 +00:00
type PVESessionProps = {
type: "pve";
params: {
client: "vnc" | "xtermjs";
serverId: string;
};
};
export type InteractiveSessionProps = SSHSessionProps | PVESessionProps;
const InteractiveSession = ({ type, params }: InteractiveSessionProps) => {
const query = new URLSearchParams({
...params,
});
2024-11-06 14:53:07 +07:00
switch (type) {
case "ssh":
2024-11-06 17:32:39 +00:00
return <Terminal wsUrl={`${BASE_WS_URL}/ws/ssh?${query}`} />;
case "pve":
const url = `${BASE_WS_URL}/ws/pve?${query}`;
return params.client === "vnc" ? (
<VNCViewer url={url} />
) : (
<Terminal wsUrl={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;