diff --git a/db.json b/db.json new file mode 100644 index 00000000..52108671 --- /dev/null +++ b/db.json @@ -0,0 +1,31 @@ +{ + "announcements": {}, + "gcode_metadata": {}, + "history": {}, + "mainsail": { + "dashboard": { + "nonExpandPanels": { + "widescreen": [] + } + }, + "gcodeViewer": { + "klipperCache": { + "axis_maximum": [ + 235, + 235, + 250, + 0 + ], + "axis_minimum": [ + -15, + -15, + -2, + 0 + ] + } + } + }, + "moonraker": {}, + "update_manager": {}, + "webcams": [] +} \ No newline at end of file diff --git a/web/base.py b/web/base.py index a3241b11..e61fee39 100644 --- a/web/base.py +++ b/web/base.py @@ -60,16 +60,12 @@ def app_root(): anker_config = "No printers found, please load your login config..." printer = None - if ":" in request.host: - request_host, request_port = request.host.split(":", 1) - else: - request_host = request.host - request_port = "80" + host, port = web.util.get_host_port(app) return render_template( "index.html", - request_host=request_host, - request_port=request_port, + request_host=host, + request_port=port, configure=app.config["login"], login_file_path=web.platform.login_path(user_os), anker_config=anker_config, diff --git a/web/moonraker/rpc/server/__init__.py b/web/moonraker/rpc/server/__init__.py index c59bebaf..dda950f6 100644 --- a/web/moonraker/rpc/server/__init__.py +++ b/web/moonraker/rpc/server/__init__.py @@ -1,6 +1,8 @@ from jsonrpc import dispatcher from flask import current_app as app +import web.util + @dispatcher.add_method(name="server.connection.identify") def server_connection_identify(client_name, version, type, url, access_token=None, api_key=None): @@ -161,12 +163,14 @@ def server_temperature_store(): @dispatcher.add_method(name="server.config") def server_config(): + host, port = web.util.get_host_port(app) + return { "config": { "server": { - "host": "0.0.0.0", - "port": 7125, - "ssl_port": 7130, + "host": host, + "port": port, + "ssl_port": port, "enable_debug_logging": True, "enable_asyncio_debug": True, "klippy_uds_address": "/tmp/klippy_uds", @@ -228,7 +232,7 @@ def server_config(): "flip_h": False, "flip_v": False, "rotate_90": False, - "stream_url": "/webcam/?action=stream", + "stream_url": f"ws://{host}:{port}/ws/video", "webcam_enabled": True }, "history": {}, @@ -299,7 +303,7 @@ def server_config(): "password": "{secrets.mqtt_credentials.password}", "enable_moonraker_api": True, # "status_objects": "\nwebhooks\ntoolhead=position,print_time\nidle_timeout=state\ngcode_macro M118" - } + } }, "files": [ { @@ -327,6 +331,32 @@ def server_config(): } +@dispatcher.add_method(name="server.webcams.list") +def server_webcams_list(): + host, port = web.util.get_host_port(app) + + return { + "webcams": [ + { + "name": "Printer", + "location": "printer", + "service": "jmuxer-stream", + "enabled": True, + "icon": "mdiWebcam", + "target_fps": 15, + "target_fps_idle": 5, + "stream_url": f"ws://{host}:{port}/ws/video", + "snapshot_url": "", + "flip_horizontal": False, + "flip_vertical": False, + "rotation": 0, + "aspect_ratio": "4:3", + "source": "config" + } + ] + } + + @dispatcher.add_method(name="server.logs.rollover") def server_logs_rollover(application): ... diff --git a/web/util.py b/web/util.py index e70c093d..e83c03e4 100644 --- a/web/util.py +++ b/web/util.py @@ -37,3 +37,33 @@ def upload_file_to_printer(app, file): with app.svc.borrow("filetransfer") as ft: ft.send_file(file, user_name) + + +def get_host_port(app): + """ + Extracts the host and port from the incoming request. + If no host or port is provided in the request, + the function falls back to the host and port from the application configuration. + + Args: + - app (object): The application object. + + Returns: + A list containing. + - request_host (str): A string representing the hostname. + - request_port (str): A string representing the port number. Defaults to '80'. + + Raises: + - None + """ + if hasattr(request, "host"): + if ":" in request.host: + request_host, request_port = request.host.split(":", 1) + else: + request_host = request.host + request_port = "80" + else: + request_host = app.config["host"] + request_port = app.config["port"] + + return [request_host, request_port]