Merge remote-tracking branch 'origin/master'
This commit is contained in:
@@ -246,13 +246,13 @@ export default class SocketService {
|
||||
public connect(): Promise<void> | void {
|
||||
// 检查浏览器支持
|
||||
if (!window.WebSocket) {
|
||||
console.log('您的浏览器不支持WebSocket');
|
||||
// console.log('您的浏览器不支持WebSocket');
|
||||
return;
|
||||
}
|
||||
|
||||
// 防止重复连接
|
||||
if (this.connectionStatus === ConnectionStatus.CONNECTING || this.connected) {
|
||||
console.warn('WebSocket已连接或正在连接中');
|
||||
// console.warn('WebSocket已连接或正在连接中');
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -263,7 +263,7 @@ export default class SocketService {
|
||||
this.setupEventHandlersLegacy();
|
||||
} catch (error) {
|
||||
this.connectionStatus = ConnectionStatus.ERROR;
|
||||
console.error('WebSocket连接失败:', error);
|
||||
//console.error('WebSocket连接失败:', error);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -276,14 +276,14 @@ export default class SocketService {
|
||||
// 检查浏览器支持
|
||||
if (!window.WebSocket) {
|
||||
const error = '您的浏览器不支持WebSocket';
|
||||
console.error(error);
|
||||
//console.error(error);
|
||||
reject(new Error(error));
|
||||
return;
|
||||
}
|
||||
|
||||
// 防止重复连接
|
||||
if (this.connectionStatus === ConnectionStatus.CONNECTING || this.connected) {
|
||||
console.warn('WebSocket已连接或正在连接中');
|
||||
//console.warn('WebSocket已连接或正在连接中');
|
||||
resolve();
|
||||
return;
|
||||
}
|
||||
@@ -307,11 +307,11 @@ export default class SocketService {
|
||||
*/
|
||||
public registerCallBack<T = any>(messageType: string, callback: CallbackFunction<T>): void {
|
||||
if (!messageType || typeof callback !== 'function') {
|
||||
console.error('注册回调函数参数无效');
|
||||
//console.error('注册回调函数参数无效');
|
||||
return;
|
||||
}
|
||||
this.callBackMapping[messageType] = callback;
|
||||
console.log(`注册消息处理器: ${messageType}`);
|
||||
// console.log(`注册消息处理器: ${messageType}`);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -321,7 +321,7 @@ export default class SocketService {
|
||||
public unRegisterCallBack(messageType: string): void {
|
||||
if (this.callBackMapping[messageType]) {
|
||||
delete this.callBackMapping[messageType];
|
||||
console.log(`注销消息处理器: ${messageType}`);
|
||||
//console.log(`注销消息处理器: ${messageType}`);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -354,10 +354,10 @@ export default class SocketService {
|
||||
const message = typeof data === 'string' ? data : JSON.stringify(data);
|
||||
this.ws.send(message);
|
||||
|
||||
console.log('发送消息:', message);
|
||||
//console.log('发送消息:', message);
|
||||
resolve();
|
||||
} catch (error) {
|
||||
console.error('发送消息失败:', error);
|
||||
//console.error('发送消息失败:', error);
|
||||
reject(error);
|
||||
}
|
||||
});
|
||||
@@ -367,7 +367,7 @@ export default class SocketService {
|
||||
* 关闭WebSocket连接
|
||||
*/
|
||||
public closeWs(): void {
|
||||
console.log('正在关闭WebSocket连接...');
|
||||
//console.log('正在关闭WebSocket连接...');
|
||||
|
||||
// 清理心跳
|
||||
this.clearHeartbeat();
|
||||
@@ -383,7 +383,7 @@ export default class SocketService {
|
||||
this.connectRetryCount = 0;
|
||||
this.sendRetryCount = 0;
|
||||
|
||||
console.log('WebSocket连接已关闭');
|
||||
//console.log('WebSocket连接已关闭');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -447,7 +447,7 @@ export default class SocketService {
|
||||
// 连接成功事件
|
||||
this.ws.onopen = () => {
|
||||
ElMessage.success("WebSocket连接服务端成功");
|
||||
console.log('WebSocket连接成功');
|
||||
// console.log('WebSocket连接成功');
|
||||
this.connectionStatus = ConnectionStatus.CONNECTED;
|
||||
this.connectRetryCount = 0;
|
||||
this.startHeartbeat();
|
||||
@@ -456,7 +456,7 @@ export default class SocketService {
|
||||
|
||||
// 连接关闭事件
|
||||
this.ws.onclose = (event: CloseEvent) => {
|
||||
console.log('WebSocket连接关闭', event.code, event.reason);
|
||||
//console.log('WebSocket连接关闭', event.code, event.reason);
|
||||
this.connectionStatus = ConnectionStatus.DISCONNECTED;
|
||||
this.clearHeartbeat();
|
||||
|
||||
@@ -489,7 +489,7 @@ export default class SocketService {
|
||||
// 连接成功事件
|
||||
this.ws.onopen = () => {
|
||||
ElMessage.success("webSocket连接服务端成功了");
|
||||
console.log('连接服务端成功了');
|
||||
// console.log('连接服务端成功了');
|
||||
this.connectionStatus = ConnectionStatus.CONNECTED;
|
||||
this.connectRetryCount = 0;
|
||||
this.startHeartbeat();
|
||||
@@ -497,7 +497,7 @@ export default class SocketService {
|
||||
|
||||
// 连接关闭事件
|
||||
this.ws.onclose = (event: CloseEvent) => {
|
||||
console.log('连接webSocket服务端关闭');
|
||||
// console.log('连接webSocket服务端关闭');
|
||||
this.connectionStatus = ConnectionStatus.DISCONNECTED;
|
||||
this.clearHeartbeat();
|
||||
|
||||
@@ -530,7 +530,7 @@ export default class SocketService {
|
||||
|
||||
// 心跳响应处理
|
||||
if (event.data === 'over') {
|
||||
console.log(`${new Date().toLocaleTimeString()} - 收到心跳响应`);
|
||||
// console.log(`${new Date().toLocaleTimeString()} - 收到心跳响应`);
|
||||
this.lastResponseHeartTime = Date.now();
|
||||
return;
|
||||
}
|
||||
@@ -553,7 +553,7 @@ export default class SocketService {
|
||||
}
|
||||
} else {
|
||||
// 非JSON格式的消息,作为普通文本处理
|
||||
console.log('收到非JSON格式消息:', event.data);
|
||||
// console.log('收到非JSON格式消息:', event.data);
|
||||
// 可以添加文本消息的处理逻辑
|
||||
if (this.callBackMapping['text']) {
|
||||
this.callBackMapping['text']({
|
||||
@@ -587,7 +587,7 @@ export default class SocketService {
|
||||
|
||||
const delay = this.config.reconnectDelay! * this.connectRetryCount;
|
||||
|
||||
console.log(`尝试第${this.connectRetryCount}次重连,${delay}ms后开始...`);
|
||||
// console.log(`尝试第${this.connectRetryCount}次重连,${delay}ms后开始...`);
|
||||
|
||||
setTimeout(() => {
|
||||
try {
|
||||
@@ -674,7 +674,7 @@ export default class SocketService {
|
||||
*/
|
||||
private sendHeartbeat(): void {
|
||||
if (this.connected && this.ws) {
|
||||
console.log(`${new Date().toLocaleTimeString()} - 发送心跳消息`);
|
||||
// console.log(`${new Date().toLocaleTimeString()} - 发送心跳消息`);
|
||||
this.ws.send('alive');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user