From 86f9f114b5270145d3a32e422884decb3463de9c Mon Sep 17 00:00:00 2001 From: Alex X Date: Sat, 27 Dec 2025 12:04:42 +0300 Subject: [PATCH] Code refactoring for #1980 --- website/schema.json | 353 ++++++++----------- www/config.html | 50 +-- www/schema.json | 824 -------------------------------------------- www/static.go | 1 - 4 files changed, 169 insertions(+), 1059 deletions(-) delete mode 100644 www/schema.json diff --git a/website/schema.json b/website/schema.json index 726879e3..d9c87e40 100644 --- a/website/schema.json +++ b/website/schema.json @@ -29,6 +29,22 @@ "panic", "disabled" ] + }, + "source": { + "type": "string", + "examples": [ + "rtsp://username:password@192.168.1.123/cam/realmonitor?channel=1&subtype=0&unicast=true&proto=Onvif", + "rtsp://username:password@192.168.1.123/stream1", + "rtsp://username:password@192.168.1.123/h264Preview_01_main", + "rtmp://192.168.1.123/bcs/channel0_main.bcs?channel=0&stream=0&user=username&password=password", + "http://192.168.1.123/flv?port=1935&app=bcs&stream=channel0_main.bcs&user=username&password=password", + "http://username:password@192.168.1.123/cgi-bin/snapshot.cgi?channel=1", + "ffmpeg:media.mp4#video=h264#hardware#width=1920#height=1080#rotate=180#audio=copy", + "ffmpeg:virtual?video=testsrc&size=4K#video=h264#hardware#bitrate=50M", + "exec:ffmpeg -re -i media.mp4 -c copy -rtsp_transport tcp -f rtsp {output}", + "onvif://username:password@192.168.1.123:80?subtype=0", + "tapo://password@192.168.1.123:8800?channel=0&subtype=0" + ] } }, "properties": { @@ -36,13 +52,14 @@ "type": "object", "properties": { "listen": { + "type": "string", "default": ":1984", "examples": [ - "127.0.0.1:8080" - ], - "$ref": "#/definitions/listen" + "127.0.0.1:1984" + ] }, "username": { + "description": "Basic auth for WebUI", "type": "string", "examples": [ "admin" @@ -52,38 +69,34 @@ "type": "string" }, "local_auth": { - "description": "Allow auth from local network without credentials (uses existing Auth header)", + "description": "Enable auth check for localhost requests", "type": "boolean", "default": false }, "base_path": { + "description": "API prefix for serving on suburl (/api => /rtc/api)", "type": "string", "examples": [ - "/go2rtc" + "/rtc" ] }, "static_dir": { + "description": "Folder for static files (custom web interface)", "type": "string", "examples": [ - "/var/www" + "www" ] }, "origin": { - "description": "Set to \"*\" to enable CORS and allow any Origin", + "description": "Allow CORS requests (only * supported)", "type": "string", - "anyOf": [ - { - "type": "string", - "const": "*" - }, - { - "type": "string", - "const": "" - } + "enum": [ + "*", + "" ] }, "tls_listen": { - "$ref": "#/definitions/listen" + "type": "string" }, "tls_cert": { "type": "string", @@ -106,16 +119,16 @@ ] }, "allow_paths": { - "description": "Allow only these HTTP paths (full paths, including base_path); when set, all other endpoints are not registered", + "description": "Allow only these HTTP paths (full paths, including base_path)", "type": "array", "items": { "type": "string" }, "examples": [ [ - "/api/ws", - "/api/config", - "/api/streams" + "/api", + "/api/streams", + "/api/webrtc" ] ] } @@ -164,6 +177,7 @@ "roborock", "tapo", "tuya", + "xiaomi", "yandex", "debug", "ngrok", @@ -189,13 +203,7 @@ "type": "array", "items": { "type": "string" - }, - "examples": [ - [ - "ffmpeg", - "/usr/bin/ffmpeg" - ] - ] + } } } }, @@ -223,6 +231,26 @@ "bin": { "type": "string", "default": "ffmpeg" + }, + "global": { + "type": "string", + "default": "-hide_banner" + }, + "file": { + "type": "string", + "default": "-re -i {input}" + }, + "http": { + "type": "string", + "default": "-fflags nobuffer -flags low_delay -i {input}" + }, + "rtsp": { + "type": "string", + "default": "-fflags nobuffer -flags low_delay -timeout 5000000 -user_agent go2rtc/ffmpeg -rtsp_flags prefer_tcp -i {input}" + }, + "rtsp/udp": { + "type": "string", + "default": "-fflags nobuffer -flags low_delay -timeout 5000000 -user_agent go2rtc/ffmpeg -i {input}" } }, "additionalProperties": { @@ -245,57 +273,62 @@ "homekit": { "type": "object", "additionalProperties": { - "type": "object", - "properties": { - "pin": { - "description": "HomeKit pairing PIN (will be normalized to XXX-XX-XXX); insecure PINs are rejected", - "type": "string", - "default": "19550224", - "anyOf": [ - { - "type": "string", - "pattern": "^[0-9]{8}$" - }, - { - "type": "string", - "pattern": "^[0-9]{3}-[0-9]{2}-[0-9]{3}$" - } - ] - }, - "name": { - "type": "string" - }, + "type": [ + "object", + "null" + ], + "properties": { + "pin": { + "description": "HomeKit pairing PIN", + "type": "string", + "default": "19550224", + "anyOf": [ + { + "type": "string", + "pattern": "^[0-9]{8}$" + }, + { + "type": "string", + "pattern": "^[0-9]{3}-[0-9]{2}-[0-9]{3}$" + } + ] + }, + "name": { + "type": "string" + }, "device_id": { "type": "string" }, - "device_private": { - "type": "string" - }, - "category_id": { - "description": "Accessory category: \"bridge\", \"doorbell\" or numeric ID (default: camera)", - "type": "string", - "anyOf": [ - { - "type": "string", - "enum": [ - "bridge", - "doorbell" - ] - }, - { - "type": "string", - "pattern": "^[0-9]+$" - }, - { - "type": "string", - "const": "" - } - ] - }, - "pairings": { - "type": "array", - "items": { + "device_private": { "type": "string" + }, + "category_id": { + "description": "Accessory category: `bridge`, `doorbell` or numeric ID", + "type": "string", + "default": "camera", + "anyOf": [ + { + "type": "string", + "enum": [ + "bridge", + "camera", + "doorbell" + ] + }, + { + "type": "string", + "pattern": "^[0-9]+$" + }, + { + "type": "string", + "const": "" + } + ] + }, + "pairings": { + "type": "array", + "items": { + "type": "string" } } } @@ -366,24 +399,6 @@ "api": { "$ref": "#/definitions/log_level" }, - "alsa": { - "$ref": "#/definitions/log_level" - }, - "bubble": { - "$ref": "#/definitions/log_level" - }, - "debug": { - "$ref": "#/definitions/log_level" - }, - "doorbird": { - "$ref": "#/definitions/log_level" - }, - "dvrip": { - "$ref": "#/definitions/log_level" - }, - "eseecloud": { - "$ref": "#/definitions/log_level" - }, "echo": { "$ref": "#/definitions/log_level" }, @@ -399,12 +414,6 @@ "default": "error", "$ref": "#/definitions/log_level" }, - "flussonic": { - "$ref": "#/definitions/log_level" - }, - "gopro": { - "$ref": "#/definitions/log_level" - }, "hass": { "$ref": "#/definitions/log_level" }, @@ -414,63 +423,27 @@ "homekit": { "$ref": "#/definitions/log_level" }, - "http": { - "$ref": "#/definitions/log_level" - }, - "isapi": { - "$ref": "#/definitions/log_level" - }, - "ivideon": { - "$ref": "#/definitions/log_level" - }, "mjpeg": { "$ref": "#/definitions/log_level" }, - "mpegts": { - "$ref": "#/definitions/log_level" - }, "mp4": { "$ref": "#/definitions/log_level" }, - "nest": { - "$ref": "#/definitions/log_level" - }, "ngrok": { "$ref": "#/definitions/log_level" }, "onvif": { "$ref": "#/definitions/log_level" }, - "pinggy": { - "$ref": "#/definitions/log_level" - }, - "ring": { - "$ref": "#/definitions/log_level" - }, - "roborock": { - "$ref": "#/definitions/log_level" - }, "rtmp": { "$ref": "#/definitions/log_level" }, "rtsp": { "$ref": "#/definitions/log_level" }, - "srtp": { - "$ref": "#/definitions/log_level" - }, "streams": { "$ref": "#/definitions/log_level" }, - "tapo": { - "$ref": "#/definitions/log_level" - }, - "tuya": { - "$ref": "#/definitions/log_level" - }, - "v4l2": { - "$ref": "#/definitions/log_level" - }, "webrtc": { "$ref": "#/definitions/log_level" }, @@ -479,13 +452,7 @@ }, "wyoming": { "$ref": "#/definitions/log_level" - }, - "yandex": { - "$ref": "#/definitions/log_level" } - }, - "additionalProperties": { - "$ref": "#/definitions/log_level" } }, "ngrok": { @@ -504,17 +471,17 @@ "type": "object", "properties": { "tunnel": { - "description": "Expose local address via Pinggy (scheme: http/tcp/tls/tlstcp, host:port is your local address)", + "description": "Expose local address via Pinggy", "type": "string", "examples": [ "http://127.0.0.1:1984", - "tcp://127.0.0.1:8554" + "tcp://192.168.1.123:554" ] } } }, "preload": { - "description": "Preload streams on startup (map stream name => probe query, default \"video&audio\")", + "description": "Preload streams on startup (map stream name => probe query, default `video&audio`)", "type": "object", "additionalProperties": { "type": "string", @@ -548,10 +515,10 @@ "type": "object", "properties": { "listen": { + "type": "string", "examples": [ ":1935" - ], - "$ref": "#/definitions/listen" + ] } } }, @@ -559,8 +526,8 @@ "type": "object", "properties": { "listen": { - "default": ":8554", - "$ref": "#/definitions/listen" + "type": "string", + "default": ":8554" }, "username": { "type": "string", @@ -585,98 +552,56 @@ "type": "object", "properties": { "listen": { - "default": ":8443", - "$ref": "#/definitions/listen" + "type": "string", + "default": ":8443" } } }, "streams": { "type": "object", "additionalProperties": { - "title": "Stream", "anyOf": [ { - "description": "Source", - "type": "string", - "examples": [ - "rtsp://username:password@192.168.1.123/cam/realmonitor?channel=1&subtype=0&unicast=true&proto=Onvif", - "rtsp://username:password@192.168.1.123/stream1", - "rtsp://username:password@192.168.1.123/h264Preview_01_main", - "rtmp://192.168.1.123/bcs/channel0_main.bcs?channel=0&stream=0&user=username&password=password", - "http://192.168.1.123/flv?port=1935&app=bcs&stream=channel0_main.bcs&user=username&password=password", - "http://username:password@192.168.1.123/cgi-bin/snapshot.cgi?channel=1", - "ffmpeg:media.mp4#video=h264#hardware#width=1920#height=1080#rotate=180#audio=copy", - "ffmpeg:virtual?video=testsrc&size=4K#video=h264#hardware#bitrate=50M", - "bubble://username:password@192.168.1.123:34567/bubble/live?ch=0&stream=0", - "dvrip://username:password@192.168.1.123:34567?channel=0&subtype=0", - "exec:ffmpeg -re -i media.mp4 -c copy -rtsp_transport tcp -f rtsp {output}", - "isapi://username:password@192.168.1.123:80/", - "kasa://username:password@192.168.1.123:19443/https/stream/mixed", - "onvif://username:password@192.168.1.123:80?subtype=0", - "tapo://password@192.168.1.123:8800?channel=0&subtype=0", - "webtorrent:?share=xxx&pwd=xxx" - ] + "$ref": "#/definitions/source" }, { "type": "array", "items": { - "description": "Source", - "type": "string" + "$ref": "#/definitions/source" } }, { - "type": "object", - "properties": { - "url": { - "description": "Source URL or list of URLs", - "anyOf": [ - { - "type": "string", - "examples": [ - "rtsp://username:password@192.168.1.123/stream1", - "ffmpeg:media.mp4#video=h264#audio=copy" - ] - }, - { - "type": "array", - "items": { - "type": "string" - } - } - ] - } - } + "type": "null" } ] } }, + "xiaomi": { + "type": "object", + "additionalProperties": { + "type": "string" + } + }, "webrtc": { "type": "object", "properties": { "listen": { - "default": ":8555/tcp", "type": "string", - "anyOf": [ - { - "type": "string", - "pattern": ":[0-9]{1,5}(/tcp|/udp)?$" - }, - { - "type": "string", - "const": "" - } + "default": ":8555", + "examples": [ + ":8555/udp" ] }, "candidates": { "type": "array", "items": { - "$ref": "#/definitions/listen/anyOf/0" - }, - "examples": [ - "216.58.210.174:8555", - "stun:8555", - "home.duckdns.org:8555" - ] + "type": "string", + "examples": [ + "216.58.210.174:8555", + "stun:8555", + "home.duckdns.org:8555" + ] + } }, "ice_servers": { "type": "array", @@ -730,13 +655,13 @@ "description": "Use only these network types", "type": "array", "items": { + "type": "string", "enum": [ "tcp4", "tcp6", "udp4", "udp6" - ], - "type": "string" + ] } }, "udp_ports": { @@ -784,7 +709,7 @@ "properties": { "listen": { "description": "Listen address for Wyoming server", - "$ref": "#/definitions/listen" + "type": "string" }, "name": { "description": "Optional satellite name (default: stream name)", diff --git a/www/config.html b/www/config.html index 58f0c3cf..47640957 100644 --- a/www/config.html +++ b/www/config.html @@ -31,20 +31,18 @@