|
| 1 | +# |
| 2 | +# This file is licensed under the Affero General Public License (AGPL) version 3. |
| 3 | +# |
| 4 | +# Copyright (C) 2025 New Vector, Ltd |
| 5 | +# |
| 6 | +# This program is free software: you can redistribute it and/or modify |
| 7 | +# it under the terms of the GNU Affero General Public License as |
| 8 | +# published by the Free Software Foundation, either version 3 of the |
| 9 | +# License, or (at your option) any later version. |
| 10 | +# |
| 11 | +# See the GNU Affero General Public License for more details: |
| 12 | +# <https://www.gnu.org/licenses/agpl-3.0.html>. |
| 13 | +# |
| 14 | +# [This file includes modifications made by New Vector Limited] |
| 15 | +# |
| 16 | +# |
| 17 | + |
| 18 | +from typing import Any, Optional |
| 19 | + |
| 20 | +from pydantic import ValidationError |
| 21 | + |
| 22 | +from synapse._pydantic_compat import Field, StrictStr, validator |
| 23 | +from synapse.types import JsonDict |
| 24 | +from synapse.util.pydantic_models import ParseModel |
| 25 | + |
| 26 | +from ._base import Config, ConfigError |
| 27 | + |
| 28 | + |
| 29 | +class TransportConfigModel(ParseModel): |
| 30 | + type: StrictStr |
| 31 | + |
| 32 | + livekit_service_url: Optional[StrictStr] = Field(default=None) |
| 33 | + """An optional livekit service URL. Only required if type is "livekit".""" |
| 34 | + |
| 35 | + @validator("livekit_service_url", always=True) |
| 36 | + def validate_livekit_service_url(cls, v: Any, values: dict) -> Any: |
| 37 | + if values.get("type") == "livekit" and not v: |
| 38 | + raise ValueError( |
| 39 | + "You must set a `livekit_service_url` when using the 'livekit' transport." |
| 40 | + ) |
| 41 | + |
| 42 | + return v |
| 43 | + |
| 44 | + |
| 45 | +class MatrixRtcConfigModel(ParseModel): |
| 46 | + transports: list = [] |
| 47 | + |
| 48 | + |
| 49 | +class MatrixRtcConfig(Config): |
| 50 | + section = "matrix_rtc" |
| 51 | + |
| 52 | + def read_config( |
| 53 | + self, config: JsonDict, allow_secrets_in_config: bool, **kwargs: Any |
| 54 | + ) -> None: |
| 55 | + matrix_rtc = config.get("matrix_rtc", {}) |
| 56 | + if matrix_rtc is None: |
| 57 | + matrix_rtc = {} |
| 58 | + |
| 59 | + try: |
| 60 | + parsed = MatrixRtcConfigModel(**matrix_rtc) |
| 61 | + except ValidationError as e: |
| 62 | + raise ConfigError( |
| 63 | + "Could not validate matrix_rtc config", |
| 64 | + ("matrix_rtc",), |
| 65 | + ) from e |
| 66 | + |
| 67 | + self.transports = parsed.transports |
0 commit comments