from __future__ import annotations from collections.abc import Awaitable, Callable from enum import StrEnum from typing import Protocol, runtime_checkable class TransportState(StrEnum): DISCONNECTED = "disconnected" CONNECTING = "connecting" CONNECTED = "connected" RECONNECTING = "reconnecting" STOPPED = "stopped" MessageHandler = Callable[[bytes], Awaitable[None]] @runtime_checkable class Transport(Protocol): @property def state(self) -> TransportState: ... async def start(self) -> None: ... async def stop(self) -> None: ... def on_message(self, handler: MessageHandler) -> None: ... async def send(self, data: bytes | str) -> None: ...