-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement API handler to fetch session config
- Loading branch information
1 parent
290c5ce
commit ed6f914
Showing
6 changed files
with
248 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// Copyright (c) 2022-present Mattermost, Inc. All Rights Reserved. | ||
// See LICENSE.txt for license information. | ||
|
||
package service | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"net/http" | ||
|
||
"github.com/mattermost/mattermost/server/public/shared/mlog" | ||
) | ||
|
||
func (s *Service) handleGetSession(w http.ResponseWriter, req *http.Request) { | ||
if req.Method != http.MethodGet { | ||
http.NotFound(w, req) | ||
return | ||
} | ||
|
||
clientID, code, err := s.authHandler(w, req) | ||
if err != nil { | ||
s.log.Error("failed to authenticate", mlog.Err(err), mlog.Int("code", code)) | ||
} | ||
|
||
if clientID == "" { | ||
http.Error(w, "unauthorized", http.StatusUnauthorized) | ||
return | ||
} | ||
|
||
callID := req.PathValue("callID") | ||
if callID == "" { | ||
http.Error(w, "callID is required", http.StatusBadRequest) | ||
return | ||
} | ||
|
||
sessionID := req.PathValue("sessionID") | ||
if sessionID == "" { | ||
http.Error(w, "sessionID is required", http.StatusBadRequest) | ||
return | ||
} | ||
|
||
cfg, err := s.rtcServer.GetSessionConfig(clientID, callID, sessionID) | ||
if err != nil { | ||
http.Error(w, fmt.Sprintf("failed to get session config: %s", err.Error()), http.StatusNotFound) | ||
return | ||
} | ||
|
||
w.Header().Add("Content-Type", "application/json") | ||
if err := json.NewEncoder(w).Encode(cfg); err != nil { | ||
s.log.Error("failed to encode data", mlog.Err(err)) | ||
} | ||
} |