refactor: convert websockets into a component

Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
This commit is contained in:
Eric Callahan 2024-01-13 10:58:03 -05:00
parent d506c9241f
commit a88468eb79
No known key found for this signature in database
GPG Key ID: 5A1EB336DFB4C71B
8 changed files with 21 additions and 21 deletions

View File

@ -33,7 +33,7 @@ from typing import (
if TYPE_CHECKING:
from .server import Server
from .websockets import WebsocketManager
from .components.websockets import WebsocketManager
from .components.authorization import Authorization
from .utils import IPAddress
from asyncio import Future

View File

@ -33,11 +33,7 @@ from ..common import (
KlippyState
)
from ..utils import json_wrapper as jsonw
from ..websockets import (
WebsocketManager,
WebSocket,
BridgeSocket
)
from .websockets import WebSocket, BridgeSocket
from streaming_form_data import StreamingFormDataParser, ParseFailedException
from streaming_form_data.targets import FileTarget, ValueTarget, SHA256Target
@ -60,6 +56,7 @@ if TYPE_CHECKING:
from ..confighelper import ConfigHelper
from ..klippy_connection import KlippyConnection as Klippy
from ..utils import IPAddress
from .websockets import WebsocketManager
from .file_manager.file_manager import FileManager
from .announcements import Announcements
from .machine import Machine

View File

@ -36,7 +36,7 @@ from typing import (
if TYPE_CHECKING:
from ..confighelper import ConfigHelper
from ..common import WebRequest
from ..websockets import WebsocketManager
from .websockets import WebsocketManager
from tornado.httputil import HTTPServerRequest
from tornado.web import RequestHandler
from .database import MoonrakerDatabase as DBComp

View File

@ -32,7 +32,7 @@ from typing import (
if TYPE_CHECKING:
from ..confighelper import ConfigHelper
from ..common import WebRequest
from ..websockets import WebsocketManager
from .websockets import WebsocketManager
STAT_CALLBACK = Callable[[int], Optional[Awaitable]]
VC_GEN_CMD_FILE = "/usr/bin/vcgencmd"

View File

@ -33,7 +33,7 @@ from typing import (
if TYPE_CHECKING:
from .application import InternalTransport
from ..confighelper import ConfigHelper
from ..websockets import WebsocketManager
from .websockets import WebsocketManager
from ..common import BaseRemoteConnection
from tornado.websocket import WebSocketClientConnection
from .database import MoonrakerDatabase

View File

@ -13,7 +13,7 @@ from ..common import RequestType
if TYPE_CHECKING:
from typing import Optional
from moonraker.websockets import WebRequest
from ..common import WebRequest
from moonraker.components.http_client import HttpClient
from moonraker.components.database import MoonrakerDatabase
from moonraker.components.announcements import Announcements

View File

@ -9,13 +9,13 @@ import logging
import asyncio
from tornado.websocket import WebSocketHandler, WebSocketClosedError
from tornado.web import HTTPError
from .common import (
from ..common import (
RequestType,
WebRequest,
BaseRemoteConnection,
TransportType,
)
from .utils import ServerError, parse_ip_address
from ..utils import ServerError, parse_ip_address
# Annotation imports
from typing import (
@ -31,12 +31,12 @@ from typing import (
)
if TYPE_CHECKING:
from .server import Server
from .klippy_connection import KlippyConnection as Klippy
from .confighelper import ConfigHelper
from .components.extensions import ExtensionManager
from .components.authorization import Authorization
from .utils import IPAddress
from ..server import Server
from ..klippy_connection import KlippyConnection as Klippy
from ..confighelper import ConfigHelper
from .extensions import ExtensionManager
from .authorization import Authorization
from ..utils import IPAddress
ConvType = Union[str, bool, float, int]
ArgVal = Union[None, int, float, bool, str]
RPCCallback = Callable[..., Coroutine]
@ -58,7 +58,6 @@ class WebsocketManager:
"/server/connection/identify", RequestType.POST, self._handle_identify,
TransportType.WEBSOCKET, auth_required=False
)
self.server.register_component("websockets", self)
def register_notification(
self,
@ -481,3 +480,6 @@ class BridgeSocket(WebSocketHandler):
def close_socket(self, code: int, reason: str) -> None:
self.close(code, reason)
def load_component(config: ConfigHelper) -> WebsocketManager:
return WebsocketManager(config)

View File

@ -32,7 +32,6 @@ from .utils import (
)
from .loghelper import LogManager
from .common import RequestType
from .websockets import WebsocketManager
# Annotation imports
from typing import (
@ -50,6 +49,7 @@ from typing import (
if TYPE_CHECKING:
from .common import WebRequest
from .components.application import MoonrakerApp
from .components.websockets import WebsocketManager
from .components.file_manager.file_manager import FileManager
from .components.machine import Machine
from .components.extensions import ExtensionManager
@ -106,7 +106,8 @@ class Server:
self.register_static_file_handler = app.register_static_file_handler
self.register_upload_handler = app.register_upload_handler
self.log_manager.set_server(self)
self.websocket_manager = WebsocketManager(config)
self.websocket_manager: WebsocketManager
self.websocket_manager = self.load_component(config, "websockets")
for warning in args.get("startup_warnings", []):
self.add_warning(warning)