diff --git a/app/utils/websocket.ts b/app/utils/websocket.ts index e8d907e..f6be471 100644 --- a/app/utils/websocket.ts +++ b/app/utils/websocket.ts @@ -1,9 +1,11 @@ export class WebSocketClient { private socket: WebSocket | null = null private baseUrl: string + private token: string constructor(baseUrl: string, token: string) { this.baseUrl = baseUrl + this.token = token } connect(path: string, params: Record = {}) { @@ -12,6 +14,7 @@ export class WebSocketClient { // 构建参数对象,自动添加 token const queryParams = { + token: this.token, ...params } @@ -30,12 +33,14 @@ export class WebSocketClient { }, onMessage: (callback: (data: any) => void) => { this.socket!.onmessage = (event) => { + try { const data = JSON.parse(event.data) callback(data) } catch (error) { - } + console.error('解析消息失败:', error) + } } }, onClose: (callback: () => void) => {