Drive-by misc changes. (#3399)

While working on a different service, noticed delegation of setting up
routes to the service itself. So, making that change and making some
methods internal only as there is no need to export them outside the
service.
This commit is contained in:
Raja Subramanian
2025-02-04 12:32:05 +05:30
committed by GitHub
parent 7ff4082e4a
commit bb0ee1139c
2 changed files with 9 additions and 5 deletions

View File

@@ -91,8 +91,12 @@ func NewRTCService(
return s
}
func (s *RTCService) Validate(w http.ResponseWriter, r *http.Request) {
_, _, code, err := s.validate(r)
func (s *RTCService) SetupRoutes(mux *http.ServeMux) {
mux.HandleFunc("/validate", s.validate)
}
func (s *RTCService) validate(w http.ResponseWriter, r *http.Request) {
_, _, code, err := s.validateInternal(r)
if err != nil {
handleError(w, r, code, err)
return
@@ -100,7 +104,7 @@ func (s *RTCService) Validate(w http.ResponseWriter, r *http.Request) {
_, _ = w.Write([]byte("success"))
}
func (s *RTCService) validate(r *http.Request) (livekit.RoomName, routing.ParticipantInit, int, error) {
func (s *RTCService) validateInternal(r *http.Request) (livekit.RoomName, routing.ParticipantInit, int, error) {
claims := GetGrants(r.Context())
var pi routing.ParticipantInit
@@ -214,7 +218,7 @@ func (s *RTCService) ServeHTTP(w http.ResponseWriter, r *http.Request) {
return
}
roomName, pi, code, err := s.validate(r)
roomName, pi, code, err := s.validateInternal(r)
if err != nil {
handleError(w, r, code, err)
return

View File

@@ -134,8 +134,8 @@ func NewLivekitServer(conf *config.Config,
mux.Handle(ingressServer.PathPrefix(), ingressServer)
mux.Handle(sipServer.PathPrefix(), sipServer)
mux.Handle("/rtc", rtcService)
rtcService.SetupRoutes(mux)
mux.Handle("/agent", agentService)
mux.HandleFunc("/rtc/validate", rtcService.Validate)
mux.HandleFunc("/", s.defaultHandler)
s.httpServer = &http.Server{