Skip to content
Draft
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
17 changes: 17 additions & 0 deletions docs/usage/configuration/config_documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -2575,6 +2575,23 @@ Example configuration:
turn_allow_guests: false
```
---
## MatrixRTC

Options related to advertise MatrixRTC backend infrastructure like SFUs.

---
### `transports`

*(array|null)*

Example configuration:
```
matrix_rtc:
transports::
- type: livekit
livekit_service_url: https://matrix-rtc.example.com/livekit/jwt
```
---
## Registration

Registration can be rate-limited using the parameters in the [Ratelimiting](#ratelimiting) section of this manual.
Expand Down
2 changes: 2 additions & 0 deletions synapse/config/homeserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
from .key import KeyConfig
from .logger import LoggingConfig
from .mas import MasConfig
from .matrixrtc import MatrixRtcConfig
from .metrics import MetricsConfig
from .modules import ModulesConfig
from .oembed import OembedConfig
Expand Down Expand Up @@ -80,6 +81,7 @@ class HomeServerConfig(RootConfig):
OembedConfig,
CaptchaConfig,
VoipConfig,
MatrixRtcConfig,
RegistrationConfig,
AccountValidityConfig,
MetricsConfig,
Expand Down
49 changes: 49 additions & 0 deletions synapse/config/matrixrtc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#
# This file is licensed under the Affero General Public License (AGPL) version 3.
#
# Copyright 2014-2016 OpenMarket Ltd
# Copyright (C) 2023 New Vector, Ltd
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# See the GNU Affero General Public License for more details:
# <https://www.gnu.org/licenses/agpl-3.0.html>.
#
# Originally licensed under the Apache License, Version 2.0:
# <http://www.apache.org/licenses/LICENSE-2.0>.
#
# [This file includes modifications made by New Vector Limited]
#
#

from typing import Any

from synapse.types import JsonDict

from ._base import Config, ConfigError


class MatrixRtcConfig(Config):
section = "matrix_rtc"

def read_config(
self, config: JsonDict, allow_secrets_in_config: bool, **kwargs: Any
) -> None:

matrix_rtc: JsonDict = config.get("matrix_rtc", {})
self.transports = matrix_rtc.get("transports", [])

if not isinstance(self.transports, list):
raise ConfigError(
"MatrixRTC transports needs to be an array of transports",
("matrix_rtc",)
)

if any(("type" not in e for e in self.transports)):
raise ConfigError(
"MatrixRTC transport is missing type",
("matrix_rtc",)
)
2 changes: 2 additions & 0 deletions synapse/rest/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
login,
login_token_request,
logout,
matrixrtc,
mutual_rooms,
notifications,
openid,
Expand Down Expand Up @@ -89,6 +90,7 @@
presence.register_servlets,
directory.register_servlets,
voip.register_servlets,
matrixrtc.register_servlets,
pusher.register_servlets,
push_rule.register_servlets,
logout.register_servlets,
Expand Down
59 changes: 59 additions & 0 deletions synapse/rest/client/matrixrtc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#
# This file is licensed under the Affero General Public License (AGPL) version 3.
#
# Copyright 2014-2016 OpenMarket Ltd
# Copyright (C) 2023 New Vector, Ltd
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# See the GNU Affero General Public License for more details:
# <https://www.gnu.org/licenses/agpl-3.0.html>.
#
# Originally licensed under the Apache License, Version 2.0:
# <http://www.apache.org/licenses/LICENSE-2.0>.
#
# [This file includes modifications made by New Vector Limited]
#
#

import logging
from typing import TYPE_CHECKING, Tuple

from synapse.http.server import HttpServer
from synapse.http.servlet import RestServlet
from synapse.http.site import SynapseRequest
from synapse.rest.client._base import client_patterns
from synapse.types import JsonDict

if TYPE_CHECKING:
from synapse.server import HomeServer

logger = logging.getLogger(__name__)


class MatrixRTCRestServlet(RestServlet):
PATTERNS = client_patterns(r"/org\.matrix\.msc4143/rtc/transports$", releases=())
CATEGORY = "Client API requests"

def __init__(self, hs: "HomeServer"):
super().__init__()
self.hs = hs
self.auth = hs.get_auth()

async def on_GET(self, request: SynapseRequest) -> Tuple[int, JsonDict]:
requester = await self.auth.get_user_by_req(request)
logger.debug("hello %s", requester.user)

transports = self.hs.config.matrix_rtc.transports

if transports:
return 200, {"rtc_transports": transports}
else:
return 200, {}


def register_servlets(hs: "HomeServer", http_server: HttpServer) -> None:
MatrixRTCRestServlet(hs).register(http_server)
55 changes: 55 additions & 0 deletions tests/rest/client/test_matrixrtc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#
# This file is licensed under the Affero General Public License (AGPL) version 3.
#
# Copyright 2014-2016 OpenMarket Ltd
# Copyright (C) 2023 New Vector, Ltd
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# See the GNU Affero General Public License for more details:
# <https://www.gnu.org/licenses/agpl-3.0.html>.
#
# Originally licensed under the Apache License, Version 2.0:
# <http://www.apache.org/licenses/LICENSE-2.0>.
#
# [This file includes modifications made by New Vector Limited]
#
#

"""Tests REST events for /rtc/endpoints path."""


from synapse.rest import admin
from synapse.rest.client import login, matrixrtc, register,room

from tests import unittest

Check failure on line 28 in tests/rest/client/test_matrixrtc.py

View workflow job for this annotation

GitHub Actions / lint

Ruff (I001)

tests/rest/client/test_matrixrtc.py:25:1: I001 Import block is un-sorted or un-formatted

PATH_PREFIX = "/_matrix/client/unstable/org.matrix.msc4143"
RTC_ENDPOINT = {"type": "focusA", "required_field": "theField"}

class MatrixRtcTestCase(unittest.HomeserverTestCase):
"""Tests /rtc/transports REST API."""

servlets = [
admin.register_servlets,
room.register_servlets,
login.register_servlets,
register.register_servlets,
matrixrtc.register_servlets
]

@unittest.override_config({"matrix_rtc": {"transports": [RTC_ENDPOINT]}})
def test_matrixrtc_endpoints(self) -> None:
channel = self.make_request("GET", f"{PATH_PREFIX}/rtc/transports")
self.assertEqual(401, channel.code)

self.register_user("user", "password")
tok = self.login("user", "password")
channel = self.make_request("GET", f"{PATH_PREFIX}/rtc/transports", access_token=tok)
self.assertEqual(200, channel.code)

self.assert_dict({"rtc_transports": [RTC_ENDPOINT]}, channel.json_body)

Loading