mirror of
https://github.com/luckfox-eng29/kvm.git
synced 2026-06-02 19:32:58 +02:00
Improve error handling when RTCPeerConnection throws (#289)
* fix(WebRTC): improve error handling during peer connection creation and add connection error overlay * refactor: update peer connection state handling and improve type definitions across components
This commit is contained in:
@@ -36,7 +36,7 @@ export default function DashboardNavbar({
|
||||
picture,
|
||||
kvmName,
|
||||
}: NavbarProps) {
|
||||
const peerConnectionState = useRTCStore(state => state.peerConnection?.connectionState);
|
||||
const peerConnectionState = useRTCStore(state => state.peerConnectionState);
|
||||
const setUser = useUserStore(state => state.setUser);
|
||||
const navigate = useNavigate();
|
||||
const onLogout = useCallback(async () => {
|
||||
|
||||
@@ -9,19 +9,22 @@ const PeerConnectionStatusMap = {
|
||||
failed: "Connection failed",
|
||||
closed: "Closed",
|
||||
new: "Connecting",
|
||||
};
|
||||
} as Record<RTCPeerConnectionState | "error" | "closing", string>;
|
||||
|
||||
export type PeerConnections = keyof typeof PeerConnectionStatusMap;
|
||||
|
||||
type StatusProps = Record<PeerConnections, {
|
||||
type StatusProps = Record<
|
||||
PeerConnections,
|
||||
{
|
||||
statusIndicatorClassName: string;
|
||||
}>;
|
||||
}
|
||||
>;
|
||||
|
||||
export default function PeerConnectionStatusCard({
|
||||
state,
|
||||
title,
|
||||
}: {
|
||||
state?: PeerConnections;
|
||||
state?: RTCPeerConnectionState | null;
|
||||
title?: string;
|
||||
}) {
|
||||
if (!state) return null;
|
||||
|
||||
@@ -8,11 +8,14 @@ import { HidState } from "@/hooks/stores";
|
||||
|
||||
type USBStates = HidState["usbState"];
|
||||
|
||||
type StatusProps = Record<USBStates, {
|
||||
type StatusProps = Record<
|
||||
USBStates,
|
||||
{
|
||||
icon: React.FC<{ className: string | undefined }>;
|
||||
iconClassName: string;
|
||||
statusIndicatorClassName: string;
|
||||
}>;
|
||||
}
|
||||
>;
|
||||
|
||||
const USBStateMap: Record<USBStates, string> = {
|
||||
configured: "Connected",
|
||||
@@ -27,9 +30,8 @@ export default function USBStateStatus({
|
||||
peerConnectionState,
|
||||
}: {
|
||||
state: USBStates;
|
||||
peerConnectionState?: RTCPeerConnectionState;
|
||||
peerConnectionState: RTCPeerConnectionState | null;
|
||||
}) {
|
||||
|
||||
const StatusCardProps: StatusProps = {
|
||||
configured: {
|
||||
icon: ({ className }) => (
|
||||
|
||||
Reference in New Issue
Block a user