mirror of
https://github.com/khairul169/vaulterm.git
synced 2025-04-28 16:49:39 +07:00
62 lines
1.4 KiB
TypeScript
62 lines
1.4 KiB
TypeScript
import React from "react";
|
|
import Terminal from "./terminal";
|
|
import VNCViewer from "./vncviewer";
|
|
import { useAuthStore } from "@/stores/auth";
|
|
import { AppServer, useServer } from "@/stores/app";
|
|
import { useWebsocketUrl } from "@/hooks/useWebsocket";
|
|
import ServerStatsBar from "./server-stats-bar";
|
|
|
|
type SSHSessionProps = {
|
|
type: "ssh";
|
|
};
|
|
|
|
type PVESessionProps = {
|
|
type: "pve";
|
|
params: {
|
|
client: "vnc" | "xtermjs";
|
|
};
|
|
};
|
|
|
|
type IncusSessionProps = {
|
|
type: "incus";
|
|
params: {
|
|
client: "vnc" | "xtermjs";
|
|
shell?: string;
|
|
};
|
|
};
|
|
|
|
export type InteractiveSessionProps = {
|
|
label: string;
|
|
params: { hostId: string };
|
|
} & (SSHSessionProps | PVESessionProps | IncusSessionProps);
|
|
|
|
const InteractiveSession = ({ type, params }: InteractiveSessionProps) => {
|
|
const { token } = useAuthStore();
|
|
const ws = useWebsocketUrl({ ...params, sid: token || "" });
|
|
const termUrl = ws("term");
|
|
const statsUrl = ws("stats");
|
|
|
|
switch (type) {
|
|
case "ssh":
|
|
return (
|
|
<>
|
|
<Terminal url={termUrl} />
|
|
<ServerStatsBar url={statsUrl} />
|
|
</>
|
|
);
|
|
|
|
case "pve":
|
|
case "incus":
|
|
return params.client === "vnc" ? (
|
|
<VNCViewer url={termUrl} />
|
|
) : (
|
|
<Terminal url={termUrl} />
|
|
);
|
|
|
|
default:
|
|
throw new Error("Unknown interactive session type");
|
|
}
|
|
};
|
|
|
|
export default InteractiveSession;
|