Make new path for signalling v1.5 support. (#4180)

* Make new path for signalling v1.5 support.

To be able to support newer clients to interact with older servers, move
signalling v1.5 to new path (`/rtc1`). On the new path, `join_request`
is required and single peer connection is used.

With the existing path `/rtc`, single peer connection is still supported
if `join_request` is used.

Newer clients connecting to old server should follow
1. Try new path WebSocket
2. If that fails, try new path validate at `/rtc1/validate`.
3. If the above gets a 404 which will happen with older server, revert
   back to old path and signalling 1.0.

Open to suggestions on path name.

* test on both paths

* change path from /rtc1 -> /rtc/v1

* test all rtc service path combinations
This commit is contained in:
Raja Subramanian
2025-12-20 01:02:22 +05:30
committed by GitHub
parent 32cd0370c7
commit cd99fec2e7
10 changed files with 249 additions and 160 deletions
+1 -1
View File
@@ -58,7 +58,7 @@ func NewAPIKeyAuthMiddleware(provider auth.KeyProvider) *APIKeyAuthMiddleware {
}
func (m *APIKeyAuthMiddleware) ServeHTTP(w http.ResponseWriter, r *http.Request, next http.HandlerFunc) {
if r.URL != nil && r.URL.Path == "/rtc/validate" {
if r.URL != nil && (r.URL.Path == "/rtc/validate" || r.URL.Path == "/rtc/v1/validate") {
w.Header().Set("Access-Control-Allow-Origin", "*")
}
+36 -7
View File
@@ -90,13 +90,25 @@ func NewRTCService(
}
func (s *RTCService) SetupRoutes(mux *http.ServeMux) {
mux.Handle("/rtc", s)
mux.HandleFunc("/rtc/validate", s.validate)
mux.HandleFunc("/rtc", s.v0)
mux.HandleFunc("/rtc/validate", s.v0Validate)
mux.HandleFunc("/rtc/v1", s.v1)
mux.HandleFunc("/rtc/v1/validate", s.v1Validate)
}
func (s *RTCService) validate(w http.ResponseWriter, r *http.Request) {
func (s *RTCService) v0Validate(w http.ResponseWriter, r *http.Request) {
lgr := utils.GetLogger(r.Context())
_, _, code, err := s.validateInternal(lgr, r, true)
_, _, code, err := s.validateInternal(lgr, r, false, true)
if err != nil {
HandleError(w, r, code, err)
return
}
_, _ = w.Write([]byte("success"))
}
func (s *RTCService) v1Validate(w http.ResponseWriter, r *http.Request) {
lgr := utils.GetLogger(r.Context())
_, _, code, err := s.validateInternal(lgr, r, true, true)
if err != nil {
HandleError(w, r, code, err)
return
@@ -120,13 +132,22 @@ var gzipReaderPool = sync.Pool{
New: func() any { return &gzip.Reader{} },
}
func (s *RTCService) validateInternal(lgr logger.Logger, r *http.Request, strict bool) (livekit.RoomName, routing.ParticipantInit, int, error) {
func (s *RTCService) validateInternal(
lgr logger.Logger,
r *http.Request,
needsJoinRequest bool,
strict bool,
) (livekit.RoomName, routing.ParticipantInit, int, error) {
var params ValidateConnectRequestParams
useSinglePeerConnection := false
joinRequest := &livekit.JoinRequest{}
wrappedJoinRequestBase64 := r.FormValue("join_request")
if wrappedJoinRequestBase64 == "" {
if needsJoinRequest {
return "", routing.ParticipantInit{}, http.StatusBadRequest, errors.New("join_request is required")
}
params.publish = r.FormValue("publish")
attributesStrParam := r.FormValue("attributes")
@@ -244,7 +265,15 @@ func (s *RTCService) validateInternal(lgr logger.Logger, r *http.Request, strict
return res.roomName, pi, code, err
}
func (s *RTCService) ServeHTTP(w http.ResponseWriter, r *http.Request) {
func (s *RTCService) v0(w http.ResponseWriter, r *http.Request) {
s.serve(w, r, false)
}
func (s *RTCService) v1(w http.ResponseWriter, r *http.Request) {
s.serve(w, r, true)
}
func (s *RTCService) serve(w http.ResponseWriter, r *http.Request, needsJoinRequest bool) {
// reject non websocket requests
if !websocket.IsWebSocketUpgrade(r) {
w.WriteHeader(404)
@@ -295,7 +324,7 @@ func (s *RTCService) ServeHTTP(w http.ResponseWriter, r *http.Request) {
loggerResolved = false
}
roomName, pi, code, err = s.validateInternal(pLogger, r, false)
roomName, pi, code, err = s.validateInternal(pLogger, r, needsJoinRequest, false)
if err != nil {
HandleError(w, r, code, err)
return