sanic=22.6.2 python3.8
log
[2023-02-08 14:13:17][impl.py:236][WARNING]:Websocket timed out waiting for pong
[2023-02-08 14:13:19][server.py:172][INFO]:connection open
@bp_api.websocket('/ws')
async def ws_send(request: Request, ws):
col = DB.get_col()
while True:
data = []
async for item in col.find():
item = format_item(item)
data.append(item)
data = json.dumps(data)
await ws.send(data)
await asyncio.sleep(2)
vue client
setup() {
const ws_url = import.meta.env.VITE_WS_URL
const {status, data, send, open, close} = useWebSocket(ws_url, {autoReconnect: true})
const state = reactive({
lists: []
})
watchEffect(() => {
send('ping')
console.log(status.value)
state.lists = JSON.parse(data.value)
})
onMounted(() => {
state.lists = []
})
return state
}