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:
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user