Skip to content
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

Append a 1 to all go2rtc ports to avoid port conflicts #129881

Merged
merged 1 commit into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions homeassistant/components/go2rtc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
from homeassistant.util.hass_dict import HassKey
from homeassistant.util.package import is_docker_env

from .const import CONF_DEBUG_UI, DEBUG_UI_URL_MESSAGE, DEFAULT_URL, DOMAIN
from .const import CONF_DEBUG_UI, DEBUG_UI_URL_MESSAGE, DOMAIN, HA_MANAGED_URL
from .server import Server

_LOGGER = logging.getLogger(__name__)
Expand Down Expand Up @@ -125,7 +125,7 @@ async def on_stop(event: Event) -> None:

hass.bus.async_listen(EVENT_HOMEASSISTANT_STOP, on_stop)

url = DEFAULT_URL
url = HA_MANAGED_URL

hass.data[_DATA_GO2RTC] = url
discovery_flow.async_create_flow(
Expand Down
3 changes: 2 additions & 1 deletion homeassistant/components/go2rtc/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@

CONF_DEBUG_UI = "debug_ui"
DEBUG_UI_URL_MESSAGE = "Url and debug_ui cannot be set at the same time."
DEFAULT_URL = "http://localhost:1984/"
HA_MANAGED_API_PORT = 11984
HA_MANAGED_URL = f"http://localhost:{HA_MANAGED_API_PORT}/"
17 changes: 11 additions & 6 deletions homeassistant/components/go2rtc/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from homeassistant.exceptions import HomeAssistantError
from homeassistant.helpers.aiohttp_client import async_get_clientsession

from .const import DEFAULT_URL
from .const import HA_MANAGED_API_PORT, HA_MANAGED_URL

_LOGGER = logging.getLogger(__name__)
_TERMINATE_TIMEOUT = 5
Expand All @@ -26,13 +26,14 @@
# - Clear default ice servers
_GO2RTC_CONFIG_FORMAT = r"""
api:
listen: "{api_ip}:1984"
listen: "{api_ip}:{api_port}"

rtsp:
# ffmpeg needs rtsp for opus audio transcoding
listen: "127.0.0.1:8554"
listen: "127.0.0.1:18554"

webrtc:
listen: ":18555/tcp"
ice_servers: []
"""

Expand All @@ -52,7 +53,11 @@ def _create_temp_file(api_ip: str) -> str:
# 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).encode())
file.write(
_GO2RTC_CONFIG_FORMAT.format(
api_ip=api_ip, api_port=HA_MANAGED_API_PORT
).encode()
)
return file.name


Expand Down Expand Up @@ -113,7 +118,7 @@ async def _start(self) -> None:
raise Go2RTCServerStartError from err

# Check the server version
client = Go2RtcRestClient(async_get_clientsession(self._hass), DEFAULT_URL)
client = Go2RtcRestClient(async_get_clientsession(self._hass), HA_MANAGED_URL)
await client.validate_server_version()

async def _log_output(self, process: asyncio.subprocess.Process) -> None:
Expand Down Expand Up @@ -173,7 +178,7 @@ async def _monitor_process(self) -> None:

async def _monitor_api(self) -> None:
"""Raise if the go2rtc process terminates."""
client = Go2RtcRestClient(async_get_clientsession(self._hass), DEFAULT_URL)
client = Go2RtcRestClient(async_get_clientsession(self._hass), HA_MANAGED_URL)

_LOGGER.debug("Monitoring go2rtc API")
try:
Expand Down
5 changes: 3 additions & 2 deletions tests/components/go2rtc/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,14 @@ async def test_server_run_success(
mock_tempfile.write.assert_called_once_with(
f"""
api:
listen: "{api_ip}:1984"
listen: "{api_ip}:11984"

rtsp:
# ffmpeg needs rtsp for opus audio transcoding
listen: "127.0.0.1:8554"
listen: "127.0.0.1:18554"

webrtc:
listen: ":18555/tcp"
ice_servers: []
""".encode()
)
Expand Down