WsClient class

WebSocket 客户端封装(web_socket_channel)。

连接格式(对齐 go-chat comet): ws://host:9502/wss/default.io?token=<JWT>&lang=zh-CN

帧格式:Text JSON AES 信封 {"iv","data"},解密后为 { "event": "...", "payload": {...} }

功能:

  • Query Token 鉴权
  • 客户端主动 Ping / 处理 Pong(默认 20s)
  • 断线指数退避自动重连 + 网络恢复智能重连
  • 按 event 流式分发

Constructors

WsClient()

Properties

baseReconnectDelay ↔ Duration
首条重连延迟
getter/setter pair
eventStream → Stream<WsFrame>
no setter
hashCode → int
The hash code for this object.
no setterinherited
heartbeatInterval ↔ Duration
心跳间隔(LumenIM 客户端默认 20s)
getter/setter pair
isConnected → bool
no setter
isConnecting → bool
是否处于连接建立过程中
no setter
isReconnectPending → bool
是否在等待重连(含因离线而挂起的重连意图)
no setter
maxReconnectDelay ↔ Duration
最大重连间隔
getter/setter pair
networkAvailable ↔ bool
由 ConnectivityMonitor 注入:当前是否有网络接口
getter/setter pair
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
wsBase → String
no setter

Methods

connect() → Future<void>
建立连接。需已设置 Token。
disconnect() → Future<void>
主动断开(不再重连)
dispose() → Future<void>
emit(String event, dynamic payload) → Future<void>
发送事件帧
init({required String wsBase, required String aesKey, OnConnListener? listener, String? acceptLanguage}) → void
wsBase 例如 ws://127.0.0.1:9502(不含路径) acceptLanguage 写入 query lang,默认 zh-CN。
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
onNetworkLost() → void
设备网络丢失:停止心跳与重连定时器,挂起重连意图。
onNetworkRestored() → void
设备网络恢复时由 NetworkManager 调用:取消退避,立即重连。
reconnectIfConnected() → Future<void>
已连接或正在连接时关闭当前通道并立刻重连(使新 lang 生效)。
sendAndWaitAck(Map<String, dynamic> payload, {Duration timeout = const Duration(seconds: 15)}) → Future<void>
发送消息并等待 im.message.send.ack / event_error
setAcceptLanguage(String value) → void
运行时更换 query lang。已连接时由调用方触发重连后生效。
setConnListener(OnConnListener? listener) → void
setToken(String? token) → void
toString() → String
A string representation of this object.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited