2021-07-04 16:13:49 +00:00
|
|
|
package core
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
2023-09-27 13:18:02 +00:00
|
|
|
"fmt"
|
2021-07-04 16:13:49 +00:00
|
|
|
"net/http"
|
|
|
|
"reflect"
|
2023-10-07 21:32:15 +00:00
|
|
|
"sort"
|
2023-05-16 17:48:13 +00:00
|
|
|
"strconv"
|
2021-07-04 16:13:49 +00:00
|
|
|
"sync"
|
2023-08-07 15:16:33 +00:00
|
|
|
"time"
|
2021-07-04 16:13:49 +00:00
|
|
|
|
|
|
|
"github.com/gin-gonic/gin"
|
2023-05-16 13:59:37 +00:00
|
|
|
"github.com/google/uuid"
|
2021-07-04 16:13:49 +00:00
|
|
|
|
2023-05-16 14:14:20 +00:00
|
|
|
"github.com/bluenviron/mediamtx/internal/conf"
|
|
|
|
"github.com/bluenviron/mediamtx/internal/logger"
|
2023-10-26 19:46:18 +00:00
|
|
|
"github.com/bluenviron/mediamtx/internal/protocols/httpserv"
|
2021-07-04 16:13:49 +00:00
|
|
|
)
|
|
|
|
|
2021-08-12 09:48:47 +00:00
|
|
|
func interfaceIsEmpty(i interface{}) bool {
|
|
|
|
return reflect.ValueOf(i).Kind() != reflect.Ptr || reflect.ValueOf(i).IsNil()
|
|
|
|
}
|
|
|
|
|
2023-05-16 17:48:13 +00:00
|
|
|
func paginate2(itemsPtr interface{}, itemsPerPage int, page int) int {
|
|
|
|
ritems := reflect.ValueOf(itemsPtr).Elem()
|
|
|
|
|
|
|
|
itemsLen := ritems.Len()
|
|
|
|
if itemsLen == 0 {
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2023-05-18 16:59:51 +00:00
|
|
|
pageCount := (itemsLen / itemsPerPage)
|
|
|
|
if (itemsLen % itemsPerPage) != 0 {
|
|
|
|
pageCount++
|
|
|
|
}
|
2023-05-16 17:48:13 +00:00
|
|
|
|
|
|
|
min := page * itemsPerPage
|
|
|
|
if min >= itemsLen {
|
|
|
|
min = itemsLen - 1
|
|
|
|
}
|
|
|
|
|
|
|
|
max := (page + 1) * itemsPerPage
|
|
|
|
if max >= itemsLen {
|
|
|
|
max = itemsLen
|
|
|
|
}
|
|
|
|
|
|
|
|
ritems.Set(ritems.Slice(min, max))
|
|
|
|
|
|
|
|
return pageCount
|
|
|
|
}
|
|
|
|
|
|
|
|
func paginate(itemsPtr interface{}, itemsPerPageStr string, pageStr string) (int, error) {
|
|
|
|
itemsPerPage := 100
|
|
|
|
|
|
|
|
if itemsPerPageStr != "" {
|
|
|
|
tmp, err := strconv.ParseUint(itemsPerPageStr, 10, 31)
|
|
|
|
if err != nil {
|
|
|
|
return 0, err
|
|
|
|
}
|
|
|
|
itemsPerPage = int(tmp)
|
|
|
|
}
|
|
|
|
|
|
|
|
page := 0
|
|
|
|
|
|
|
|
if pageStr != "" {
|
|
|
|
tmp, err := strconv.ParseUint(pageStr, 10, 31)
|
|
|
|
if err != nil {
|
|
|
|
return 0, err
|
|
|
|
}
|
|
|
|
page = int(tmp)
|
|
|
|
}
|
|
|
|
|
|
|
|
return paginate2(itemsPtr, itemsPerPage, page), nil
|
|
|
|
}
|
|
|
|
|
2023-10-07 21:32:15 +00:00
|
|
|
func sortedKeys(paths map[string]*conf.OptionalPath) []string {
|
|
|
|
ret := make([]string, len(paths))
|
|
|
|
i := 0
|
|
|
|
for name := range paths {
|
|
|
|
ret[i] = name
|
|
|
|
i++
|
|
|
|
}
|
|
|
|
sort.Strings(ret)
|
|
|
|
return ret
|
|
|
|
}
|
|
|
|
|
2023-07-11 14:51:23 +00:00
|
|
|
func paramName(ctx *gin.Context) (string, bool) {
|
|
|
|
name := ctx.Param("name")
|
|
|
|
|
|
|
|
if len(name) < 2 || name[0] != '/' {
|
|
|
|
return "", false
|
|
|
|
}
|
|
|
|
|
|
|
|
return name[1:], true
|
|
|
|
}
|
|
|
|
|
2021-08-11 10:45:53 +00:00
|
|
|
type apiPathManager interface {
|
2023-10-07 21:32:15 +00:00
|
|
|
apiPathsList() (*apiPathList, error)
|
2023-05-18 13:07:47 +00:00
|
|
|
apiPathsGet(string) (*apiPath, error)
|
2021-08-11 10:45:53 +00:00
|
|
|
}
|
|
|
|
|
2023-05-16 13:59:37 +00:00
|
|
|
type apiHLSManager interface {
|
2023-10-07 21:32:15 +00:00
|
|
|
apiMuxersList() (*apiHLSMuxerList, error)
|
2023-05-18 13:07:47 +00:00
|
|
|
apiMuxersGet(string) (*apiHLSMuxer, error)
|
2022-12-15 23:50:47 +00:00
|
|
|
}
|
|
|
|
|
2021-08-11 10:45:53 +00:00
|
|
|
type apiRTSPServer interface {
|
2023-05-18 13:07:47 +00:00
|
|
|
apiConnsList() (*apiRTSPConnsList, error)
|
|
|
|
apiConnsGet(uuid.UUID) (*apiRTSPConn, error)
|
2023-10-07 21:32:15 +00:00
|
|
|
apiSessionsList() (*apiRTSPSessionList, error)
|
2023-05-18 13:07:47 +00:00
|
|
|
apiSessionsGet(uuid.UUID) (*apiRTSPSession, error)
|
|
|
|
apiSessionsKick(uuid.UUID) error
|
2021-08-11 10:45:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type apiRTMPServer interface {
|
2023-10-07 21:32:15 +00:00
|
|
|
apiConnsList() (*apiRTMPConnList, error)
|
2023-05-18 13:07:47 +00:00
|
|
|
apiConnsGet(uuid.UUID) (*apiRTMPConn, error)
|
|
|
|
apiConnsKick(uuid.UUID) error
|
|
|
|
}
|
|
|
|
|
|
|
|
type apiWebRTCManager interface {
|
2023-10-07 21:32:15 +00:00
|
|
|
apiSessionsList() (*apiWebRTCSessionList, error)
|
2023-05-18 13:07:47 +00:00
|
|
|
apiSessionsGet(uuid.UUID) (*apiWebRTCSession, error)
|
|
|
|
apiSessionsKick(uuid.UUID) error
|
2021-08-11 10:45:53 +00:00
|
|
|
}
|
|
|
|
|
2023-07-31 19:20:09 +00:00
|
|
|
type apiSRTServer interface {
|
2023-10-07 21:32:15 +00:00
|
|
|
apiConnsList() (*apiSRTConnList, error)
|
2023-07-31 19:20:09 +00:00
|
|
|
apiConnsGet(uuid.UUID) (*apiSRTConn, error)
|
|
|
|
apiConnsKick(uuid.UUID) error
|
|
|
|
}
|
|
|
|
|
2021-07-04 16:13:49 +00:00
|
|
|
type apiParent interface {
|
2023-05-04 18:16:41 +00:00
|
|
|
logger.Writer
|
2022-08-04 19:07:17 +00:00
|
|
|
apiConfigSet(conf *conf.Conf)
|
2021-07-04 16:13:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type api struct {
|
2023-05-16 13:59:37 +00:00
|
|
|
conf *conf.Conf
|
|
|
|
pathManager apiPathManager
|
|
|
|
rtspServer apiRTSPServer
|
|
|
|
rtspsServer apiRTSPServer
|
|
|
|
rtmpServer apiRTMPServer
|
|
|
|
rtmpsServer apiRTMPServer
|
|
|
|
hlsManager apiHLSManager
|
|
|
|
webRTCManager apiWebRTCManager
|
2023-07-31 19:20:09 +00:00
|
|
|
srtServer apiSRTServer
|
2023-05-16 13:59:37 +00:00
|
|
|
parent apiParent
|
2021-07-04 16:13:49 +00:00
|
|
|
|
2023-07-30 21:03:00 +00:00
|
|
|
httpServer *httpserv.WrappedServer
|
2023-04-11 18:42:40 +00:00
|
|
|
mutex sync.Mutex
|
2021-07-04 16:13:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func newAPI(
|
|
|
|
address string,
|
2023-04-11 18:47:19 +00:00
|
|
|
readTimeout conf.StringDuration,
|
2021-07-04 16:13:49 +00:00
|
|
|
conf *conf.Conf,
|
2021-08-11 10:45:53 +00:00
|
|
|
pathManager apiPathManager,
|
|
|
|
rtspServer apiRTSPServer,
|
|
|
|
rtspsServer apiRTSPServer,
|
|
|
|
rtmpServer apiRTMPServer,
|
2022-08-16 11:53:04 +00:00
|
|
|
rtmpsServer apiRTMPServer,
|
2023-05-16 13:59:37 +00:00
|
|
|
hlsManager apiHLSManager,
|
|
|
|
webRTCManager apiWebRTCManager,
|
2023-07-31 19:20:09 +00:00
|
|
|
srtServer apiSRTServer,
|
2021-07-04 16:13:49 +00:00
|
|
|
parent apiParent,
|
|
|
|
) (*api, error) {
|
|
|
|
a := &api{
|
2023-05-16 13:59:37 +00:00
|
|
|
conf: conf,
|
|
|
|
pathManager: pathManager,
|
|
|
|
rtspServer: rtspServer,
|
|
|
|
rtspsServer: rtspsServer,
|
|
|
|
rtmpServer: rtmpServer,
|
|
|
|
rtmpsServer: rtmpsServer,
|
|
|
|
hlsManager: hlsManager,
|
|
|
|
webRTCManager: webRTCManager,
|
2023-07-31 19:20:09 +00:00
|
|
|
srtServer: srtServer,
|
2023-05-16 13:59:37 +00:00
|
|
|
parent: parent,
|
2021-07-04 16:13:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
router := gin.New()
|
2023-08-13 14:38:23 +00:00
|
|
|
router.SetTrustedProxies(nil) //nolint:errcheck
|
2023-04-09 15:12:50 +00:00
|
|
|
|
2023-08-07 15:16:33 +00:00
|
|
|
group := router.Group("/")
|
2021-11-05 16:18:21 +00:00
|
|
|
|
2023-10-07 21:32:15 +00:00
|
|
|
group.GET("/v3/config/global/get", a.onConfigGlobalGet)
|
|
|
|
group.PATCH("/v3/config/global/patch", a.onConfigGlobalPatch)
|
|
|
|
|
|
|
|
group.GET("/v3/config/pathdefaults/get", a.onConfigPathDefaultsGet)
|
|
|
|
group.PATCH("/v3/config/pathdefaults/patch", a.onConfigPathDefaultsPatch)
|
|
|
|
|
|
|
|
group.GET("/v3/config/paths/list", a.onConfigPathsList)
|
|
|
|
group.GET("/v3/config/paths/get/*name", a.onConfigPathsGet)
|
|
|
|
group.POST("/v3/config/paths/add/*name", a.onConfigPathsAdd)
|
|
|
|
group.PATCH("/v3/config/paths/patch/*name", a.onConfigPathsPatch)
|
|
|
|
group.POST("/v3/config/paths/replace/*name", a.onConfigPathsReplace)
|
|
|
|
group.DELETE("/v3/config/paths/delete/*name", a.onConfigPathsDelete)
|
|
|
|
|
|
|
|
group.GET("/v3/paths/list", a.onPathsList)
|
|
|
|
group.GET("/v3/paths/get/*name", a.onPathsGet)
|
2021-11-05 16:53:24 +00:00
|
|
|
|
2023-05-16 13:59:37 +00:00
|
|
|
if !interfaceIsEmpty(a.hlsManager) {
|
2023-10-07 21:32:15 +00:00
|
|
|
group.GET("/v3/hlsmuxers/list", a.onHLSMuxersList)
|
|
|
|
group.GET("/v3/hlsmuxers/get/*name", a.onHLSMuxersGet)
|
2022-12-15 23:50:47 +00:00
|
|
|
}
|
|
|
|
|
2021-11-05 16:18:21 +00:00
|
|
|
if !interfaceIsEmpty(a.rtspServer) {
|
2023-10-07 21:32:15 +00:00
|
|
|
group.GET("/v3/rtspconns/list", a.onRTSPConnsList)
|
|
|
|
group.GET("/v3/rtspconns/get/:id", a.onRTSPConnsGet)
|
|
|
|
group.GET("/v3/rtspsessions/list", a.onRTSPSessionsList)
|
|
|
|
group.GET("/v3/rtspsessions/get/:id", a.onRTSPSessionsGet)
|
|
|
|
group.POST("/v3/rtspsessions/kick/:id", a.onRTSPSessionsKick)
|
2021-11-05 16:18:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if !interfaceIsEmpty(a.rtspsServer) {
|
2023-10-07 21:32:15 +00:00
|
|
|
group.GET("/v3/rtspsconns/list", a.onRTSPSConnsList)
|
|
|
|
group.GET("/v3/rtspsconns/get/:id", a.onRTSPSConnsGet)
|
|
|
|
group.GET("/v3/rtspssessions/list", a.onRTSPSSessionsList)
|
|
|
|
group.GET("/v3/rtspssessions/get/:id", a.onRTSPSSessionsGet)
|
|
|
|
group.POST("/v3/rtspssessions/kick/:id", a.onRTSPSSessionsKick)
|
2021-11-05 16:18:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if !interfaceIsEmpty(a.rtmpServer) {
|
2023-10-07 21:32:15 +00:00
|
|
|
group.GET("/v3/rtmpconns/list", a.onRTMPConnsList)
|
|
|
|
group.GET("/v3/rtmpconns/get/:id", a.onRTMPConnsGet)
|
|
|
|
group.POST("/v3/rtmpconns/kick/:id", a.onRTMPConnsKick)
|
2021-11-05 16:18:21 +00:00
|
|
|
}
|
|
|
|
|
2022-08-16 11:53:04 +00:00
|
|
|
if !interfaceIsEmpty(a.rtmpsServer) {
|
2023-10-07 21:32:15 +00:00
|
|
|
group.GET("/v3/rtmpsconns/list", a.onRTMPSConnsList)
|
|
|
|
group.GET("/v3/rtmpsconns/get/:id", a.onRTMPSConnsGet)
|
|
|
|
group.POST("/v3/rtmpsconns/kick/:id", a.onRTMPSConnsKick)
|
2022-08-16 11:53:04 +00:00
|
|
|
}
|
|
|
|
|
2023-05-16 13:59:37 +00:00
|
|
|
if !interfaceIsEmpty(a.webRTCManager) {
|
2023-10-07 21:32:15 +00:00
|
|
|
group.GET("/v3/webrtcsessions/list", a.onWebRTCSessionsList)
|
|
|
|
group.GET("/v3/webrtcsessions/get/:id", a.onWebRTCSessionsGet)
|
|
|
|
group.POST("/v3/webrtcsessions/kick/:id", a.onWebRTCSessionsKick)
|
2021-11-05 16:18:21 +00:00
|
|
|
}
|
2021-07-04 16:13:49 +00:00
|
|
|
|
2023-07-31 19:20:09 +00:00
|
|
|
if !interfaceIsEmpty(a.srtServer) {
|
2023-10-07 21:32:15 +00:00
|
|
|
group.GET("/v3/srtconns/list", a.onSRTConnsList)
|
|
|
|
group.GET("/v3/srtconns/get/:id", a.onSRTConnsGet)
|
|
|
|
group.POST("/v3/srtconns/kick/:id", a.onSRTConnsKick)
|
2023-07-31 19:20:09 +00:00
|
|
|
}
|
|
|
|
|
2023-07-30 21:03:00 +00:00
|
|
|
network, address := restrictNetwork("tcp", address)
|
|
|
|
|
2023-05-16 18:12:45 +00:00
|
|
|
var err error
|
2023-07-30 21:03:00 +00:00
|
|
|
a.httpServer, err = httpserv.NewWrappedServer(
|
|
|
|
network,
|
2023-05-16 18:12:45 +00:00
|
|
|
address,
|
2023-08-07 15:16:33 +00:00
|
|
|
time.Duration(readTimeout),
|
2023-05-16 18:12:45 +00:00
|
|
|
"",
|
|
|
|
"",
|
|
|
|
router,
|
2023-08-07 15:16:33 +00:00
|
|
|
a,
|
2023-05-16 18:12:45 +00:00
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
2023-01-08 12:23:11 +00:00
|
|
|
}
|
2021-07-04 16:13:49 +00:00
|
|
|
|
2023-05-04 18:16:41 +00:00
|
|
|
a.Log(logger.Info, "listener opened on "+address)
|
2021-07-04 16:13:49 +00:00
|
|
|
|
|
|
|
return a, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a *api) close() {
|
2023-05-04 18:16:41 +00:00
|
|
|
a.Log(logger.Info, "listener is closing")
|
2023-07-30 21:03:00 +00:00
|
|
|
a.httpServer.Close()
|
2021-07-04 16:13:49 +00:00
|
|
|
}
|
|
|
|
|
2023-05-04 18:16:41 +00:00
|
|
|
func (a *api) Log(level logger.Level, format string, args ...interface{}) {
|
2021-07-04 16:13:49 +00:00
|
|
|
a.parent.Log(level, "[API] "+format, args...)
|
|
|
|
}
|
|
|
|
|
2023-09-27 13:18:02 +00:00
|
|
|
// error coming from something the user inserted into the request.
|
|
|
|
func (a *api) writeUserError(ctx *gin.Context, err error) {
|
|
|
|
a.Log(logger.Error, err.Error())
|
|
|
|
ctx.AbortWithStatus(http.StatusBadRequest)
|
|
|
|
}
|
|
|
|
|
|
|
|
// error coming from the server.
|
|
|
|
func (a *api) writeServerError(ctx *gin.Context, err error) {
|
|
|
|
a.Log(logger.Error, err.Error())
|
|
|
|
ctx.AbortWithStatus(http.StatusInternalServerError)
|
|
|
|
}
|
|
|
|
|
2023-10-07 21:32:15 +00:00
|
|
|
func (a *api) onConfigGlobalGet(ctx *gin.Context) {
|
2021-07-04 16:13:49 +00:00
|
|
|
a.mutex.Lock()
|
|
|
|
c := a.conf
|
|
|
|
a.mutex.Unlock()
|
|
|
|
|
2023-10-07 21:32:15 +00:00
|
|
|
ctx.JSON(http.StatusOK, c.Global())
|
2021-07-04 16:13:49 +00:00
|
|
|
}
|
|
|
|
|
2023-10-07 21:32:15 +00:00
|
|
|
func (a *api) onConfigGlobalPatch(ctx *gin.Context) {
|
|
|
|
var c conf.OptionalGlobal
|
|
|
|
err := json.NewDecoder(ctx.Request.Body).Decode(&c)
|
2021-07-04 16:13:49 +00:00
|
|
|
if err != nil {
|
2023-09-27 13:18:02 +00:00
|
|
|
a.writeUserError(ctx, err)
|
2021-07-04 16:13:49 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
a.mutex.Lock()
|
2021-09-06 16:39:15 +00:00
|
|
|
defer a.mutex.Unlock()
|
|
|
|
|
2023-03-31 14:22:08 +00:00
|
|
|
newConf := a.conf.Clone()
|
|
|
|
|
2023-10-07 21:32:15 +00:00
|
|
|
newConf.PatchGlobal(&c)
|
2021-07-04 16:13:49 +00:00
|
|
|
|
2023-05-06 21:00:42 +00:00
|
|
|
err = newConf.Check()
|
2021-07-04 16:13:49 +00:00
|
|
|
if err != nil {
|
2023-09-27 13:18:02 +00:00
|
|
|
a.writeUserError(ctx, err)
|
2021-07-04 16:13:49 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2023-03-31 14:22:08 +00:00
|
|
|
a.conf = newConf
|
2021-08-07 14:07:08 +00:00
|
|
|
|
2021-07-04 16:13:49 +00:00
|
|
|
// since reloading the configuration can cause the shutdown of the API,
|
|
|
|
// call it in a goroutine
|
2023-03-31 14:22:08 +00:00
|
|
|
go a.parent.apiConfigSet(newConf)
|
2021-07-04 16:13:49 +00:00
|
|
|
|
|
|
|
ctx.Status(http.StatusOK)
|
|
|
|
}
|
|
|
|
|
2023-10-07 21:32:15 +00:00
|
|
|
func (a *api) onConfigPathDefaultsGet(ctx *gin.Context) {
|
|
|
|
a.mutex.Lock()
|
|
|
|
c := a.conf
|
|
|
|
a.mutex.Unlock()
|
|
|
|
|
|
|
|
ctx.JSON(http.StatusOK, c.PathDefaults)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a *api) onConfigPathDefaultsPatch(ctx *gin.Context) {
|
|
|
|
var p conf.OptionalPath
|
|
|
|
err := json.NewDecoder(ctx.Request.Body).Decode(&p)
|
|
|
|
if err != nil {
|
|
|
|
a.writeUserError(ctx, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
a.mutex.Lock()
|
|
|
|
defer a.mutex.Unlock()
|
|
|
|
|
|
|
|
newConf := a.conf.Clone()
|
|
|
|
|
|
|
|
newConf.PatchPathDefaults(&p)
|
|
|
|
|
|
|
|
err = newConf.Check()
|
|
|
|
if err != nil {
|
|
|
|
a.writeUserError(ctx, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
a.conf = newConf
|
|
|
|
a.parent.apiConfigSet(newConf)
|
|
|
|
|
|
|
|
ctx.Status(http.StatusOK)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a *api) onConfigPathsList(ctx *gin.Context) {
|
|
|
|
a.mutex.Lock()
|
|
|
|
c := a.conf
|
|
|
|
a.mutex.Unlock()
|
|
|
|
|
|
|
|
data := &apiPathConfList{
|
|
|
|
Items: make([]*conf.OptionalPath, len(c.OptionalPaths)),
|
|
|
|
}
|
|
|
|
|
|
|
|
for i, key := range sortedKeys(c.OptionalPaths) {
|
|
|
|
data.Items[i] = c.OptionalPaths[key]
|
|
|
|
}
|
|
|
|
|
|
|
|
data.ItemCount = len(data.Items)
|
|
|
|
pageCount, err := paginate(&data.Items, ctx.Query("itemsPerPage"), ctx.Query("page"))
|
|
|
|
if err != nil {
|
|
|
|
a.writeUserError(ctx, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
data.PageCount = pageCount
|
|
|
|
|
|
|
|
ctx.JSON(http.StatusOK, data)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a *api) onConfigPathsGet(ctx *gin.Context) {
|
|
|
|
name, ok := paramName(ctx)
|
|
|
|
if !ok {
|
|
|
|
a.writeUserError(ctx, fmt.Errorf("invalid name"))
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
a.mutex.Lock()
|
|
|
|
c := a.conf
|
|
|
|
a.mutex.Unlock()
|
|
|
|
|
|
|
|
p, ok := c.OptionalPaths[name]
|
|
|
|
if !ok {
|
2023-10-27 18:23:46 +00:00
|
|
|
a.writeServerError(ctx, fmt.Errorf("path configuration not found"))
|
2023-10-07 21:32:15 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx.JSON(http.StatusOK, p)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a *api) onConfigPathsAdd(ctx *gin.Context) { //nolint:dupl
|
2023-07-11 14:51:23 +00:00
|
|
|
name, ok := paramName(ctx)
|
|
|
|
if !ok {
|
2023-09-27 13:18:02 +00:00
|
|
|
a.writeUserError(ctx, fmt.Errorf("invalid name"))
|
2021-09-23 07:07:36 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2023-10-07 21:32:15 +00:00
|
|
|
var p conf.OptionalPath
|
|
|
|
err := json.NewDecoder(ctx.Request.Body).Decode(&p)
|
2021-07-04 16:13:49 +00:00
|
|
|
if err != nil {
|
2023-09-27 13:18:02 +00:00
|
|
|
a.writeUserError(ctx, err)
|
2021-07-04 16:13:49 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
a.mutex.Lock()
|
2021-09-06 16:39:15 +00:00
|
|
|
defer a.mutex.Unlock()
|
|
|
|
|
2023-03-31 14:22:08 +00:00
|
|
|
newConf := a.conf.Clone()
|
2021-07-04 16:13:49 +00:00
|
|
|
|
2023-10-07 21:32:15 +00:00
|
|
|
err = newConf.AddPath(name, &p)
|
|
|
|
if err != nil {
|
|
|
|
a.writeUserError(ctx, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
err = newConf.Check()
|
|
|
|
if err != nil {
|
|
|
|
a.writeUserError(ctx, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
a.conf = newConf
|
|
|
|
a.parent.apiConfigSet(newConf)
|
|
|
|
|
|
|
|
ctx.Status(http.StatusOK)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a *api) onConfigPathsPatch(ctx *gin.Context) { //nolint:dupl
|
|
|
|
name, ok := paramName(ctx)
|
|
|
|
if !ok {
|
|
|
|
a.writeUserError(ctx, fmt.Errorf("invalid name"))
|
2021-07-04 16:13:49 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2023-10-07 21:32:15 +00:00
|
|
|
var p conf.OptionalPath
|
|
|
|
err := json.NewDecoder(ctx.Request.Body).Decode(&p)
|
|
|
|
if err != nil {
|
|
|
|
a.writeUserError(ctx, err)
|
|
|
|
return
|
|
|
|
}
|
2023-06-02 16:43:04 +00:00
|
|
|
|
2023-10-07 21:32:15 +00:00
|
|
|
a.mutex.Lock()
|
|
|
|
defer a.mutex.Unlock()
|
2023-06-02 16:43:04 +00:00
|
|
|
|
2023-10-07 21:32:15 +00:00
|
|
|
newConf := a.conf.Clone()
|
2021-09-27 12:59:27 +00:00
|
|
|
|
2023-10-07 21:32:15 +00:00
|
|
|
err = newConf.PatchPath(name, &p)
|
|
|
|
if err != nil {
|
|
|
|
a.writeUserError(ctx, err)
|
|
|
|
return
|
|
|
|
}
|
2021-07-04 16:13:49 +00:00
|
|
|
|
2023-05-06 21:00:42 +00:00
|
|
|
err = newConf.Check()
|
2021-07-04 16:13:49 +00:00
|
|
|
if err != nil {
|
2023-09-27 13:18:02 +00:00
|
|
|
a.writeUserError(ctx, err)
|
2021-07-04 16:13:49 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2023-03-31 14:22:08 +00:00
|
|
|
a.conf = newConf
|
2023-10-07 21:32:15 +00:00
|
|
|
a.parent.apiConfigSet(newConf)
|
2021-07-04 16:13:49 +00:00
|
|
|
|
|
|
|
ctx.Status(http.StatusOK)
|
|
|
|
}
|
|
|
|
|
2023-10-07 21:32:15 +00:00
|
|
|
func (a *api) onConfigPathsReplace(ctx *gin.Context) { //nolint:dupl
|
2023-07-11 14:51:23 +00:00
|
|
|
name, ok := paramName(ctx)
|
|
|
|
if !ok {
|
2023-09-27 13:18:02 +00:00
|
|
|
a.writeUserError(ctx, fmt.Errorf("invalid name"))
|
2021-09-23 07:07:36 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2023-10-07 21:32:15 +00:00
|
|
|
var p conf.OptionalPath
|
|
|
|
err := json.NewDecoder(ctx.Request.Body).Decode(&p)
|
2021-07-04 16:13:49 +00:00
|
|
|
if err != nil {
|
2023-09-27 13:18:02 +00:00
|
|
|
a.writeUserError(ctx, err)
|
2021-07-04 16:13:49 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
a.mutex.Lock()
|
2021-09-06 16:39:15 +00:00
|
|
|
defer a.mutex.Unlock()
|
|
|
|
|
2023-03-31 14:22:08 +00:00
|
|
|
newConf := a.conf.Clone()
|
2021-07-04 16:13:49 +00:00
|
|
|
|
2023-10-07 21:32:15 +00:00
|
|
|
err = newConf.ReplacePath(name, &p)
|
|
|
|
if err != nil {
|
|
|
|
a.writeUserError(ctx, err)
|
2021-07-04 16:13:49 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2023-05-06 21:00:42 +00:00
|
|
|
err = newConf.Check()
|
2021-07-04 16:13:49 +00:00
|
|
|
if err != nil {
|
2023-09-27 13:18:02 +00:00
|
|
|
a.writeUserError(ctx, err)
|
2021-07-04 16:13:49 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2023-03-31 14:22:08 +00:00
|
|
|
a.conf = newConf
|
2023-10-07 21:32:15 +00:00
|
|
|
a.parent.apiConfigSet(newConf)
|
2021-07-04 16:13:49 +00:00
|
|
|
|
|
|
|
ctx.Status(http.StatusOK)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a *api) onConfigPathsDelete(ctx *gin.Context) {
|
2023-07-11 14:51:23 +00:00
|
|
|
name, ok := paramName(ctx)
|
|
|
|
if !ok {
|
2023-09-27 13:18:02 +00:00
|
|
|
a.writeUserError(ctx, fmt.Errorf("invalid name"))
|
2021-09-23 07:07:36 +00:00
|
|
|
return
|
|
|
|
}
|
2021-07-04 16:13:49 +00:00
|
|
|
|
|
|
|
a.mutex.Lock()
|
2021-09-06 16:39:15 +00:00
|
|
|
defer a.mutex.Unlock()
|
|
|
|
|
2023-10-07 21:32:15 +00:00
|
|
|
newConf := a.conf.Clone()
|
|
|
|
|
|
|
|
err := newConf.RemovePath(name)
|
|
|
|
if err != nil {
|
|
|
|
a.writeUserError(ctx, err)
|
2021-07-04 16:13:49 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2023-10-07 21:32:15 +00:00
|
|
|
err = newConf.Check()
|
2021-07-04 16:13:49 +00:00
|
|
|
if err != nil {
|
2023-09-27 13:18:02 +00:00
|
|
|
a.writeUserError(ctx, err)
|
2021-07-04 16:13:49 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2023-03-31 14:22:08 +00:00
|
|
|
a.conf = newConf
|
2023-10-07 21:32:15 +00:00
|
|
|
a.parent.apiConfigSet(newConf)
|
2021-07-04 16:13:49 +00:00
|
|
|
|
|
|
|
ctx.Status(http.StatusOK)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a *api) onPathsList(ctx *gin.Context) {
|
2023-05-18 13:07:47 +00:00
|
|
|
data, err := a.pathManager.apiPathsList()
|
|
|
|
if err != nil {
|
2023-09-27 13:18:02 +00:00
|
|
|
a.writeServerError(ctx, err)
|
2022-11-09 17:31:31 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2023-05-18 18:05:59 +00:00
|
|
|
data.ItemCount = len(data.Items)
|
2023-05-18 13:07:47 +00:00
|
|
|
pageCount, err := paginate(&data.Items, ctx.Query("itemsPerPage"), ctx.Query("page"))
|
2023-05-16 17:48:13 +00:00
|
|
|
if err != nil {
|
2023-09-27 13:18:02 +00:00
|
|
|
a.writeUserError(ctx, err)
|
2023-05-16 17:48:13 +00:00
|
|
|
return
|
|
|
|
}
|
2023-05-18 13:07:47 +00:00
|
|
|
data.PageCount = pageCount
|
|
|
|
|
|
|
|
ctx.JSON(http.StatusOK, data)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a *api) onPathsGet(ctx *gin.Context) {
|
2023-07-11 14:51:23 +00:00
|
|
|
name, ok := paramName(ctx)
|
|
|
|
if !ok {
|
2023-09-27 13:18:02 +00:00
|
|
|
a.writeUserError(ctx, fmt.Errorf("invalid name"))
|
2023-07-10 17:53:25 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
data, err := a.pathManager.apiPathsGet(name)
|
2023-05-18 13:07:47 +00:00
|
|
|
if err != nil {
|
2023-10-27 18:23:46 +00:00
|
|
|
a.writeServerError(ctx, err)
|
2023-05-18 13:07:47 +00:00
|
|
|
return
|
|
|
|
}
|
2023-05-16 17:48:13 +00:00
|
|
|
|
2023-05-18 13:07:47 +00:00
|
|
|
ctx.JSON(http.StatusOK, data)
|
2022-11-09 17:31:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (a *api) onRTSPConnsList(ctx *gin.Context) {
|
2023-05-18 13:07:47 +00:00
|
|
|
data, err := a.rtspServer.apiConnsList()
|
|
|
|
if err != nil {
|
2023-09-27 13:18:02 +00:00
|
|
|
a.writeServerError(ctx, err)
|
2021-07-04 16:13:49 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2023-05-18 18:05:59 +00:00
|
|
|
data.ItemCount = len(data.Items)
|
2023-05-18 13:07:47 +00:00
|
|
|
pageCount, err := paginate(&data.Items, ctx.Query("itemsPerPage"), ctx.Query("page"))
|
2023-05-16 17:48:13 +00:00
|
|
|
if err != nil {
|
2023-09-27 13:18:02 +00:00
|
|
|
a.writeUserError(ctx, err)
|
2023-05-16 17:48:13 +00:00
|
|
|
return
|
|
|
|
}
|
2023-05-18 13:07:47 +00:00
|
|
|
data.PageCount = pageCount
|
2023-05-16 17:48:13 +00:00
|
|
|
|
2023-05-18 13:07:47 +00:00
|
|
|
ctx.JSON(http.StatusOK, data)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a *api) onRTSPConnsGet(ctx *gin.Context) {
|
|
|
|
uuid, err := uuid.Parse(ctx.Param("id"))
|
|
|
|
if err != nil {
|
2023-09-27 13:18:02 +00:00
|
|
|
a.writeUserError(ctx, err)
|
2023-05-18 13:07:47 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
data, err := a.rtspServer.apiConnsGet(uuid)
|
|
|
|
if err != nil {
|
2023-10-27 18:23:46 +00:00
|
|
|
a.writeServerError(ctx, err)
|
2023-05-18 13:07:47 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx.JSON(http.StatusOK, data)
|
2021-07-04 16:13:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (a *api) onRTSPSessionsList(ctx *gin.Context) {
|
2023-05-18 13:07:47 +00:00
|
|
|
data, err := a.rtspServer.apiSessionsList()
|
|
|
|
if err != nil {
|
2023-09-27 13:18:02 +00:00
|
|
|
a.writeServerError(ctx, err)
|
2021-08-11 15:32:47 +00:00
|
|
|
return
|
2021-07-04 16:13:49 +00:00
|
|
|
}
|
|
|
|
|
2023-05-18 18:05:59 +00:00
|
|
|
data.ItemCount = len(data.Items)
|
2023-05-18 13:07:47 +00:00
|
|
|
pageCount, err := paginate(&data.Items, ctx.Query("itemsPerPage"), ctx.Query("page"))
|
|
|
|
if err != nil {
|
2023-09-27 13:18:02 +00:00
|
|
|
a.writeUserError(ctx, err)
|
2023-05-18 13:07:47 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
data.PageCount = pageCount
|
|
|
|
|
|
|
|
ctx.JSON(http.StatusOK, data)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a *api) onRTSPSessionsGet(ctx *gin.Context) {
|
|
|
|
uuid, err := uuid.Parse(ctx.Param("id"))
|
2023-05-16 17:48:13 +00:00
|
|
|
if err != nil {
|
2023-09-27 13:18:02 +00:00
|
|
|
a.writeUserError(ctx, err)
|
2023-05-16 17:48:13 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2023-05-18 13:07:47 +00:00
|
|
|
data, err := a.rtspServer.apiSessionsGet(uuid)
|
|
|
|
if err != nil {
|
2023-10-27 18:23:46 +00:00
|
|
|
a.writeServerError(ctx, err)
|
2023-05-18 13:07:47 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx.JSON(http.StatusOK, data)
|
2021-07-04 16:13:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (a *api) onRTSPSessionsKick(ctx *gin.Context) {
|
2023-05-16 13:59:37 +00:00
|
|
|
uuid, err := uuid.Parse(ctx.Param("id"))
|
|
|
|
if err != nil {
|
2023-09-27 13:18:02 +00:00
|
|
|
a.writeUserError(ctx, err)
|
2023-05-16 13:59:37 +00:00
|
|
|
return
|
|
|
|
}
|
2021-07-04 16:13:49 +00:00
|
|
|
|
2023-05-18 13:07:47 +00:00
|
|
|
err = a.rtspServer.apiSessionsKick(uuid)
|
|
|
|
if err != nil {
|
2023-10-27 18:23:46 +00:00
|
|
|
a.writeServerError(ctx, err)
|
2021-08-11 15:32:47 +00:00
|
|
|
return
|
2021-07-04 16:13:49 +00:00
|
|
|
}
|
|
|
|
|
2021-08-11 15:32:47 +00:00
|
|
|
ctx.Status(http.StatusOK)
|
|
|
|
}
|
|
|
|
|
2022-11-09 17:31:31 +00:00
|
|
|
func (a *api) onRTSPSConnsList(ctx *gin.Context) {
|
2023-05-18 13:07:47 +00:00
|
|
|
data, err := a.rtspsServer.apiConnsList()
|
|
|
|
if err != nil {
|
2023-09-27 13:18:02 +00:00
|
|
|
a.writeServerError(ctx, err)
|
2022-11-09 17:31:31 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2023-05-18 18:05:59 +00:00
|
|
|
data.ItemCount = len(data.Items)
|
2023-05-18 13:07:47 +00:00
|
|
|
pageCount, err := paginate(&data.Items, ctx.Query("itemsPerPage"), ctx.Query("page"))
|
|
|
|
if err != nil {
|
2023-09-27 13:18:02 +00:00
|
|
|
a.writeUserError(ctx, err)
|
2023-05-18 13:07:47 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
data.PageCount = pageCount
|
|
|
|
|
|
|
|
ctx.JSON(http.StatusOK, data)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a *api) onRTSPSConnsGet(ctx *gin.Context) {
|
|
|
|
uuid, err := uuid.Parse(ctx.Param("id"))
|
2023-05-16 17:48:13 +00:00
|
|
|
if err != nil {
|
2023-09-27 13:18:02 +00:00
|
|
|
a.writeUserError(ctx, err)
|
2023-05-16 17:48:13 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2023-05-18 13:07:47 +00:00
|
|
|
data, err := a.rtspsServer.apiConnsGet(uuid)
|
|
|
|
if err != nil {
|
2023-10-27 18:23:46 +00:00
|
|
|
a.writeServerError(ctx, err)
|
2023-05-18 13:07:47 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx.JSON(http.StatusOK, data)
|
2022-11-09 17:31:31 +00:00
|
|
|
}
|
|
|
|
|
2021-08-11 15:32:47 +00:00
|
|
|
func (a *api) onRTSPSSessionsList(ctx *gin.Context) {
|
2023-05-18 13:07:47 +00:00
|
|
|
data, err := a.rtspsServer.apiSessionsList()
|
|
|
|
if err != nil {
|
2023-09-27 13:18:02 +00:00
|
|
|
a.writeServerError(ctx, err)
|
2021-08-11 15:32:47 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2023-05-18 18:05:59 +00:00
|
|
|
data.ItemCount = len(data.Items)
|
2023-05-18 13:07:47 +00:00
|
|
|
pageCount, err := paginate(&data.Items, ctx.Query("itemsPerPage"), ctx.Query("page"))
|
2023-05-16 17:48:13 +00:00
|
|
|
if err != nil {
|
2023-09-27 13:18:02 +00:00
|
|
|
a.writeUserError(ctx, err)
|
2023-05-16 17:48:13 +00:00
|
|
|
return
|
|
|
|
}
|
2023-05-18 13:07:47 +00:00
|
|
|
data.PageCount = pageCount
|
2023-05-16 17:48:13 +00:00
|
|
|
|
2023-05-18 13:07:47 +00:00
|
|
|
ctx.JSON(http.StatusOK, data)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a *api) onRTSPSSessionsGet(ctx *gin.Context) {
|
|
|
|
uuid, err := uuid.Parse(ctx.Param("id"))
|
|
|
|
if err != nil {
|
2023-09-27 13:18:02 +00:00
|
|
|
a.writeUserError(ctx, err)
|
2023-05-18 13:07:47 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
data, err := a.rtspsServer.apiSessionsGet(uuid)
|
|
|
|
if err != nil {
|
2023-10-27 18:23:46 +00:00
|
|
|
a.writeServerError(ctx, err)
|
2023-05-18 13:07:47 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx.JSON(http.StatusOK, data)
|
2021-08-11 15:32:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (a *api) onRTSPSSessionsKick(ctx *gin.Context) {
|
2023-05-16 13:59:37 +00:00
|
|
|
uuid, err := uuid.Parse(ctx.Param("id"))
|
|
|
|
if err != nil {
|
2023-09-27 13:18:02 +00:00
|
|
|
a.writeUserError(ctx, err)
|
2023-05-16 13:59:37 +00:00
|
|
|
return
|
|
|
|
}
|
2021-08-11 15:32:47 +00:00
|
|
|
|
2023-05-18 13:07:47 +00:00
|
|
|
err = a.rtspsServer.apiSessionsKick(uuid)
|
|
|
|
if err != nil {
|
2023-10-27 18:23:46 +00:00
|
|
|
a.writeServerError(ctx, err)
|
2021-08-11 15:32:47 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx.Status(http.StatusOK)
|
2021-07-04 16:13:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (a *api) onRTMPConnsList(ctx *gin.Context) {
|
2023-05-18 13:07:47 +00:00
|
|
|
data, err := a.rtmpServer.apiConnsList()
|
|
|
|
if err != nil {
|
2023-09-27 13:18:02 +00:00
|
|
|
a.writeServerError(ctx, err)
|
2021-07-04 16:13:49 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2023-05-18 18:05:59 +00:00
|
|
|
data.ItemCount = len(data.Items)
|
2023-05-18 13:07:47 +00:00
|
|
|
pageCount, err := paginate(&data.Items, ctx.Query("itemsPerPage"), ctx.Query("page"))
|
|
|
|
if err != nil {
|
2023-09-27 13:18:02 +00:00
|
|
|
a.writeUserError(ctx, err)
|
2023-05-18 13:07:47 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
data.PageCount = pageCount
|
|
|
|
|
|
|
|
ctx.JSON(http.StatusOK, data)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a *api) onRTMPConnsGet(ctx *gin.Context) {
|
|
|
|
uuid, err := uuid.Parse(ctx.Param("id"))
|
2023-05-16 17:48:13 +00:00
|
|
|
if err != nil {
|
2023-09-27 13:18:02 +00:00
|
|
|
a.writeUserError(ctx, err)
|
2023-05-16 17:48:13 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2023-05-18 13:07:47 +00:00
|
|
|
data, err := a.rtmpServer.apiConnsGet(uuid)
|
|
|
|
if err != nil {
|
2023-10-27 18:23:46 +00:00
|
|
|
a.writeServerError(ctx, err)
|
2023-05-18 13:07:47 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx.JSON(http.StatusOK, data)
|
2021-07-04 16:13:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (a *api) onRTMPConnsKick(ctx *gin.Context) {
|
2023-05-16 13:59:37 +00:00
|
|
|
uuid, err := uuid.Parse(ctx.Param("id"))
|
|
|
|
if err != nil {
|
2023-09-27 13:18:02 +00:00
|
|
|
a.writeUserError(ctx, err)
|
2023-05-16 13:59:37 +00:00
|
|
|
return
|
|
|
|
}
|
2021-07-04 16:13:49 +00:00
|
|
|
|
2023-05-18 13:07:47 +00:00
|
|
|
err = a.rtmpServer.apiConnsKick(uuid)
|
|
|
|
if err != nil {
|
2023-10-27 18:23:46 +00:00
|
|
|
a.writeServerError(ctx, err)
|
2021-07-04 16:13:49 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx.Status(http.StatusOK)
|
|
|
|
}
|
2021-11-05 16:14:31 +00:00
|
|
|
|
2022-08-16 11:53:04 +00:00
|
|
|
func (a *api) onRTMPSConnsList(ctx *gin.Context) {
|
2023-05-18 13:07:47 +00:00
|
|
|
data, err := a.rtmpsServer.apiConnsList()
|
|
|
|
if err != nil {
|
2023-09-27 13:18:02 +00:00
|
|
|
a.writeServerError(ctx, err)
|
2022-08-16 11:53:04 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2023-05-18 18:05:59 +00:00
|
|
|
data.ItemCount = len(data.Items)
|
2023-05-18 13:07:47 +00:00
|
|
|
pageCount, err := paginate(&data.Items, ctx.Query("itemsPerPage"), ctx.Query("page"))
|
2023-05-16 17:48:13 +00:00
|
|
|
if err != nil {
|
2023-09-27 13:18:02 +00:00
|
|
|
a.writeUserError(ctx, err)
|
2023-05-16 17:48:13 +00:00
|
|
|
return
|
|
|
|
}
|
2023-05-18 13:07:47 +00:00
|
|
|
data.PageCount = pageCount
|
2023-05-16 17:48:13 +00:00
|
|
|
|
2023-05-18 13:07:47 +00:00
|
|
|
ctx.JSON(http.StatusOK, data)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a *api) onRTMPSConnsGet(ctx *gin.Context) {
|
|
|
|
uuid, err := uuid.Parse(ctx.Param("id"))
|
|
|
|
if err != nil {
|
2023-09-27 13:18:02 +00:00
|
|
|
a.writeUserError(ctx, err)
|
2023-05-18 13:07:47 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
data, err := a.rtmpsServer.apiConnsGet(uuid)
|
|
|
|
if err != nil {
|
2023-10-27 18:23:46 +00:00
|
|
|
a.writeServerError(ctx, err)
|
2023-05-18 13:07:47 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx.JSON(http.StatusOK, data)
|
2022-08-16 11:53:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (a *api) onRTMPSConnsKick(ctx *gin.Context) {
|
2023-05-16 13:59:37 +00:00
|
|
|
uuid, err := uuid.Parse(ctx.Param("id"))
|
|
|
|
if err != nil {
|
2023-09-27 13:18:02 +00:00
|
|
|
a.writeUserError(ctx, err)
|
2023-05-16 13:59:37 +00:00
|
|
|
return
|
|
|
|
}
|
2022-08-16 11:53:04 +00:00
|
|
|
|
2023-05-18 13:07:47 +00:00
|
|
|
err = a.rtmpsServer.apiConnsKick(uuid)
|
|
|
|
if err != nil {
|
2023-10-27 18:23:46 +00:00
|
|
|
a.writeServerError(ctx, err)
|
2022-08-16 11:53:04 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx.Status(http.StatusOK)
|
|
|
|
}
|
|
|
|
|
2021-11-05 16:14:31 +00:00
|
|
|
func (a *api) onHLSMuxersList(ctx *gin.Context) {
|
2023-05-18 13:07:47 +00:00
|
|
|
data, err := a.hlsManager.apiMuxersList()
|
|
|
|
if err != nil {
|
2023-09-27 13:18:02 +00:00
|
|
|
a.writeServerError(ctx, err)
|
2022-12-15 23:50:47 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2023-05-18 18:05:59 +00:00
|
|
|
data.ItemCount = len(data.Items)
|
2023-05-18 13:07:47 +00:00
|
|
|
pageCount, err := paginate(&data.Items, ctx.Query("itemsPerPage"), ctx.Query("page"))
|
2023-05-16 17:48:13 +00:00
|
|
|
if err != nil {
|
2023-09-27 13:18:02 +00:00
|
|
|
a.writeUserError(ctx, err)
|
2023-05-16 17:48:13 +00:00
|
|
|
return
|
|
|
|
}
|
2023-05-18 13:07:47 +00:00
|
|
|
data.PageCount = pageCount
|
|
|
|
|
|
|
|
ctx.JSON(http.StatusOK, data)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a *api) onHLSMuxersGet(ctx *gin.Context) {
|
2023-07-11 14:51:23 +00:00
|
|
|
name, ok := paramName(ctx)
|
|
|
|
if !ok {
|
2023-09-27 13:18:02 +00:00
|
|
|
a.writeUserError(ctx, fmt.Errorf("invalid name"))
|
2023-07-10 17:53:25 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
data, err := a.hlsManager.apiMuxersGet(name)
|
2023-05-18 13:07:47 +00:00
|
|
|
if err != nil {
|
2023-10-27 18:23:46 +00:00
|
|
|
a.writeServerError(ctx, err)
|
2023-05-18 13:07:47 +00:00
|
|
|
return
|
|
|
|
}
|
2023-05-16 17:48:13 +00:00
|
|
|
|
2023-05-18 13:07:47 +00:00
|
|
|
ctx.JSON(http.StatusOK, data)
|
2022-12-15 23:50:47 +00:00
|
|
|
}
|
|
|
|
|
2023-05-16 13:59:37 +00:00
|
|
|
func (a *api) onWebRTCSessionsList(ctx *gin.Context) {
|
2023-05-18 13:07:47 +00:00
|
|
|
data, err := a.webRTCManager.apiSessionsList()
|
|
|
|
if err != nil {
|
2023-09-27 13:18:02 +00:00
|
|
|
a.writeServerError(ctx, err)
|
2021-11-05 16:14:31 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2023-05-18 18:05:59 +00:00
|
|
|
data.ItemCount = len(data.Items)
|
2023-05-18 13:07:47 +00:00
|
|
|
pageCount, err := paginate(&data.Items, ctx.Query("itemsPerPage"), ctx.Query("page"))
|
|
|
|
if err != nil {
|
2023-09-27 13:18:02 +00:00
|
|
|
a.writeUserError(ctx, err)
|
2023-05-18 13:07:47 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
data.PageCount = pageCount
|
|
|
|
|
|
|
|
ctx.JSON(http.StatusOK, data)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a *api) onWebRTCSessionsGet(ctx *gin.Context) {
|
|
|
|
uuid, err := uuid.Parse(ctx.Param("id"))
|
2023-05-16 17:48:13 +00:00
|
|
|
if err != nil {
|
2023-09-27 13:18:02 +00:00
|
|
|
a.writeUserError(ctx, err)
|
2023-05-16 17:48:13 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2023-05-18 13:07:47 +00:00
|
|
|
data, err := a.webRTCManager.apiSessionsGet(uuid)
|
|
|
|
if err != nil {
|
2023-10-27 18:23:46 +00:00
|
|
|
a.writeServerError(ctx, err)
|
2023-05-18 13:07:47 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx.JSON(http.StatusOK, data)
|
2021-11-05 16:14:31 +00:00
|
|
|
}
|
|
|
|
|
2023-05-16 13:59:37 +00:00
|
|
|
func (a *api) onWebRTCSessionsKick(ctx *gin.Context) {
|
|
|
|
uuid, err := uuid.Parse(ctx.Param("id"))
|
|
|
|
if err != nil {
|
2023-09-27 13:18:02 +00:00
|
|
|
a.writeUserError(ctx, err)
|
2023-05-16 13:59:37 +00:00
|
|
|
return
|
|
|
|
}
|
2022-12-15 23:50:47 +00:00
|
|
|
|
2023-05-18 13:07:47 +00:00
|
|
|
err = a.webRTCManager.apiSessionsKick(uuid)
|
|
|
|
if err != nil {
|
2023-10-27 18:23:46 +00:00
|
|
|
a.writeServerError(ctx, err)
|
2022-12-15 23:50:47 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx.Status(http.StatusOK)
|
|
|
|
}
|
|
|
|
|
2023-07-31 19:20:09 +00:00
|
|
|
func (a *api) onSRTConnsList(ctx *gin.Context) {
|
|
|
|
data, err := a.srtServer.apiConnsList()
|
|
|
|
if err != nil {
|
2023-09-27 13:18:02 +00:00
|
|
|
a.writeServerError(ctx, err)
|
2023-07-31 19:20:09 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
data.ItemCount = len(data.Items)
|
|
|
|
pageCount, err := paginate(&data.Items, ctx.Query("itemsPerPage"), ctx.Query("page"))
|
|
|
|
if err != nil {
|
2023-09-27 13:18:02 +00:00
|
|
|
a.writeUserError(ctx, err)
|
2023-07-31 19:20:09 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
data.PageCount = pageCount
|
|
|
|
|
|
|
|
ctx.JSON(http.StatusOK, data)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a *api) onSRTConnsGet(ctx *gin.Context) {
|
|
|
|
uuid, err := uuid.Parse(ctx.Param("id"))
|
|
|
|
if err != nil {
|
2023-09-27 13:18:02 +00:00
|
|
|
a.writeUserError(ctx, err)
|
2023-07-31 19:20:09 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
data, err := a.srtServer.apiConnsGet(uuid)
|
|
|
|
if err != nil {
|
2023-10-27 18:23:46 +00:00
|
|
|
a.writeServerError(ctx, err)
|
2023-07-31 19:20:09 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx.JSON(http.StatusOK, data)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a *api) onSRTConnsKick(ctx *gin.Context) {
|
|
|
|
uuid, err := uuid.Parse(ctx.Param("id"))
|
|
|
|
if err != nil {
|
2023-09-27 13:18:02 +00:00
|
|
|
a.writeUserError(ctx, err)
|
2023-07-31 19:20:09 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
err = a.srtServer.apiConnsKick(uuid)
|
|
|
|
if err != nil {
|
2023-10-27 18:23:46 +00:00
|
|
|
a.writeServerError(ctx, err)
|
2023-07-31 19:20:09 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx.Status(http.StatusOK)
|
|
|
|
}
|
|
|
|
|
2022-08-04 19:07:17 +00:00
|
|
|
// confReload is called by core.
|
|
|
|
func (a *api) confReload(conf *conf.Conf) {
|
2021-11-05 16:14:31 +00:00
|
|
|
a.mutex.Lock()
|
|
|
|
defer a.mutex.Unlock()
|
|
|
|
a.conf = conf
|
|
|
|
}
|