Documentation
¶
Index ¶
- Variables
- func ObsDefaultStdoutFn(ev *ObsEvent_t)
- func ObsEventType_toString(t ObsEventType_t) string
- type Client
- func (c *Client) CloseForTest()
- func (c *Client) GetClientStatus() ClientStatus_t
- func (c *Client) GetIsStopListen() (isStop bool)
- func (c *Client) GetNeedManualMsg() string
- func (c *Client) GetRoomCount() int
- func (c *Client) GetSendEnterRoomMsgNum() uint32
- func (c *Client) GetSinceLastServerConfirm() time.Duration
- func (c *Client) GetUiStatusToUser() UiStatusToUser_t
- func (c *Client) GetWsDialNum() uint32
- func (c *Client) HasNeed() bool
- func (c *Client) IsConnectedSucc() bool
- func (c *Client) RoomEnter(roomId string, onChangeFn func(ev *RoomOnChange_t)) (leaveFn func())
- func (c *Client) SetIsStopListen(isStop bool)
- func (c *Client) SetWsDialUrl(url string)
- type ClientDeny_t
- type ClientStatusCtx_t
- type ClientStatusType_t
- type ClientStatus_t
- type ClientWsDialReq_t
- type CloseReason_t
- type Cmd_t
- type DenyScope_t
- type Msg_t
- type ObsEventType_t
- type ObsEvent_t
- type RoomEvent_t
- type RoomOnChange_t
- type ServerConn_t
- type ServerManager
- func (s *ServerManager) Close()
- func (s *ServerManager) CloseConnBySessionId(sessionId string, isTemp bool, reason string)
- func (s *ServerManager) FireChange(ev RoomEvent_t)
- func (s *ServerManager) GetSnapshot() ServerSnapshot_t
- func (s *ServerManager) ServeHTTP(w http.ResponseWriter, r *http.Request)
- type ServerOnAccept_ctx_t
- type ServerOnAllow_ctx_t
- type ServerSnapshot_t
- type TimeoutCfg_t
- type UiStatusToUser_t
Constants ¶
This section is empty.
Variables ¶
var ObsDefaultFn func(ev *ObsEvent_t) = ObsDefaultStdoutFn
package 级别的默认观测函数. 初始值为 ObsDefaultStdoutFn. 设置为 nil 表示全局关闭默认观测.
Functions ¶
Types ¶
type Client ¶
type Client struct {
// 第一次连接或者重连时 连接的信息.
// 用回调是为了让调用者可以动态修改 sessionId 参数.
WsDialReqFn func() ClientWsDialReq_t
// 服务端拒绝(连接或房间)的处理回调. 可选.
// 不注册时: 服务端发来 deny -> 客户端判定为对接错误(应修复bug), 断开且不再重连, 后续 RoomEnter 报错.
// 注册后默认行为: 连接级被拒 -> 连接保持/继续重连, 但进/离房间无效果, 新 RoomEnter 本地直接回 OnDenyFn(不找服务端), 重连时复位;
// 房间级被拒 -> 该房间留在 intent 里(随重连自动重试), 只是当前不更新数据.
OnDenyFn func(ev *ClientDeny_t)
TimeoutCfg zlibSync.Var[TimeoutCfg_t]
// 观测事件回调. nil 表示使用 ObsDefaultFn. 设置为空函数表示关闭观测.
ObsFn func(ev *ObsEvent_t)
// websocket message 最大读取字节数. 0表示使用默认值64KB, 负值 panic(_init 会把默认值写回本字段).
// 必须 >= 服务端 WriteBufMaxBytes(单个 websocket message 最大可达该值), 否则会因消息过大断开.
ReadMsgMaxBytes int
// 发起 websocket 升级请求(含 tls 握手)用的 http.Client. 可选.
// nil: 用本库内置的, 按 ClientWsDialReq_t.EnableTlsVerify 决定验不验证 tls 证书.
// 非 nil: 完全以本字段为准, ClientWsDialReq_t.EnableTlsVerify 被忽略(tls 由本 http.Client 的
// Transport.TLSClientConfig 决定). 用途: 自定义 tls.Config(公钥锁定/自定义 CA/双向认证)、http 代理、自定义 dialer.
// 生命周期完全由调用者负责: 本库只读取和使用它, 不持有语义, 也不关闭它 —— CloseForTest 不会动它,
// 用完后的连接清理(CloseIdleConnections)由调用者自己做.
// 必须在第一次 RoomEnter 之前设置好, 之后不再修改(无锁保护, 每次(重)连时直接读本字段).
// 不用担心 HTTP/2: websocket 升级只能走 HTTP/1.1, 而 Go 的 net/http 已内建处理 —— 带
// "Connection: upgrade"+"Upgrade: websocket" 的请求会被 Request.requiresHTTP1() 标成 onlyH1,
// 握手时清空 ALPN 且不复用已缓存的 h2 连接. 所以标准 *http.Transport 随便传(开着
// ForceAttemptHTTP2 也行). 只有塞进只会 h2 的自定义 RoundTripper(如 x/net/http2.Transport)才会废.
HttpClient *http.Client
// contains filtered or unexported fields
}
* 客户端连接状态分为:
- 正常连接. (已确认正常连接上服务器)(注意,可能没有需求)
- 无需求 (没有连接上,且没有需求)
- 网络失败 (上次网络连接失败,并且有需求,并且当前没有连上)
- 连接中 (上次没有连接失败,有需求,并且当前没有连上)
- 已关闭 (调用者要求关闭本对象,后续一定不会再连接了)
func (*Client) CloseForTest ¶
func (c *Client) CloseForTest()
func (*Client) GetClientStatus ¶
func (c *Client) GetClientStatus() ClientStatus_t
func (*Client) GetIsStopListen ¶
func (*Client) GetNeedManualMsg ¶
获取 needManual 状态的原因文本. 空字符串表示不在 needManual 状态.
func (*Client) GetSendEnterRoomMsgNum ¶
func (*Client) GetSinceLastServerConfirm ¶
获取距离上次收到服务端有效消息的时间. 从未收到过时返回 -1.
func (*Client) GetUiStatusToUser ¶
func (c *Client) GetUiStatusToUser() UiStatusToUser_t
获取当前面向终端用户的ui状态. 判断优先级: needManual > offline > syncing > synced.
func (*Client) GetWsDialNum ¶
func (*Client) IsConnectedSucc ¶
func (*Client) RoomEnter ¶
func (c *Client) RoomEnter(roomId string, onChangeFn func(ev *RoomOnChange_t)) (leaveFn func())
客户端加入房间. 本函数 不会报错,不会阻塞. 请注意不要向已经关闭的客户端发送 roomEnter, 此时该请求会被忽略.
func (*Client) SetIsStopListen ¶
func (*Client) SetWsDialUrl ¶
type ClientDeny_t ¶
服务端拒绝事件, 传给 OnDenyFn. IsConn=true 表示连接级拒绝(identity 认证失败); IsConn=false 表示房间级拒绝(进入 RoomId 被拒).
type ClientStatusCtx_t ¶
type ClientStatusCtx_t struct {
Type ClientStatusType_t
LastCloseReason CloseReason_t
LastCloseLog string
CanSetCloseReason bool // 是否可以设置关闭原因(开始链接时,配置为 true,设置过第一个 关闭原因后配置为 false.)
// contains filtered or unexported fields
}
最后关闭原因日志.
type ClientStatusType_t ¶
type ClientStatusType_t string
表示当前客户端的状态.
const ClientStatus_closeForTest ClientStatusType_t = "closeForTest" // 测试关闭了链接.
const ClientStatus_connected ClientStatusType_t = "connected" // 客户端认为自己已经连上了,没有断开,并且当前有需求.
const ClientStatus_connectedNoNeed ClientStatusType_t = "connectedNoNeed" // 当前没有需求,链接上了 (在 ClientNoNeedIdleDur 时间内)
const ClientStatus_dialing ClientStatusType_t = "dialing" // 链接中
const ClientStatus_noConnectNoNeed ClientStatusType_t = "noConnectNoNeed" // 当前没有需求,并且没有链接(注意有需求了还能链接)
const ClientStatus_stopListen ClientStatusType_t = "stopListen" // 停止监听
const ClientStatus_waitReconnect ClientStatusType_t = "waitReconnect" // 等待重连 (在 ClientReconnectMinDur 时间内)
type ClientStatus_t ¶
type ClientStatus_t struct {
Type ClientStatusType_t // 当前状态
HasNeed bool // 当前是否有需求.
LastCloseReason CloseReason_t // 最后关闭原因.(注意当前处于链接中的时候,这两项没有)
LastCloseLog string // 最后关闭时的详细信息.(注意当前处于链接中的时候,这两项没有)
IsStopListen bool // 当前是否停止监听.
}
type ClientWsDialReq_t ¶
type CloseReason_t ¶
type CloseReason_t string
const CloseReason_clientNoNeed CloseReason_t = "clientNoNeed"
const CloseReason_closeByReadTimeout CloseReason_t = "closeByReadTimeout"
const CloseReason_dialFail CloseReason_t = "dialFail"
const CloseReason_protocolNoMatch CloseReason_t = "protocolNoMatch"
const CloseReason_readFail CloseReason_t = "readFail"
const CloseReason_serverCloseConnTemp CloseReason_t = "serverCloseConnTemp"
const CloseReason_testClose CloseReason_t = "testClose"
const CloseReason_writeFail CloseReason_t = "writeFail"
type Cmd_t ¶
type Cmd_t = uint8
const Cmd_closeConn Cmd_t = 9 // 服务端->客户端. 要求客户端关闭连接. IsTemp+Reason.
const Cmd_connAllow Cmd_t = 7 // 服务端->客户端. 连接已批准. 携带 AuthEnabled(服务端是否启用认证).
const Cmd_deny Cmd_t = 8 // 服务端->客户端. 拒绝(连接或房间). DenyScope+RoomId+Reason.
const Cmd_identity Cmd_t = 6 // 客户端->服务端. 连接后首包. 携带 opaque identity 字符串. 重连重发.
const Cmd_ping Cmd_t = 1
const Cmd_roomEnter Cmd_t = 3
const Cmd_roomLeave Cmd_t = 4
const Cmd_roomValue Cmd_t = 5
const Cmd_roomValueMore Cmd_t = 10 // 服务端->客户端. LiveData 分片, 后面还有. LiveData(分片) 有效.
LiveData 超过单 frame 上限时, 一次 roomValue 拆成 [roomValueMore...][roomValue] 分块传输(服务端->客户端). roomValueMore 只携带一段 LiveData 分片(后面还有); 最后一段用普通 Cmd_roomValue(携带全部元数据), 与不分块时的单条 roomValue 同构. 同一连接上一次分块序列由写缓冲原子整组写入, 中间不会插入其它消息, 客户端把之前累积的 roomValueMore 分片拼到收到的 roomValue 前面即可.
const Cmd_setTimeCfg Cmd_t = 2
type DenyScope_t ¶
type DenyScope_t = uint8
Cmd_deny 的 DenyScope 取值.
const DenyScope_conn DenyScope_t = 1 // 连接级拒绝(identity 认证失败).
const DenyScope_room DenyScope_t = 2 // 房间级拒绝(进入某房间被拒).
type Msg_t ¶
type Msg_t struct {
Cmd Cmd_t
RoomId string
RoomEpoch string // 房间纪元id. 每次房间被创建时由 zlibIdGen.NewId() 生成. 用于检测房间被重建(包括服务器重启).
ChangeSeq uint64 // 变化序号. 同一个 RoomEpoch 下递增表示有新变化.
CVersionId string // 自定义版本id. 服务器内存存储该数据. 调用者用于追踪实际数据变化. 最大100字节.
LiveData []byte // 事件发生时的附加实时数据. 本模块不存储. 默认上限1024字节, 可由服务端 LiveDataMaxSize 调大(最大16MB). 超过单 frame 时拆分为 roomValueMore...roomValue.
TimeoutCfg *TimeoutCfg_t
Identity string // Cmd_identity. opaque 凭证. 最大65535字节.
AuthEnabled bool // Cmd_connAllow. 服务端是否配置了认证(用于客户端"漏接 onDenyFn 当场告警").
DenyScope DenyScope_t // Cmd_deny. 拒绝的作用域.
Reason string // Cmd_deny / Cmd_closeConn. 原因文本. 最大65535字节.
IsTemp bool // Cmd_closeConn. true=临时(客户端应重连); false=永久(客户端不再重连).
}
协议消息. 按照Cmd选择有效字段进行序列化. Cmd_ping: 无额外字段. Cmd_setTimeCfg: TimeoutCfg 有效. Cmd_roomEnter: RoomId 有效. Cmd_roomLeave: RoomId 有效. Cmd_roomValue: RoomId, RoomEpoch, ChangeSeq, CVersionId, LiveData 有效. Cmd_identity: Identity 有效. Cmd_connAllow: AuthEnabled 有效. Cmd_deny: DenyScope, RoomId(房间级时), Reason 有效. Cmd_closeConn: IsTemp, Reason 有效.
func UnmarshalMsg ¶
从二进制数据反序列化Msg_t. 按Cmd选择字段解析.
func (*Msg_t) BinarySize ¶
计算序列化后的字节数, 同时校验输入合法性. errMsg 非空表示输入无法序列化.
func (*Msg_t) MarshalBinary ¶
按Cmd选择字段的二进制序列化格式(小端法): Cmd_ping: [Cmd: uint8] Cmd_setTimeCfg: [Cmd: uint8][count: uint8][ [fieldId: uint8][value: int64LE] ] * count (fieldId见TimeoutCfg_t注释, 不认识的fieldId跳过) Cmd_roomEnter: [Cmd: uint8][RoomId: uint16LE长度 + 内容] Cmd_roomLeave: [Cmd: uint8][RoomId: uint16LE长度 + 内容] Cmd_roomValue: [Cmd: uint8][RoomId: uint16LE长度 + 内容][RoomEpoch: uint8长度 + 内容][ChangeSeq: uvarint][CVersionId: uint8长度 + 内容][LiveData: uint16LE长度 + 内容] Cmd_roomValueMore: [Cmd: uint8][LiveData分片: uint16LE长度 + 内容] Cmd_identity: [Cmd: uint8][Identity: uint16LE长度 + 内容] Cmd_connAllow: [Cmd: uint8][AuthEnabled: uint8] Cmd_deny: [Cmd: uint8][DenyScope: uint8][RoomId: uint16LE长度 + 内容][Reason: uint16LE长度 + 内容] Cmd_closeConn: [Cmd: uint8][IsTemp: uint8][Reason: uint16LE长度 + 内容]
func (*Msg_t) MarshalBinaryInto ¶
将消息序列化写入预分配的字节切片. 调用者保证 len(buf) >= BinarySize().
func (*Msg_t) MarshalBinaryTo ¶
将消息序列化写入 BufWriter. 格式与 MarshalBinaryInto 一致.
type ObsEventType_t ¶
type ObsEventType_t = uint8
const ObsEventType_clientConnClose ObsEventType_t = 25
const ObsEventType_clientConnConnected ObsEventType_t = 21
const ObsEventType_clientConnDialFail ObsEventType_t = 22
const ObsEventType_clientConnDialing ObsEventType_t = 20
客户端事件 20-39
const ObsEventType_clientConnNoNeed ObsEventType_t = 24
const ObsEventType_clientConnWaitReconnect ObsEventType_t = 23
const ObsEventType_clientNeedManual ObsEventType_t = 27
const ObsEventType_clientServerCloseConn ObsEventType_t = 26
const ObsEventType_serverAuthTimeout ObsEventType_t = 8
const ObsEventType_serverCloseConnTimeout ObsEventType_t = 9
const ObsEventType_serverConnAccept ObsEventType_t = 1
服务端事件 1-19
const ObsEventType_serverConnClose ObsEventType_t = 2
const ObsEventType_serverFireChange ObsEventType_t = 3
const ObsEventType_serverLiveDataDropped ObsEventType_t = 4
const ObsEventType_serverMsgTooLarge ObsEventType_t = 11
const ObsEventType_serverProtocolError ObsEventType_t = 10
const ObsEventType_serverRoomOverLimit ObsEventType_t = 6
const ObsEventType_serverUnknownCmd ObsEventType_t = 7
const ObsEventType_serverWriteBufFull ObsEventType_t = 5
type ObsEvent_t ¶
type ObsEvent_t struct {
Type ObsEventType_t
RemoteAddr string // serverConnAccept/serverConnClose/serverWriteBufFull 等
SessionId string // serverConnAccept/serverConnClose 等
RoomId string // serverFireChange/serverLiveDataDropped/serverWriteBufFull 等
CloseReason string // serverConnClose/clientConnClose 时有效
CloseDetail string // serverConnClose/clientConnDialFail/clientConnClose 时有效
NotifiedCount int // serverFireChange 时有效
LiveDataLen int // serverLiveDataDropped 时有效
}
观测事件. 使用 sync.Pool 复用, 回调内有效, 离开回调后字段值不保证. 如果回调内需要异步处理, 必须自行复制需要的字段.
func (*ObsEvent_t) Reset ¶
func (ev *ObsEvent_t) Reset()
type RoomEvent_t ¶
type RoomEvent_t struct {
RoomId string
LiveData []byte // 可选. 调用者负责序列化. 超过 ServerManager.LiveDataMaxSize(默认1024) 则该次静默忽略(发 obs). 超过单 frame 时自动分块传输.
CVersionId string // 可选. 自定义版本id. 最大100字节,超过panic. 用于调用者追踪实际数据变化.
}
FireChange的输入参数.
type RoomOnChange_t ¶
type RoomOnChange_t struct {
RoomId string // 房间id.
RoomEpoch string // 房间纪元id. 每次房间被创建时生成. 不同的 RoomEpoch 表示房间被重建过(包括服务器重启).
ChangeSeq uint64 // 变化序号. 同一个 RoomEpoch 下递增表示有新变化.
CVersionId string // 自定义版本id. 服务器内存存储该数据. 调用者用于追踪实际数据变化. 最大100字节.
LiveData []byte // hgmBjson编码的实时数据. 长度为0表示本次没有传输. 只读,多个listener共享同一底层数组.
ErrMsg string // 回调中设置此字段表示报错. 非空时客户端进入 needManual 状态.
}
房间变化事件,传递给RoomEnter的回调.
type ServerConn_t ¶
type ServerConn_t struct {
SessionIdNet string // 网络层 sessionId(来自 OnAcceptFn, 如 ws cookie/url query). 可能为空.
IdentityInBand string // 客户端 in-band 发来的 identity(Cmd_identity). 可能为空.
Userdata any // 调用者可读写. 用于跨回调传递数据(如连接级解析出的角色, 房间级复用).
// contains filtered or unexported fields
}
暴露给 OnAllowFn 的连接对象. 同一连接的多次回调拿到的是同一个对象(指针), 因此 Userdata 可以在连接级回调里设置, 在后续房间级回调里读取(跨调用传递数据).
func (*ServerConn_t) CloseConn ¶
func (c *ServerConn_t) CloseConn(isTemp bool, reason string)
要求客户端关闭当前连接. isTemp=true 客户端应重连(重连会重新认证); isTemp=false 客户端不再重连. reason 为原因文本. 用于禁用某 sessionId / 把客户端从某房间踢出(踢出靠重连时重新过 OnAllowFn).
type ServerManager ¶
type ServerManager struct {
TimeoutCfg zlibSync.Var[TimeoutCfg_t]
// 接受请求中间件. 用于从网络层(ws cookie/url query)读取网络层 sessionId(写入 ctx.SessionId),
// 或直接终止请求(ctx.IsStop). 注意这是"网络层身份", 与客户端 in-band 发来的 identity 互相独立.
OnAcceptFn func(ctx *ServerOnAccept_ctx_t)
// 认证回调. 可选. nil 表示不认证(连接和进房全部放行, 和没有认证系统一样).
// 同一个回调同时处理连接级(ctx.RoomId=="")和房间级(ctx.RoomId!="")认证, 由 ctx 区分.
// 回调内不显式 ctx.Deny() 即视为允许. 回调是同步的, 可以阻塞(查库/调权限服务),
// 阻塞期间该连接的 keepalive 与其它房间数据照常流动(回调跑在每条连接独立的 cmd goroutine 上, 不在读循环上).
OnAllowFn func(ctx *ServerOnAllow_ctx_t)
// 观测事件回调. nil 表示使用 ObsDefaultFn. 设置为空函数表示关闭观测.
ObsFn func(ev *ObsEvent_t)
// 单连接最大房间数. 0表示使用默认值1024, 负值 _init 时 panic. 超过上限会给客户端报错并断开连接.
RoomEnterMaxPerConn int
// 写入缓冲最大字节数(每条连接). 0表示使用默认值64KB, 最大可配置 64MB(负值或超限 _init 时 panic). 调用者发现缓冲满了服务端主动断开连接.
// 注意: 调大后客户端的 ReadMsgMaxBytes 必须 >= 本值(单个 websocket message 最大可达本值), 否则客户端会因消息过大断开.
// 本字段必须在首次调用 API(ServeHTTP/FireChange) 之前配置好, 之后不再更改(并发安全靠此文档约束, 不加锁/atomic; _init 会把默认值写回本字段).
WriteBufMaxBytes int
// 单次 LiveData 最大字节数. 0表示使用默认值1024, 最大可配置 16MB(负值或超限 _init 时 panic). 超过则该次 FireChange 的 LiveData 被静默丢弃(发 obs).
// 必须 <= WriteBufMaxBytes 的 25%, 否则 _init 时 panic. 超过单 frame 上限时自动用 roomValueMore...roomValue 分块传输.
// 本字段必须在首次调用 API(ServeHTTP/FireChange) 之前配置好, 之后不再更改(并发安全靠此文档约束, 不加锁/atomic; _init 会把默认值写回本字段).
LiveDataMaxSize int
// contains filtered or unexported fields
}
func (*ServerManager) CloseConnBySessionId ¶
func (s *ServerManager) CloseConnBySessionId(sessionId string, isTemp bool, reason string)
按 sessionId(网络层 sessionId 或 in-band identity)找到所有连接, 要求它们关闭. isTemp=true 客户端重连(重连重新过 OnAllowFn, 用于踢出/撤权); isTemp=false 客户端不再重连(永久封禁).
func (*ServerManager) FireChange ¶
func (s *ServerManager) FireChange(ev RoomEvent_t)
有个房间发生了变化. 房间不存在时自动创建.
func (*ServerManager) GetSnapshot ¶
func (s *ServerManager) GetSnapshot() ServerSnapshot_t
查询服务端当前状态快照.
func (*ServerManager) ServeHTTP ¶
func (s *ServerManager) ServeHTTP(w http.ResponseWriter, r *http.Request)
type ServerOnAccept_ctx_t ¶
type ServerOnAllow_ctx_t ¶
type ServerOnAllow_ctx_t struct {
Conn *ServerConn_t
RoomId string
// contains filtered or unexported fields
}
OnAllowFn 的回调参数. RoomId=="" 表示连接级认证(identity); RoomId!="" 表示房间级认证(进入该房间). 回调内不调用 Deny 即视为允许.
func (*ServerOnAllow_ctx_t) Deny ¶
func (ctx *ServerOnAllow_ctx_t) Deny(reason string)
拒绝本次(连接或房间). reason 为原因文本, 会下发给客户端.
type ServerSnapshot_t ¶
服务端当前状态快照.
type TimeoutCfg_t ¶
type TimeoutCfg_t struct {
ClientReconnectMinDur time.Duration // fieldId=1. 客户端 最小重连时间间隔。比如 1秒。
ClientIdleToSendKeepAliveDur time.Duration // fieldId=2. 客户端 网络idle(最后发包时间/最后收包时间的较小值)到 发送keep alive 的时间间隔。比如1秒。
ClientLastReadToReconnectDur time.Duration // fieldId=3. 客户端 最后收包时间 到关闭连接 开始重连的时间间隔。比如 5秒。
ClientWsDialTimeoutDur time.Duration // fieldId=4. 客户端 websocket.Dial 这个步骤的 最大等待时间间隔。比如 2秒。 (注意 这个步骤有个tcp.Dial+http req/resp ws最少:2rtt, wss最少:3rtt)
ClientNoNeedIdleDur time.Duration // fieldId=5. 客户端没有需求,到 关闭连接的超时.
ClientLastReadToUiNoWorkDur time.Duration // fieldId=6. 客户端 最后收包时间 超过此值 ui状态显示为离线. 默认10秒.
ServerLastReadToCloseDur time.Duration // 不参与二进制序列化(仅服务端使用). 服务端 最后收包时间 到关闭连接 的时间间隔。比如 2分钟。
ServerAuthTimeoutDur time.Duration // 不参与二进制序列化(仅服务端使用). 服务端 未认证连接的超时关闭时间间隔。比如 30秒。
ServerAskStopListenTimeoutDur time.Duration // 不参与二进制序列化(仅服务端使用). 服务端 发送askStopListen后等待客户端断开的超时时间间隔。比如 30秒。
}
func (*TimeoutCfg_t) InitWithDefault ¶
func (tc *TimeoutCfg_t) InitWithDefault()
type UiStatusToUser_t ¶
type UiStatusToUser_t = string
面向终端用户的ui状态. 用于在界面上展示当前数据同步状态. "现在距离上次收到服务端确认连接有效的时间" 是客户端对象上的跨连接字段(lastReadSuccTimeAll), 收到任意一个能证明当前ws应用层链路活着的服务端入站消息时更新.
const UiStatusToUser_needManual UiStatusToUser_t = "needManual"
需要手动: 存在无法自动恢复的问题, 需要用户手动介入(比如刷新页面). 触发条件: 开发者传入的 onChangeFn 回调报错(通过 ErrMsg 或 panic/throw), 或 isStopListen 为 true(服务端发送 Cmd_askStopListen 或外部调用 SetIsStopListen(true)).
const UiStatusToUser_offline UiStatusToUser_t = "offline"
离线: 距离上次收到服务端有效消息已超过 ClientLastReadToUiNoWorkDur. 网络大概率不正常, 用户应检查网络. 网络恢复后可自动回到已同步.
const UiStatusToUser_synced UiStatusToUser_t = "synced"
已同步: 最近收到服务端有效消息(在 ClientLastReadToReconnectDur 内), 且当前没有房间变化回调正在运行, 且ws连接正常. 表示数据是最新的.
const UiStatusToUser_syncing UiStatusToUser_t = "syncing"
同步中: 最近收到服务端有效消息(在 ClientLastReadToUiNoWorkDur 内), 但存在以下任一情况: 距离上次收到有效消息已超过 ClientLastReadToReconnectDur, 或当前有房间变化回调正在运行, 或ws连接不正常(断开/重连中). 预期网络大概率正常, 可以自动恢复到已同步.