diff --git a/src/components/cards/computer-card.tsx b/src/components/cards/computer-card.tsx index f04b2fe..df5d394 100644 --- a/src/components/cards/computer-card.tsx +++ b/src/components/cards/computer-card.tsx @@ -1,11 +1,15 @@ import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover"; import { Badge } from "@/components/ui/badge"; -import { Monitor, Wifi, WifiOff, Loader2 } from "lucide-react"; +import { Monitor, Wifi, WifiOff, Loader2, Maximize2, X } from "lucide-react"; import { useState } from "react"; import { cn } from "@/lib/utils"; import { FolderStatusPopover } from "../folder-status-popover"; import { useGetClientFolderStatusForDevice } from "@/hooks/queries"; import type { ClientFolderStatus } from "@/types/folder"; +import { Button } from "@/components/ui/button"; +import { getRemoteDesktopUrl } from "@/services/remote-control.service"; +import { BASE_URL } from "@/config/api"; +import { toast } from "sonner"; export function ComputerCard({ device, position, @@ -17,6 +21,10 @@ export function ComputerCard({ folderStatus?: ClientFolderStatus; isCheckingFolder?: boolean; }) { + const [isConnecting, setIsConnecting] = useState(false); + const [showRemote, setShowRemote] = useState(false); + const [proxyUrl, setProxyUrl] = useState(null); + if (!device) { return (
@@ -33,6 +41,46 @@ export function ComputerCard({ const firstNetworkInfo = device.networkInfos?.[0]; const agentVersion = device.version; + const handleConnect = async () => { + if (!device?.id) { + toast.error("Không tìm thấy nodeID của thiết bị."); + return; + } + + try { + setIsConnecting(true); + const response = await getRemoteDesktopUrl(device.id); + const originalUrl = new URL(response.url); + const pathAndQuery = originalUrl.pathname + originalUrl.search; + const cleanPath = pathAndQuery.startsWith("/") + ? pathAndQuery.substring(1) + : pathAndQuery; + const baseWithoutApi = BASE_URL.replace("/api", ""); + const proxyUrlFull = `${baseWithoutApi}/api/meshcentral/proxy/${cleanPath}`; + + setProxyUrl(proxyUrlFull); + setShowRemote(true); + } catch (error: any) { + toast.error( + error?.response?.data?.message || "Không thể kết nối remote cho thiết bị này." + ); + } finally { + setIsConnecting(false); + } + }; + + const handleCloseRemote = () => { + setShowRemote(false); + setProxyUrl(null); + }; + + const handleFullscreen = () => { + const iframe = document.getElementById(`mesh-iframe-${device.id}`) as HTMLIFrameElement; + if (iframe?.requestFullscreen) { + iframe.requestFullscreen(); + } + }; + function DeviceFolderCheck() { const deviceId = device.id; const room = device.room; @@ -127,6 +175,26 @@ export function ComputerCard({
)} +
+
Kết nối
+ +
+
Kiểm tra thư mục
@@ -148,62 +216,102 @@ export function ComputerCard({ ); return ( - - -
+ <> + +
- {position} -
- - {/* Folder Status Icon */} - {device && !isOffline && ( -
- -
- )} - - - {firstNetworkInfo?.ipAddress && ( -
- {firstNetworkInfo.ipAddress} - {agentVersion && ( -
- v{agentVersion} -
- )} -
- )} -
- - {isOffline ? "Off" : "On"} - + {position} +
+ + {/* Folder Status Icon */} + {device && !isOffline && ( +
+ +
+ )} + + + {firstNetworkInfo?.ipAddress && ( +
+ {firstNetworkInfo.ipAddress} + {agentVersion && ( +
+ v{agentVersion} +
+ )} +
+ )} +
+ + {isOffline ? "Off" : "On"} + +
+
+
+ + + +
+ + {showRemote && proxyUrl && ( +
+
+
+

Remote Session - {device.id}

+
+ + +
+
+