新增 WebSocket 网关:连接管理、心跳保活、限流与消息路由
This commit is contained in:
@@ -75,6 +75,27 @@ type WechatMiniSettingS struct {
|
||||
AppSecret string
|
||||
}
|
||||
|
||||
// WSSettingS WebSocket 网关配置。
|
||||
// 前半段供 internal/wsgateway 传输层使用;后半段是第二步房间与匹配要用的预留项。
|
||||
type WSSettingS struct {
|
||||
PingInterval int // 心跳间隔(秒):服务端按此周期发 ping,也下发给客户端作为应用层心跳建议值
|
||||
ReadTimeout int // 读超时(秒):超过该时长未收到任何客户端消息即判定死连接并断开
|
||||
WriteTimeout int // 写超时(秒):单次 Write 或 Ping 的最长等待时间
|
||||
MaxMessageBytes int // 单帧上限(字节):超过该大小的消息由库直接拒绝
|
||||
MaxMsgPerSec int // 单连接每秒消息数上限:用于限流,超出即断开
|
||||
SendQueueSize int // 发送队列长度:写满说明客户端消费太慢(慢客户端),直接断开
|
||||
Compression bool // 是否启用 permessage-deflate 压缩
|
||||
MultiDevice bool // 是否允许多设备同时在线:false 表示同账号新连接踢掉旧连接
|
||||
OriginPatterns []string // 允许的 Origin 域名列表:浏览器调试用,小游戏连接通常不带 Origin
|
||||
|
||||
// ===== 以下为房间 / 匹配预留(第二步填充) =====
|
||||
ReconnectGraceSec int // 掉线后保留座位的时长(秒):超时未重连则判负或平局
|
||||
RoomIdleTimeoutSec int // 房间空闲自动关闭的时长(秒)
|
||||
MatchTimeoutSec int // 匹配排队超过该时长(秒)自动取消
|
||||
QueueTickMs int // 匹配队列的扫描间隔(毫秒)
|
||||
MaxRooms int // 同时存在的房间数上限,防止内存失控
|
||||
}
|
||||
|
||||
func (s *Setting) ReadSection(k string, v any) error {
|
||||
err := s.vp.UnmarshalKey(k, v)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user