package clientapi import ( "net/http" "strings" "github.com/dariuszjaniak/warp/server/internal/httputil" "github.com/dariuszjaniak/warp/server/internal/userapi" ) // rtcTransportsPath is MSC4143's endpoint for the group call backends a // client may use: the same list /.well-known/matrix/client carries as // org.matrix.msc4143.rtc_foci, behind authentication and without needing // the discovery document. const rtcTransportsPath = "/_matrix/client/unstable/org.matrix.msc4143/rtc/transports" // RTCTransport is one group call backend: a LiveKit SFU, named by the JWT // service that hands out tokens for it. type RTCTransport struct { Type string `json:"type"` LiveKitServiceURL string `json:"livekit_service_url"` } // RTCTransports lists the configured group call backends, or nil for none. func RTCTransports(liveKitServiceURL string) []RTCTransport { if liveKitServiceURL == "" { return nil } return []RTCTransport{{Type: "livekit", LiveKitServiceURL: strings.TrimRight(liveKitServiceURL, "/")}} } type rtcTransportsResponse struct { Transports []RTCTransport `json:"rtc_transports"` } // registerRTCRoutes adds the MSC4143 endpoint, if a backend is configured. // Without one it is left unregistered: the 404 is how a client learns there // is none. func (c *ClientAPI) registerRTCRoutes(r *httputil.Router) { if len(c.rtcTransports) == 0 { return } c.authed(r, "GET "+rtcTransportsPath, c.limitDefault, c.handleRTCTransports) } // handleRTCTransports implements // GET /_matrix/client/unstable/org.matrix.msc4143/rtc/transports. func (c *ClientAPI) handleRTCTransports(w http.ResponseWriter, _ *http.Request, _ userapi.Authenticated) error { httputil.WriteJSON(w, http.StatusOK, rtcTransportsResponse{Transports: c.rtcTransports}) return nil }