主题
FletApp 继承自: Connection
处理 Flet 应用的 WebSocket 连接。
参数: loop:asyncio 事件循环(asyncio.get_running_loop())。 executor:线程池执行器(app_manager.executor)。 main:应用入口点——为新连接的用户调用的异步方法。其处理协程必须接收 1 个 Page 实例参数。 before_main:在 main 之前调用。 session_timeout_seconds:会话生存期,以秒为单位,自用户断开连接后起算。 oauth_state_timeout_seconds:OAuth 状态的生存期,以秒为单位,即启动 OAuth 流程与重定向到 OAuth 回调 URL 之间允许的最大时间间隔。 upload_endpoint_path:上传端点的绝对 URL,例如 /upload。 secret_key:用于对上传请求签名的密钥。
只读属性
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
loop | AbstractEventLoop | — | Returns the event loop associated with this connection. Returns: Initialized asyncio event loop. Raises: RuntimeError: If the loop has not been assigned. |
executor | ThreadPoolExecutor | — | Returns the thread pool executor used by this connection. Returns: Initialized thread pool executor. Raises: RuntimeError: If the executor has not been assigned. |
pubsubhub | PubSubHub | — | Returns the pub/sub hub used to broadcast session messages. Returns: Initialized pub/sub hub instance. Raises: RuntimeError: If the pub/sub hub has not been assigned. |
方法
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
handle | — | — | Handle WebSocket connection. Args: websocket: WebSocket instance. |
send_message | — | — | Serialize and enqueue a server message for transport to the client. Wire format: one packet per send_bytes call — [0x00][msgpack body]. WebSocket preserves message boundaries so no length prefix is needed. Args: message: Outbound protocol message. |
send_data_channel_frame | None | — | Send a raw DataChannel frame [0x01][channel_id:u32 LE][bytes] over the WebSocket. Called by _ProtocolMuxedDataChannel.send. |
data_channel_for | — | — | Resolve or construct the muxed DataChannel for channel_id. |
unregister_data_channel | None | — | — |
get_upload_url | str | — | Build signed upload URL for a file. Args: file_name: File name to be uploaded. expires: URL lifetime in seconds. Returns: Signed relative upload URL. Raises: RuntimeError: If upload endpoint is not configured. |
oauth_authorize | — | — | Persist OAuth state metadata for a pending authorization flow. Args: attrs: OAuth attributes payload containing state and optional completion page data. |
dispose | — | — | Release app-level session reference during teardown. |