- export const getWebSocketUrl = (endpoint = '') => {
- const protocol = window.location.protocol;
- const host = window.location.host;
-
- // 自动识别协议:HTTPS用wss,HTTP用ws
- const wsProtocol = protocol === 'https:' ? 'wss:' : 'ws:';
- const websocketPath = import.meta.env.VITE_APP_WEBSOCKET_PATH;
-
- return `${wsProtocol}//${host}${websocketPath}${endpoint}`;
- };
|