From da3e4f106787a563785ffe42c4543b2672a34bdf Mon Sep 17 00:00:00 2001 From: MatrixSeven Date: Thu, 5 Mar 2026 12:51:50 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=9B=B4=E6=96=B0=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E4=BC=A0=E8=BE=93=E5=8A=9F=E8=83=BD=EF=BC=8C=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E9=80=9F=E5=BA=A6=E5=92=8CETA=E8=AE=A1=E7=AE=97=EF=BC=8C?= =?UTF-8?q?=E4=BC=98=E5=8C=96=E8=BF=9B=E5=BA=A6=E5=9B=9E=E8=B0=83=EF=BC=8C?= =?UTF-8?q?=E5=A2=9E=E5=BC=BA=E7=94=A8=E6=88=B7=E4=BD=93=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/components/WebRTCFileTransfer.tsx | 2 +- .../components/webrtc/WebRTCFileReceive.tsx | 39 +- .../components/webrtc/WebRTCFileUpload.tsx | 36 +- .../connection/useSharedWebRTCManager.ts | 4 + .../connection/useWebRTCDataChannelManager.ts | 67 ++- .../file-transfer/useFileStateManager.ts | 11 +- .../file-transfer/useFileTransferBusiness.ts | 393 +++++++----------- chuan-next/src/types/index.ts | 2 + 8 files changed, 297 insertions(+), 257 deletions(-) diff --git a/chuan-next/src/components/WebRTCFileTransfer.tsx b/chuan-next/src/components/WebRTCFileTransfer.tsx index edd6ffe..86fda3e 100644 --- a/chuan-next/src/components/WebRTCFileTransfer.tsx +++ b/chuan-next/src/components/WebRTCFileTransfer.tsx @@ -181,7 +181,7 @@ export const WebRTCFileTransfer: React.FC = () => { fileName: progressInfo.fileName, progress: progressInfo.progress }); - updateFileProgress(progressInfo.fileId, progressInfo.fileName, progressInfo.progress); + updateFileProgress(progressInfo.fileId, progressInfo.fileName, progressInfo.progress, progressInfo.speed, progressInfo.eta); if (progressInfo.progress >= 100 && mode === 'send') { setCurrentTransferFile(null); } diff --git a/chuan-next/src/components/webrtc/WebRTCFileReceive.tsx b/chuan-next/src/components/webrtc/WebRTCFileReceive.tsx index f290954..d619996 100644 --- a/chuan-next/src/components/webrtc/WebRTCFileReceive.tsx +++ b/chuan-next/src/components/webrtc/WebRTCFileReceive.tsx @@ -25,6 +25,28 @@ const formatFileSize = (bytes: number): string => { return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + ' ' + sizes[i]; }; +const formatSpeed = (bytesPerSecond: number): string => { + if (bytesPerSecond <= 0) return '--'; + const k = 1024; + if (bytesPerSecond < k) return `${bytesPerSecond.toFixed(0)} B/s`; + if (bytesPerSecond < k * k) return `${(bytesPerSecond / k).toFixed(1)} KB/s`; + if (bytesPerSecond < k * k * k) return `${(bytesPerSecond / (k * k)).toFixed(2)} MB/s`; + return `${(bytesPerSecond / (k * k * k)).toFixed(2)} GB/s`; +}; + +const formatETA = (seconds: number): string => { + if (seconds <= 0 || !isFinite(seconds)) return '--'; + if (seconds < 60) return `${Math.ceil(seconds)}秒`; + if (seconds < 3600) { + const m = Math.floor(seconds / 60); + const s = Math.ceil(seconds % 60); + return `${m}分${s > 0 ? s + '秒' : ''}`; + } + const h = Math.floor(seconds / 3600); + const m = Math.ceil((seconds % 3600) / 60); + return `${h}时${m > 0 ? m + '分' : ''}`; +}; + interface WebRTCFileReceiveProps { onJoinRoom: (code: string) => void; files: FileInfo[]; @@ -204,6 +226,8 @@ export function WebRTCFileReceive({ const isCompleted = file.status === 'completed'; const hasDownloadedFile = downloadedFiles?.has(file.id); const currentProgress = file.progress; + const currentSpeed = file.speed; + const currentEta = file.eta; console.log('文件状态:', { fileName: file.name, @@ -226,9 +250,6 @@ export function WebRTCFileReceive({ {hasDownloadedFile && (

✅ 传输完成,点击保存

)} - {isDownloading && ( -

⏳ 传输中...{currentProgress.toFixed(1)}%

- )}