YingXingAI/config/websocket.config.js

101 lines
2.3 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 相关配置
*/
// 根据环境选择 WebSocket 地址
const getWebSocketUrl = () => {
// #ifdef H5
// H5 开发环境
if (process.env.NODE_ENV === 'development') {
return 'ws://localhost:8082/ws/chat'
}
// H5 生产环境
return 'wss://120.55.234.65:8082/ws/chat'
// #endif
// #ifdef MP-WEIXIN
// 小程序必须使用 wss加密连接
return 'wss://120.55.234.65:8082/ws/chat'
// #endif
// #ifdef APP-PLUS
// App 可以使用 ws 或 wss
return 'wss://120.55.234.65:8082/ws/chat'
// #endif
// 默认地址
return 'ws://120.55.234.65:8082/ws/chat'
}
export default {
// WebSocket 服务器地址(动态获取)
url: getWebSocketUrl(),
// 重连配置
reconnect: {
enabled: true, // 是否启用自动重连
maxAttempts: 10, // 最大重连次数
interval: 3000, // 重连间隔(毫秒)
incrementInterval: true, // 是否递增重连间隔
maxInterval: 30000 // 最大重连间隔
},
// 心跳配置
heartbeat: {
enabled: true, // 是否启用心跳
interval: 30000, // 心跳间隔(毫秒)
timeout: 10000, // 心跳超时时间
pingMessage: { // 心跳消息格式
type: 'ping',
timestamp: () => Date.now()
}
},
// 消息队列配置
messageQueue: {
enabled: true, // 是否启用消息队列
maxSize: 100, // 队列最大长度
clearOnConnect: false // 连接成功后是否清空队列
},
// 日志配置
log: {
enabled: true, // 是否启用日志
level: 'info' // 日志级别debug, info, warn, error
},
// 消息类型定义
messageTypes: {
// 文字消息
TEXT: 'text',
// 图片消息
IMAGE: 'image',
// 语音消息
VOICE: 'voice',
// 系统消息
SYSTEM: 'system',
// 心跳
PING: 'ping',
PONG: 'pong',
// 已读回执
READ: 'read',
// 输入中
TYPING: 'typing',
// 人工转接
TRANSFER: 'transfer'
},
// 事件名称定义
events: {
OPEN: 'open',
CLOSE: 'close',
ERROR: 'error',
MESSAGE: 'message',
RECONNECT: 'reconnect',
RECONNECT_FAILED: 'reconnect_failed'
}
}