-
-
Notifications
You must be signed in to change notification settings - Fork 37.5k
Bump go2rtc to 1.9.12 and go2rtc-client to 0.3.0 #156948
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -29,8 +29,18 @@ | |
| _GO2RTC_CONFIG_FORMAT = r"""# This file is managed by Home Assistant | ||
| # Do not edit it manually | ||
|
|
||
| app: | ||
| modules: {app_modules} | ||
|
|
||
| api: | ||
| listen: "{api_ip}:{api_port}" | ||
| allow_paths: {api_allow_paths} | ||
|
|
||
| # ffmpeg needs the exec module | ||
| # Restrict execution to only ffmpeg binary | ||
| exec: | ||
| allow_paths: | ||
| - ffmpeg | ||
|
|
||
| rtsp: | ||
| listen: "127.0.0.1:18554" | ||
|
|
@@ -40,6 +50,43 @@ | |
| ice_servers: [] | ||
| """ | ||
|
|
||
| _APP_MODULES = ( | ||
| "api", | ||
| "exec", # Execution module for ffmpeg | ||
| "ffmpeg", | ||
| "http", | ||
| "mjpeg", | ||
| "onvif", | ||
| "rtmp", | ||
| "rtsp", | ||
| "srtp", | ||
| "webrtc", | ||
| "ws", | ||
| ) | ||
|
|
||
| _API_ALLOW_PATHS = ( | ||
| "/", # UI static page and version control | ||
| "/api", # Main API path | ||
| "/api/frame.jpeg", # Snapshot functionality | ||
| "/api/schemes", # Supported stream schemes | ||
| "/api/streams", # Stream management | ||
| "/api/webrtc", # Webrtc functionality | ||
| "/api/ws", # Websocket functionality (e.g. webrtc candidates) | ||
| ) | ||
|
|
||
| # Additional modules when UI is enabled | ||
| _UI_APP_MODULES = ( | ||
| *_APP_MODULES, | ||
| "debug", | ||
| ) | ||
| # Additional api paths when UI is enabled | ||
| _UI_API_ALLOW_PATHS = ( | ||
| *_API_ALLOW_PATHS, | ||
| "/api/config", # UI config view | ||
| "/api/log", # UI log view | ||
| "/api/streams.dot", # UI network view | ||
| ) | ||
|
|
||
| _LOG_LEVEL_MAP = { | ||
| "TRC": logging.DEBUG, | ||
| "DBG": logging.DEBUG, | ||
|
|
@@ -61,14 +108,34 @@ class Go2RTCWatchdogError(HomeAssistantError): | |
| """Raised on watchdog error.""" | ||
|
|
||
|
|
||
| def _create_temp_file(api_ip: str) -> str: | ||
| def _format_list_for_yaml(items: tuple[str, ...]) -> str: | ||
| """Format a list of strings for yaml config.""" | ||
| if not items: | ||
| return "[]" | ||
| formatted_items = ",".join(f'"{item}"' for item in items) | ||
| return f"[{formatted_items}]" | ||
|
|
||
|
|
||
| def _create_temp_file(enable_ui: bool) -> str: | ||
| """Create temporary config file.""" | ||
| app_modules: tuple[str, ...] = _APP_MODULES | ||
| api_paths: tuple[str, ...] = _API_ALLOW_PATHS | ||
| api_ip = _LOCALHOST_IP | ||
| if enable_ui: | ||
| app_modules = _UI_APP_MODULES | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Alternatively, we could make a new tuple as a local variable here and add the tuple constants into the new tuple and only make the constants contain the separate features instead of making the constants contain all needed features. |
||
| api_paths = _UI_API_ALLOW_PATHS | ||
| # Listen on all interfaces for allowing access from all ips | ||
| api_ip = "" | ||
|
|
||
| # Set delete=False to prevent the file from being deleted when the file is closed | ||
| # Linux is clearing tmp folder on reboot, so no need to delete it manually | ||
| with NamedTemporaryFile(prefix="go2rtc_", suffix=".yaml", delete=False) as file: | ||
| file.write( | ||
| _GO2RTC_CONFIG_FORMAT.format( | ||
| api_ip=api_ip, api_port=HA_MANAGED_API_PORT | ||
| api_ip=api_ip, | ||
| api_port=HA_MANAGED_API_PORT, | ||
| app_modules=_format_list_for_yaml(app_modules), | ||
| api_allow_paths=_format_list_for_yaml(api_paths), | ||
| ).encode() | ||
| ) | ||
| return file.name | ||
|
|
@@ -86,10 +153,7 @@ def __init__( | |
| self._log_buffer: deque[str] = deque(maxlen=_LOG_BUFFER_SIZE) | ||
| self._process: asyncio.subprocess.Process | None = None | ||
| self._startup_complete = asyncio.Event() | ||
| self._api_ip = _LOCALHOST_IP | ||
| if enable_ui: | ||
| # Listen on all interfaces for allowing access from all ips | ||
| self._api_ip = "" | ||
| self._enable_ui = enable_ui | ||
| self._watchdog_task: asyncio.Task | None = None | ||
| self._watchdog_tasks: list[asyncio.Task] = [] | ||
|
|
||
|
|
@@ -104,7 +168,7 @@ async def _start(self) -> None: | |
| """Start the server.""" | ||
| _LOGGER.debug("Starting go2rtc server") | ||
| config_file = await self._hass.async_add_executor_job( | ||
| _create_temp_file, self._api_ip | ||
| _create_temp_file, self._enable_ui | ||
| ) | ||
|
|
||
| self._startup_complete.clear() | ||
|
|
||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| # serializer version: 1 | ||
| # name: test_server_run_success[False] | ||
| _CallList([ | ||
| _Call( | ||
| tuple( | ||
| b'# This file is managed by Home Assistant\n# Do not edit it manually\n\napp:\n modules: ["api","exec","ffmpeg","http","mjpeg","onvif","rtmp","rtsp","srtp","webrtc","ws"]\n\napi:\n listen: "127.0.0.1:11984"\n allow_paths: ["/","/api","/api/frame.jpeg","/api/schemes","/api/streams","/api/webrtc","/api/ws"]\n\n# ffmpeg needs the exec module\n# Restrict execution to only ffmpeg binary\nexec:\n allow_paths:\n - ffmpeg\n\nrtsp:\n listen: "127.0.0.1:18554"\n\nwebrtc:\n listen: ":18555/tcp"\n ice_servers: []\n', | ||
| ), | ||
| dict({ | ||
| }), | ||
| ), | ||
| ]) | ||
| # --- | ||
| # name: test_server_run_success[True] | ||
| _CallList([ | ||
| _Call( | ||
| tuple( | ||
| b'# This file is managed by Home Assistant\n# Do not edit it manually\n\napp:\n modules: ["api","exec","ffmpeg","http","mjpeg","onvif","rtmp","rtsp","srtp","webrtc","ws","debug"]\n\napi:\n listen: ":11984"\n allow_paths: ["/","/api","/api/frame.jpeg","/api/schemes","/api/streams","/api/webrtc","/api/ws","/api/config","/api/log","/api/streams.dot"]\n\n# ffmpeg needs the exec module\n# Restrict execution to only ffmpeg binary\nexec:\n allow_paths:\n - ffmpeg\n\nrtsp:\n listen: "127.0.0.1:18554"\n\nwebrtc:\n listen: ":18555/tcp"\n ice_servers: []\n', | ||
| ), | ||
| dict({ | ||
| }), | ||
| ), | ||
| ]) | ||
| # --- |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
provider.initialize()call is not wrapped in error handling. If theschemes.list()API call fails, it will raise an unhandled exception and cause the config entry setup to fail without a proper error message or ConfigEntryNotReady exception.Consider wrapping this call in a try-except block similar to the pattern used above for
client.validate_server_version():