python Flet 订阅广播无法正常收到对方消息,怎么解决?

基于flet官方例子修改成异步的订阅后,只能收到发送方自己的消息,求助!

import flet as ft
import flet_fastapi

async def main(page: ft.Page):
    page.title = "Flet Chat"

    async def on_message_async(msg):
        messages.controls.append(ft.Text(msg))
        await page.update_async()

    await page.pubsub.subscribe_async(on_message_async)

    async def send_click(e):
        await page.pubsub.send_all_async(f"{message.value}")
        message.value = ""
        await page.update_async()

    messages = ft.Column()
    message = ft.TextField(hint_text="Your message...", expand=True)
    send = ft.ElevatedButton("Send", on_click=send_click)
    await page.add_async(messages, ft.Row(controls=[message, send]))

#ft.app(target=main, view=ft.AppView.WEB_BROWSER)
app = flet_fastapi.app(main) # You only get your own messages

使用 ft.app(target=main, view=ft.AppView.WEB_BROWSER) 正常,但无法部署到服务端。

阅读 546
1 个回答
✓ 已被采纳

image.png
已经联系作者,确认是框架的BUG。

推荐问题
宣传栏