Files
xk-doctor-wx/config/websocket.js
李琦 eacca1bf7b 1. 开方线上功能基本完成
2. 修复了一些抽屉组件的滑动失效问题
2026-05-14 14:29:51 +08:00

74 lines
1.7 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**
* WebSocket配置文件
* 统一管理WebSocket相关配置环境与 config/app-env.js 一致)
*/
import { getDoctorWxWsUrls, isDoctorWxDev } from './app-env.js';
const wsUrls = getDoctorWxWsUrls();
/**
* WebSocket配置
*/
export const websocketConfig = {
/**
* WebSocket URL配置
* dev: 开发环境WebSocket地址
* prod: 生产环境WebSocket地址
*/
url: wsUrls,
/**
* 获取当前环境的WebSocket URL
* @returns {string} WebSocket URL
*/
getUrl() {
return isDoctorWxDev() ? wsUrls.dev : wsUrls.prod;
},
/**
* 由 WebSocket URL 推导 IM 服务 HTTP 基址(与 WS 同 host用于 Go API
* 例ws://127.0.0.1:12080/ws -> http://127.0.0.1:12080
*/
getHttpBaseUrl() {
const ws = this.getUrl();
if (!ws || typeof ws !== 'string') return '';
let base = ws
.replace(/^wss:\/\//i, 'https://')
.replace(/^ws:\/\//i, 'http://');
base = base.replace(/\/?ws\/?$/i, '');
return base.replace(/\/+$/, '') || base;
},
/** Go IMPOST /api/send-to-user */
getSendToUserApiUrl() {
const base = this.getHttpBaseUrl();
if (!base) return '';
return `${base}/api/send-to-user`;
},
/**
* 重连配置
*/
reconnect: {
maxAttempts: 5, // 最大重连次数
initialDelay: 1000, // 初始重连延迟(毫秒)
maxDelay: 30000 // 最大重连延迟(毫秒)
},
/**
* 心跳配置
*/
heartbeat: {
interval: 300000 // 心跳间隔毫秒5分钟
},
/**
* 用户标识配置
*/
user: {
prefix: 'doctor-', // 医生小程序使用doctor-前缀
platform: 'doctor-miniprogram' // 平台标识(医生小程序)
}
};