Add bidirectional host bridge

This commit is contained in:
gem
2026-06-09 16:26:37 +08:00
parent 7b3c5cb0f5
commit 0d4fbd030c
17 changed files with 632 additions and 3 deletions

View File

@@ -69,6 +69,9 @@
---| 'network_ws_message'
---| 'network_ws_error'
---| 'network_ws_close'
---| 'host_notify'
---| 'host_call'
---| 'host_call_result'
---@alias RuntimeScaleMode
---| 'fit'
@@ -598,6 +601,20 @@
---@field url string ws/wss URL.
---@field protocols? string[]
---@class RuntimeHostCallOptions
---@field id? string
---@field method string Host method name registered by Flutter.
---@field data? any
---@class RuntimeHostNotifyOptions
---@field method string Host notification name registered by Flutter.
---@field data? any
---@class RuntimeHostRespondOptions
---@field id string Host-to-Lua call id from host_call event.
---@field result? any
---@field error? string
---@class RuntimeImportApi
---@field import fun(moduleName: string): table
---@field log fun(...: any)
@@ -605,6 +622,9 @@
---@field ws_connect fun(options: RuntimeWsConnectOptions): string Opens a WebSocket and returns connection id. Event types: network_ws_open/network_ws_message/network_ws_error/network_ws_close.
---@field ws_send fun(id: string, message: string): boolean
---@field ws_close fun(id: string): boolean
---@field host_call fun(options: RuntimeHostCallOptions): string Starts an async Lua-to-Flutter host call. Result event type: host_call_result.
---@field host_notify fun(options: RuntimeHostNotifyOptions): boolean Sends a fire-and-forget notification to Flutter host code.
---@field host_respond fun(options: RuntimeHostRespondOptions): boolean Completes a Flutter-to-Lua host_call event.
---@type RuntimeImportApi
runtime = runtime