mirror of
https://github.com/MatrixSeven/file-transfer-go.git
synced 2026-05-20 04:17:29 +08:00
feat: 修复ws主动断开问题|精简连接逻辑,移除不必要的状态和日志
This commit is contained in:
@@ -50,11 +50,7 @@ export const WebRTCFileTransfer: React.FC = () => {
|
|||||||
isConnected,
|
isConnected,
|
||||||
isConnecting,
|
isConnecting,
|
||||||
isWebSocketConnected,
|
isWebSocketConnected,
|
||||||
connectionError,
|
|
||||||
isTransferring,
|
|
||||||
progress,
|
|
||||||
error,
|
error,
|
||||||
receivedFiles,
|
|
||||||
connect,
|
connect,
|
||||||
disconnect,
|
disconnect,
|
||||||
sendFile,
|
sendFile,
|
||||||
|
|||||||
@@ -42,10 +42,11 @@ export const WebRTCTextReceiver: React.FC<WebRTCTextReceiverProps> = ({
|
|||||||
// 连接所有传输通道
|
// 连接所有传输通道
|
||||||
const connectAll = useCallback(async (code: string, role: 'sender' | 'receiver') => {
|
const connectAll = useCallback(async (code: string, role: 'sender' | 'receiver') => {
|
||||||
console.log('=== 连接所有传输通道 ===', { code, role });
|
console.log('=== 连接所有传输通道 ===', { code, role });
|
||||||
await Promise.all([
|
await connection.connect(code, role);
|
||||||
textTransfer.connect(code, role),
|
// await Promise.all([
|
||||||
fileTransfer.connect(code, role)
|
// textTransfer.connect(code, role),
|
||||||
]);
|
// fileTransfer.connect(code, role)
|
||||||
|
// ]);
|
||||||
}, [textTransfer, fileTransfer]);
|
}, [textTransfer, fileTransfer]);
|
||||||
|
|
||||||
// 是否有任何连接
|
// 是否有任何连接
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
import { UrlSource } from './../../../node_modules/lightningcss/node/ast.d';
|
|
||||||
import { useState, useRef, useCallback } from 'react';
|
import { useState, useRef, useCallback } from 'react';
|
||||||
import { config } from '@/lib/config';
|
import { config } from '@/lib/config';
|
||||||
|
|
||||||
@@ -85,28 +84,28 @@ export function useSharedWebRTCManager(): WebRTCConnection {
|
|||||||
|
|
||||||
// 清理连接
|
// 清理连接
|
||||||
const cleanup = useCallback(() => {
|
const cleanup = useCallback(() => {
|
||||||
console.log('[SharedWebRTC] 清理连接');
|
// console.log('[SharedWebRTC] 清理连接');
|
||||||
if (timeoutRef.current) {
|
// if (timeoutRef.current) {
|
||||||
clearTimeout(timeoutRef.current);
|
// clearTimeout(timeoutRef.current);
|
||||||
timeoutRef.current = null;
|
// timeoutRef.current = null;
|
||||||
}
|
// }
|
||||||
|
|
||||||
if (dcRef.current) {
|
// if (dcRef.current) {
|
||||||
dcRef.current.close();
|
// dcRef.current.close();
|
||||||
dcRef.current = null;
|
// dcRef.current = null;
|
||||||
}
|
// }
|
||||||
|
|
||||||
if (pcRef.current) {
|
// if (pcRef.current) {
|
||||||
pcRef.current.close();
|
// pcRef.current.close();
|
||||||
pcRef.current = null;
|
// pcRef.current = null;
|
||||||
}
|
// }
|
||||||
|
|
||||||
if (wsRef.current) {
|
// if (wsRef.current) {
|
||||||
wsRef.current.close();
|
// wsRef.current.close();
|
||||||
wsRef.current = null;
|
// wsRef.current = null;
|
||||||
}
|
// }
|
||||||
|
|
||||||
currentRoom.current = null;
|
// currentRoom.current = null;
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
// 创建 Offer
|
// 创建 Offer
|
||||||
|
|||||||
Reference in New Issue
Block a user