diff --git a/schemata/config-v1.json b/schemata/config-v1.json index 68eff9f..bf5b358 100644 --- a/schemata/config-v1.json +++ b/schemata/config-v1.json @@ -5,9 +5,6 @@ "kind": { "const": "cocoa", "default": "cocoa", - "enum": [ - "cocoa" - ], "title": "Kind", "type": "string" } @@ -52,28 +49,14 @@ "WebsocketsReceiverConfig": { "properties": { "host": { - "anyOf": [ - { - "format": "hostname", - "type": "string" - }, - { - "items": { - "format": "hostname", - "type": "string" - }, - "type": "array" - } - ], "description": "The hostname you'd like your WebSockets server to listen on. In most cases the default behaviour, which binds to all network interfaces, will be fine.", - "title": "Host" + "format": "hostname", + "title": "Host", + "type": "string" }, "kind": { "const": "websockets", "default": "websockets", - "enum": [ - "websockets" - ], "title": "Kind", "type": "string" }, diff --git a/schemata/playback-v1.json b/schemata/playback-v1.json index 58b7244..29c2300 100644 --- a/schemata/playback-v1.json +++ b/schemata/playback-v1.json @@ -136,9 +136,6 @@ }, { "const": "oneshot", - "enum": [ - "oneshot" - ], "type": "string" } ], @@ -172,9 +169,6 @@ }, { "const": "oneshot", - "enum": [ - "oneshot" - ], "type": "string" } ], @@ -328,9 +322,6 @@ "state": { "const": "stop", "default": "stop", - "enum": [ - "stop" - ], "title": "State", "type": "string" } diff --git a/src/mpd_now_playable/config/model.py b/src/mpd_now_playable/config/model.py index 0fde2d1..a112042 100644 --- a/src/mpd_now_playable/config/model.py +++ b/src/mpd_now_playable/config/model.py @@ -35,7 +35,7 @@ class WebsocketsReceiverConfig(BaseReceiverConfig): #: The hostname you'd like your WebSockets server to listen on. In most #: cases the default behaviour, which binds to all network interfaces, will #: be fine. - host: Optional[Host | tuple[Host, ...]] = None + host: Optional[Host] = None ReceiverConfig = Annotated[ diff --git a/src/mpd_now_playable/receivers/websockets/receiver.py b/src/mpd_now_playable/receivers/websockets/receiver.py index a125b6b..d218f35 100644 --- a/src/mpd_now_playable/receivers/websockets/receiver.py +++ b/src/mpd_now_playable/receivers/websockets/receiver.py @@ -2,7 +2,7 @@ from pathlib import Path import ormsgpack from websockets import broadcast -from websockets.server import WebSocketServerProtocol, serve +from websockets.asyncio.server import Server, ServerConnection, serve from yarl import URL from ...config.model import WebsocketsReceiverConfig @@ -24,12 +24,11 @@ def default(value: object) -> object: class WebsocketsReceiver(Receiver): config: WebsocketsReceiverConfig player: Player - connections: set[WebSocketServerProtocol] + server: Server last_status: bytes = MSGPACK_NULL def __init__(self, config: WebsocketsReceiverConfig): self.config = config - self.connections = set() @classmethod def loop_factory(cls) -> DefaultLoopFactory: @@ -37,18 +36,14 @@ class WebsocketsReceiver(Receiver): async def start(self, player: Player) -> None: self.player = player - await serve( + self.server = await serve( self.handle, host=self.config.host, port=self.config.port, reuse_port=True ) - async def handle(self, conn: WebSocketServerProtocol) -> None: - self.connections.add(conn) + async def handle(self, conn: ServerConnection) -> None: await conn.send(self.last_status) - try: - await conn.wait_closed() - finally: - self.connections.remove(conn) + await conn.wait_closed() async def update(self, playback: Playback) -> None: self.last_status = ormsgpack.packb(playback, default=default) - broadcast(self.connections, self.last_status) + broadcast(self.server.connections, self.last_status)