|
| 1 | +# |
| 2 | +# This file is licensed under the Affero General Public License (AGPL) version 3. |
| 3 | +# |
| 4 | +# Copyright 2014-2016 OpenMarket Ltd |
| 5 | +# Copyright (C) 2023 New Vector, Ltd |
| 6 | +# |
| 7 | +# This program is free software: you can redistribute it and/or modify |
| 8 | +# it under the terms of the GNU Affero General Public License as |
| 9 | +# published by the Free Software Foundation, either version 3 of the |
| 10 | +# License, or (at your option) any later version. |
| 11 | +# |
| 12 | +# See the GNU Affero General Public License for more details: |
| 13 | +# <https://www.gnu.org/licenses/agpl-3.0.html>. |
| 14 | +# |
| 15 | +# Originally licensed under the Apache License, Version 2.0: |
| 16 | +# <http://www.apache.org/licenses/LICENSE-2.0>. |
| 17 | +# |
| 18 | +# [This file includes modifications made by New Vector Limited] |
| 19 | +# |
| 20 | +# |
| 21 | + |
| 22 | +import logging |
| 23 | +from typing import TYPE_CHECKING, Tuple |
| 24 | + |
| 25 | +from synapse.http.server import HttpServer |
| 26 | +from synapse.http.servlet import RestServlet |
| 27 | +from synapse.http.site import SynapseRequest |
| 28 | +from synapse.rest.client._base import client_patterns |
| 29 | +from synapse.types import JsonDict |
| 30 | + |
| 31 | +if TYPE_CHECKING: |
| 32 | + from synapse.server import HomeServer |
| 33 | + |
| 34 | +logger = logging.getLogger(__name__) |
| 35 | + |
| 36 | + |
| 37 | +class MatrixRTCRestServlet(RestServlet): |
| 38 | + PATTERNS = client_patterns(r"/org\.matrix\.msc4143/rtc/services$", releases=()) |
| 39 | + CATEGORY = "Client API requests" |
| 40 | + |
| 41 | + def __init__(self, hs: "HomeServer"): |
| 42 | + super().__init__() |
| 43 | + self.hs = hs |
| 44 | + self.auth = hs.get_auth() |
| 45 | + |
| 46 | + async def on_GET(self, request: SynapseRequest) -> Tuple[int, JsonDict]: |
| 47 | + requester = await self.auth.get_user_by_req(request) |
| 48 | + logger.debug("hello %s", requester.user) |
| 49 | + |
| 50 | + services = self.hs.config.matrix_rtc.services |
| 51 | + |
| 52 | + if services: |
| 53 | + return 200, {"services": services} |
| 54 | + else: |
| 55 | + return 200, {} |
| 56 | + |
| 57 | + |
| 58 | +def register_servlets(hs: "HomeServer", http_server: HttpServer) -> None: |
| 59 | + MatrixRTCRestServlet(hs).register(http_server) |
0 commit comments