package webserver import ( "net/http" "os" "github.com/gin-gonic/gin" "github.com/pion/webrtc/v3" "github.com/sirupsen/logrus" ) type Response struct { Succeed bool `json:"succeed"` Message string `json:"message"` Data interface{} `json:"data"` } func (s *Server) getInstruction(c *gin.Context) { f, _ := os.ReadFile(s.options.InstructionFile) c.JSON(http.StatusOK, Response{ Succeed: true, Message: "", Data: string(f), }) } func (s *Server) exchangeSDP(c *gin.Context) { offer := &webrtc.SessionDescription{} if err := c.BindJSON(offer); err != nil { c.JSON(http.StatusBadRequest, Response{ Succeed: false, Message: "bad request", Data: err.Error(), }) logrus.Error(err) return } answer, err := s.RTCConnector.Regist(offer) if err != nil { c.JSON(http.StatusInternalServerError, Response{ Succeed: false, Message: "internal error", Data: err.Error(), }) return } c.JSON(http.StatusOK, Response{ Succeed: true, Message: "", Data: answer, }) } func (s *Server) getICEConfig(c *gin.Context) { c.JSON(http.StatusOK, Response{ Succeed: true, Message: "", Data: s.options.WebRTC.STUNServers, }) } func (s *Server) getName(c *gin.Context) { c.JSON(http.StatusOK, Response{ Succeed: true, Message: "", Data: s.options.Name, }) }