chore: 升级 rust 到 1.93.1,移除 ws 中的一些无用变量 (#650)
This commit is contained in:
@@ -1,3 +1,3 @@
|
|||||||
[toolchain]
|
[toolchain]
|
||||||
channel = "1.93.0"
|
channel = "1.93.1"
|
||||||
components = ["clippy"]
|
components = ["clippy"]
|
||||||
|
|||||||
@@ -26,13 +26,11 @@ interface ClientEvent {
|
|||||||
type LogsCallback = (data: string) => void;
|
type LogsCallback = (data: string) => void;
|
||||||
type TasksCallback = (data: TaskStatus) => void;
|
type TasksCallback = (data: TaskStatus) => void;
|
||||||
type SysInfoCallback = (data: SysInfo) => void;
|
type SysInfoCallback = (data: SysInfo) => void;
|
||||||
type ErrorCallback = (error: Event) => void;
|
|
||||||
|
|
||||||
export class WebSocketManager {
|
export class WebSocketManager {
|
||||||
private static instance: WebSocketManager;
|
private static instance: WebSocketManager;
|
||||||
private socket: WebSocket | null = null;
|
private socket: WebSocket | null = null;
|
||||||
private connected = false;
|
private connected = false;
|
||||||
private connecting = false;
|
|
||||||
private reconnectTimer: ReturnType<typeof setTimeout> | null = null;
|
private reconnectTimer: ReturnType<typeof setTimeout> | null = null;
|
||||||
private reconnectAttempts = 0;
|
private reconnectAttempts = 0;
|
||||||
private maxReconnectAttempts = 5;
|
private maxReconnectAttempts = 5;
|
||||||
@@ -41,7 +39,6 @@ export class WebSocketManager {
|
|||||||
private logsSubscribers: Set<LogsCallback> = new Set();
|
private logsSubscribers: Set<LogsCallback> = new Set();
|
||||||
private tasksSubscribers: Set<TasksCallback> = new Set();
|
private tasksSubscribers: Set<TasksCallback> = new Set();
|
||||||
private sysInfoSubscribers: Set<SysInfoCallback> = new Set();
|
private sysInfoSubscribers: Set<SysInfoCallback> = new Set();
|
||||||
private errorSubscribers: Set<ErrorCallback> = new Set();
|
|
||||||
|
|
||||||
private subscribedEvents: Set<EventType> = new Set();
|
private subscribedEvents: Set<EventType> = new Set();
|
||||||
private connectionPromise: Promise<void> | null = null;
|
private connectionPromise: Promise<void> | null = null;
|
||||||
@@ -61,7 +58,6 @@ export class WebSocketManager {
|
|||||||
if (this.connectionPromise) return this.connectionPromise;
|
if (this.connectionPromise) return this.connectionPromise;
|
||||||
|
|
||||||
this.connectionPromise = new Promise((resolve, reject) => {
|
this.connectionPromise = new Promise((resolve, reject) => {
|
||||||
this.connecting = true;
|
|
||||||
const token = api.getAuthToken() || '';
|
const token = api.getAuthToken() || '';
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -73,7 +69,6 @@ export class WebSocketManager {
|
|||||||
);
|
);
|
||||||
this.socket.onopen = () => {
|
this.socket.onopen = () => {
|
||||||
this.connected = true;
|
this.connected = true;
|
||||||
this.connecting = false;
|
|
||||||
this.reconnectAttempts = 0;
|
this.reconnectAttempts = 0;
|
||||||
this.connectionPromise = null;
|
this.connectionPromise = null;
|
||||||
this.resubscribeEvents();
|
this.resubscribeEvents();
|
||||||
@@ -84,20 +79,17 @@ export class WebSocketManager {
|
|||||||
|
|
||||||
this.socket.onclose = () => {
|
this.socket.onclose = () => {
|
||||||
this.connected = false;
|
this.connected = false;
|
||||||
this.connecting = false;
|
|
||||||
this.connectionPromise = null;
|
this.connectionPromise = null;
|
||||||
this.scheduleReconnect();
|
this.scheduleReconnect();
|
||||||
};
|
};
|
||||||
|
|
||||||
this.socket.onerror = (error) => {
|
this.socket.onerror = (error) => {
|
||||||
console.error('WebSocket error:', error);
|
console.error('WebSocket error:', error);
|
||||||
this.connecting = false;
|
|
||||||
this.connectionPromise = null;
|
this.connectionPromise = null;
|
||||||
reject(error);
|
reject(error);
|
||||||
toast.error('WebSocket 连接发生错误,请检查网络或稍后重试');
|
toast.error('WebSocket 连接发生错误,请检查网络或稍后重试');
|
||||||
};
|
};
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.connecting = false;
|
|
||||||
this.connectionPromise = null;
|
this.connectionPromise = null;
|
||||||
reject(error);
|
reject(error);
|
||||||
console.error('Failed to create WebSocket:', error);
|
console.error('Failed to create WebSocket:', error);
|
||||||
@@ -273,7 +265,6 @@ export class WebSocketManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.connected = false;
|
this.connected = false;
|
||||||
this.connecting = false;
|
|
||||||
this.connectionPromise = null;
|
this.connectionPromise = null;
|
||||||
this.subscribedEvents.clear();
|
this.subscribedEvents.clear();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user