mirror of
https://github.com/Textualize/textual-web.git
synced 2025-10-17 02:36:40 +03:00
Skeleton of handling msgpackd data
This commit is contained in:
@@ -196,6 +196,7 @@ class AppSession(Session):
|
||||
|
||||
META = b"M"
|
||||
DATA = b"D"
|
||||
PACKED = b"P"
|
||||
|
||||
stderr_data = io.BytesIO()
|
||||
|
||||
@@ -216,6 +217,7 @@ class AppSession(Session):
|
||||
|
||||
on_data = self._connector.on_data
|
||||
on_meta = self._connector.on_meta
|
||||
on_packed = self._connector.on_packed
|
||||
try:
|
||||
ready = False
|
||||
for _ in range(10):
|
||||
@@ -240,6 +242,8 @@ class AppSession(Session):
|
||||
await self.send_meta({"type": meta_type})
|
||||
else:
|
||||
await on_meta(json.loads(payload))
|
||||
elif type_bytes == PACKED:
|
||||
await on_packed(payload)
|
||||
|
||||
except IncompleteReadError:
|
||||
# Incomplete read means that the stream was closed
|
||||
|
||||
@@ -81,6 +81,13 @@ class _ClientConnector(SessionConnector):
|
||||
"You may be running a version of Textual unsupported by this version of Textual Web."
|
||||
)
|
||||
|
||||
async def on_packed(self, payload: bytes) -> None:
|
||||
"""Handle packed data from session.
|
||||
|
||||
Args:
|
||||
payload: Msgpack data to handle.
|
||||
"""
|
||||
|
||||
async def on_close(self) -> None:
|
||||
await self.client.send(packets.SessionClose(self.session_id, self.route_key))
|
||||
self.client.session_manager.on_session_end(self.session_id)
|
||||
|
||||
@@ -22,6 +22,13 @@ class SessionConnector:
|
||||
meta: Mapping of meta information.
|
||||
"""
|
||||
|
||||
async def on_packed(self, payload: bytes) -> None:
|
||||
"""Handle data packed with msgpack from session.
|
||||
|
||||
Args:
|
||||
payload: Msgpack data to handle.
|
||||
"""
|
||||
|
||||
async def on_close(self) -> None:
|
||||
"""Handle session close."""
|
||||
|
||||
|
||||
Reference in New Issue
Block a user