-
Notifications
You must be signed in to change notification settings - Fork 8
Session State and Events
The session runtime uses three information layers to express where the session is, what just happened, and where each component ended up. They serve different purposes and must not be collapsed into one boolean or derived from logs.
| Layer | Type | Question | Main consumers |
|---|---|---|---|
| Main state | SessionState |
Which overall phase is the session in? | UI and lifecycle decisions |
| Process facts | SessionEvent |
Which step just succeeded, failed, or requested an action? | Session handlers, log and monitoring projections |
| Component snapshot | SessionComponentStateSnapshot |
What is the current state of ADB, server, sockets, and decoders? | Diagnostics and readiness checks |
Session.handleEvent() writes events to one Channel. The session processes them sequentially and updates SessionRuntimeState. Producers must not bypass this entry point to create competing global session state.
SessionState currently contains:
IdleAdbConnectingAdbConnected(context)AdbDisconnected(issue)ServerStartingServerStarted(context)ServerFailed(issue)Connected(context)Reconnecting(context)Failed(issue)
These are runtime phases, not a promise that every branch follows one linear graph. The Connected context records the local port, connected sockets, whether audio is enabled, and whether the dummy byte was confirmed. It means the socket layer reached its working condition; by itself it does not prove that metadata or a decoder is ready.
SessionEvent is grouped by responsibility:
- ADB: connecting, verification, success, and disconnection.
- Server: push, startup, and their failures.
- Forward: setup, removal, and failure.
- Socket: connecting, connected, disconnected, and error.
- Decoder: started, stopped, and error.
- Control:
RequestReconnectandRequestCleanup, which are runtime action requests. - Codec: video/audio encoder detection and errors.
- Session:
SessionErrorfor failures that do not belong to a more specific domain.
Events should carry structured contexts or issues. UI text and logs can be generated from them, but failures should not be flattened into unclassifiable strings at the source.
Tracked SessionComponent values are the ADB connection, scrcpy server, video/audio/control sockets, and video/audio decoders. Each uses ComponentState: Idle, Starting, Running, Connected, Stopped, Disconnected, or Error(message).
The snapshot derives three read models:
-
InfrastructureConnectionReadModel: whether ADB is connected, the server is running, and socket prerequisites are met. -
SocketConnectionReadModel: expected socket count, connected set, video readiness, and whether all required sockets are present. -
DecoderConnectionReadModel: running and stopped decoder sets.
When audio is disabled, runtime state updates the expected socket count; consumers must not continue assuming three sockets.
- Events are input facts or action requests; main state and component snapshots are read models produced by event handling.
- Events such as
AdbConnected,ServerStarted, andSocketConnectedadvance main or component state. -
RequestReconnectincrements the attempt and invokes the single callback only when the session is neither reconnecting nor failed and budget remains. - Entering
Connectedresets the reconnect counter.RequestCleanupreturns the main state toIdleand clears component state. - A decoder size error may lower
maxSizefor the current run and request reconnection, but that temporary fallback is not written to persisted user configuration.
Issue models are divided into ADB, server, forward, socket, decoder, reconnect, codec, and session domains. Place new failures in the nearest infrastructure domain and preserve structured fields needed by policy and presentation. Use a session issue only for genuinely cross-domain failures.
- Find the phase where
SessionStatestopped. - Find the last relevant
SessionEventand its context or issue. - Identify the component that did not reach its expected state in the snapshot.
- Then follow that component's code and logs instead of guessing state from the complete log stream.
- Does a new event have a clear producer, one handling entry point, and an issue domain?
- Should it change main state, component state, or only a monitoring projection?
- Does the UI incorrectly treat ADB, socket, and media readiness as the same state?
- Can cleanup and reconnection both react to the same low-level closure?
- Do tests cover success, failure, duplicate events, and audio-disabled paths?
- Overview / 总览
- Quick Start / 快速开始
- Connection & Pairing / 连接设备与配对
- Session Management / 会话管理
- Remote Control / 远程控制
- Settings / 设置
- Management Features / 管理功能
- FAQ / 常见问题
- Overview / 总览
- Technical Index / 技术文档索引
- Audit Checklist / 初始化与更新清单
- Conventions / 文档维护约定
- Architecture / 架构
- Module Map / 模块地图与边界
- Runtime Path / 运行时主链路
- Session State / 会话状态与事件
- Session Lifecycle / 会话配置与连接生命周期
- ADB, USB & Wireless / ADB、USB 与无线
- ADB Lifecycle / ADB 连接生命周期
- Pairing / 设备配对与无线调试
- Codecs / 编码与解码
- Remote Interaction / 远程交互性能与悬浮菜单
- Clipboard / 剪贴板同步
- Management / 管理功能
- Events & Shell / 事件、监控与 Shell
- Logging / 日志系统与维护
- Troubleshooting / 分层排障方法
- UI Design / UI 设计系统
- Bilingual Copy / 双语与文案
- Remote UI Analysis / 远程 UI 布局分析
- Engineering Rules / 工程与验证规则
- External Research / 外部研究与取舍
Technical topics appear here only after their page-level audit is complete. / 技术主题仅在完成逐页审核后加入侧边栏。