This commit is contained in:
2025-12-22 17:08:49 +08:00
parent b023bec261
commit ae16757984

View File

@@ -126,12 +126,13 @@ import type { ChatRoomVO, ChatRoomMessageVO, TbChatRoomMessageDTO } from 'shared
import SockJS from 'sockjs-client'
import { Client } from '@stomp/stompjs'
// WebSocket配置 (通过网关代理访问workcase服务)
// 原生WebSocket URL (ws://或wss://)
// WebSocket配置 (通过Nginx代理访问网关再到workcase服务)
// SockJS URL (http://)
const getWsUrl = () => {
const token = localStorage.getItem('token') || ''
// 直接连接网关跳过Nginx调试
return `ws://localhost:8180/urban-lifeline/workcase/ws/chat?token=${encodeURIComponent(token)}`
const protocol = window.location.protocol
const host = window.location.host
return `${protocol}//${host}/api/urban-lifeline/workcase/ws/chat-sockjs?token=${encodeURIComponent(token)}`
}
// STOMP客户端
@@ -304,16 +305,16 @@ const formatTime = (time: string | null | undefined) => {
// ==================== WebSocket连接管理 ====================
// 初始化WebSocket连接使用原生WebSocket降级)
// 初始化WebSocket连接支持SockJS降级)
const initWebSocket = () => {
const token = localStorage.getItem('token') || ''
const wsUrl = getWsUrl()
console.log('WebSocket连接URL:', wsUrl)
// 创建STOMP客户端使用原生WebSocket
// 创建STOMP客户端使用SockJS支持降级
stompClient = new Client({
brokerURL: wsUrl, // 使用原生WebSocket URL
webSocketFactory: () => new SockJS(wsUrl),
connectHeaders: {
Authorization: `Bearer ${token}`
},