重启之后清除登录信息
This commit is contained in:
@@ -6,16 +6,19 @@ import { Notification } from "electron";
|
||||
|
||||
class WebSocketClient {
|
||||
constructor(options = {}) {
|
||||
this.reconnectInterval = 5000; // 重连间隔时间
|
||||
this.reconnectInterval = options.reconnectInterval || 5000; // 重连间隔时间
|
||||
this.lockReconnect = false;
|
||||
this.ws = null;
|
||||
this.pingTimeout = null;
|
||||
this.reconnectAttempts = 0;
|
||||
this.messageHandlers = new Map();
|
||||
this.isConnected = false;
|
||||
this.options = options;
|
||||
|
||||
// 初始化时立即创建连接
|
||||
this.createConnect();
|
||||
// 延迟创建连接,避免在应用启动时立即连接
|
||||
setTimeout(() => {
|
||||
this.createConnect();
|
||||
}, 1000);
|
||||
}
|
||||
|
||||
createConnect() {
|
||||
@@ -26,10 +29,10 @@ class WebSocketClient {
|
||||
|
||||
// 检查必要的连接信息是否存在
|
||||
if (!apiUrl || !userInfo || !token) {
|
||||
logger.error("WebSocket连接信息不完整,等待重试");
|
||||
logger.error("apiUrl:", apiUrl);
|
||||
logger.error("userInfo:", userInfo);
|
||||
logger.error("token:", token);
|
||||
logger.info("WebSocket连接信息不完整,等待重试");
|
||||
logger.info("apiUrl:", apiUrl);
|
||||
logger.info("userInfo:", userInfo);
|
||||
logger.info("token:", token);
|
||||
this.scheduleReconnect();
|
||||
return;
|
||||
}
|
||||
@@ -92,10 +95,8 @@ class WebSocketClient {
|
||||
this.ws = new WebSocket(this.url, token, this.options);
|
||||
|
||||
this.ws.on('open', () => {
|
||||
logger.info('😀😀😀😀 WebSocket connect create ok 😀😀😀😀');
|
||||
logger.info('😀😀😀😀 WebSocket connect create ok 😀😀😀😀');
|
||||
logger.info('😀😀😀😀 WebSocket connect create ok 😀😀😀😀');
|
||||
logger.info('WebSocket protocol:', this.ws.protocol); // 添加协议日志
|
||||
logger.info('WebSocket 连接成功');
|
||||
logger.info('WebSocket protocol:', this.ws.protocol);
|
||||
this.isConnected = true;
|
||||
this.reconnectAttempts = 0;
|
||||
this.lockReconnect = false;
|
||||
@@ -105,8 +106,19 @@ class WebSocketClient {
|
||||
|
||||
this.ws.on('message', (data) => {
|
||||
try {
|
||||
logger.info('收到消息:', data.toString());
|
||||
const message = JSON.parse(data);
|
||||
const messageStr = data.toString();
|
||||
const message = JSON.parse(messageStr);
|
||||
|
||||
// 减少心跳消息的日志打印
|
||||
if (message.cmd === 'heartcheck') {
|
||||
// 心跳消息不打印日志,或者只在调试模式下打印
|
||||
if (process.env.NODE_ENV === 'development') {
|
||||
logger.debug('收到心跳消息');
|
||||
}
|
||||
} else {
|
||||
logger.info('收到消息:', messageStr);
|
||||
}
|
||||
|
||||
this.handleMessage(message);
|
||||
} catch (error) {
|
||||
logger.error('消息解析错误:', error);
|
||||
|
||||
Reference in New Issue
Block a user