Added/deleted-type websocket messages

Events are now sent for not only when an object changes but also when one is created or deleted.

For now it's not really possible to subscribe to these events however.

This breaks backwards-compatibility with the websocket messages.
This commit is contained in:
Donkie
2023-10-15 19:46:10 +02:00
parent 3c5b3cea5a
commit a6d527aaf0
6 changed files with 92 additions and 25 deletions

View File

@@ -4,6 +4,8 @@ import logging
from fastapi import WebSocket
from spoolman.api.v1.models import Event
logger = logging.getLogger(__name__)
@@ -37,12 +39,12 @@ class WebsocketManager:
pool_str,
)
async def send(self, pool: tuple[str, ...], message: str) -> None:
async def send(self, pool: tuple[str, ...], evt: Event) -> None:
"""Send a message to all websockets in a pool."""
pool_str = ",".join(pool)
if pool_str in self.connections:
for websocket in self.connections[pool_str]:
await websocket.send_text(message)
await websocket.send_text(evt.json())
websocket_manager = WebsocketManager()