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)}%

- )}