|
|
@ -1,4 +1,5 @@ |
|
|
|
package core |
|
|
|
// Package api contains the API server.
|
|
|
|
|
|
|
|
package api |
|
|
|
|
|
|
|
|
|
|
|
import ( |
|
|
|
import ( |
|
|
|
"encoding/json" |
|
|
|
"encoding/json" |
|
|
@ -97,17 +98,20 @@ func paramName(ctx *gin.Context) (string, bool) { |
|
|
|
return name[1:], true |
|
|
|
return name[1:], true |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
type apiPathManager interface { |
|
|
|
// PathManager contains methods used by the API and Metrics server.
|
|
|
|
apiPathsList() (*defs.APIPathList, error) |
|
|
|
type PathManager interface { |
|
|
|
apiPathsGet(string) (*defs.APIPath, error) |
|
|
|
APIPathsList() (*defs.APIPathList, error) |
|
|
|
|
|
|
|
APIPathsGet(string) (*defs.APIPath, error) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
type apiHLSServer interface { |
|
|
|
// HLSServer contains methods used by the API and Metrics server.
|
|
|
|
|
|
|
|
type HLSServer interface { |
|
|
|
APIMuxersList() (*defs.APIHLSMuxerList, error) |
|
|
|
APIMuxersList() (*defs.APIHLSMuxerList, error) |
|
|
|
APIMuxersGet(string) (*defs.APIHLSMuxer, error) |
|
|
|
APIMuxersGet(string) (*defs.APIHLSMuxer, error) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
type apiRTSPServer interface { |
|
|
|
// RTSPServer contains methods used by the API and Metrics server.
|
|
|
|
|
|
|
|
type RTSPServer interface { |
|
|
|
APIConnsList() (*defs.APIRTSPConnsList, error) |
|
|
|
APIConnsList() (*defs.APIRTSPConnsList, error) |
|
|
|
APIConnsGet(uuid.UUID) (*defs.APIRTSPConn, error) |
|
|
|
APIConnsGet(uuid.UUID) (*defs.APIRTSPConn, error) |
|
|
|
APISessionsList() (*defs.APIRTSPSessionList, error) |
|
|
|
APISessionsList() (*defs.APIRTSPSessionList, error) |
|
|
@ -115,19 +119,22 @@ type apiRTSPServer interface { |
|
|
|
APISessionsKick(uuid.UUID) error |
|
|
|
APISessionsKick(uuid.UUID) error |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
type apiRTMPServer interface { |
|
|
|
// RTMPServer contains methods used by the API and Metrics server.
|
|
|
|
|
|
|
|
type RTMPServer interface { |
|
|
|
APIConnsList() (*defs.APIRTMPConnList, error) |
|
|
|
APIConnsList() (*defs.APIRTMPConnList, error) |
|
|
|
APIConnsGet(uuid.UUID) (*defs.APIRTMPConn, error) |
|
|
|
APIConnsGet(uuid.UUID) (*defs.APIRTMPConn, error) |
|
|
|
APIConnsKick(uuid.UUID) error |
|
|
|
APIConnsKick(uuid.UUID) error |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
type apiSRTServer interface { |
|
|
|
// SRTServer contains methods used by the API and Metrics server.
|
|
|
|
|
|
|
|
type SRTServer interface { |
|
|
|
APIConnsList() (*defs.APISRTConnList, error) |
|
|
|
APIConnsList() (*defs.APISRTConnList, error) |
|
|
|
APIConnsGet(uuid.UUID) (*defs.APISRTConn, error) |
|
|
|
APIConnsGet(uuid.UUID) (*defs.APISRTConn, error) |
|
|
|
APIConnsKick(uuid.UUID) error |
|
|
|
APIConnsKick(uuid.UUID) error |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
type apiWebRTCServer interface { |
|
|
|
// WebRTCServer contains methods used by the API and Metrics server.
|
|
|
|
|
|
|
|
type WebRTCServer interface { |
|
|
|
APISessionsList() (*defs.APIWebRTCSessionList, error) |
|
|
|
APISessionsList() (*defs.APIWebRTCSessionList, error) |
|
|
|
APISessionsGet(uuid.UUID) (*defs.APIWebRTCSession, error) |
|
|
|
APISessionsGet(uuid.UUID) (*defs.APIWebRTCSession, error) |
|
|
|
APISessionsKick(uuid.UUID) error |
|
|
|
APISessionsKick(uuid.UUID) error |
|
|
@ -135,52 +142,30 @@ type apiWebRTCServer interface { |
|
|
|
|
|
|
|
|
|
|
|
type apiParent interface { |
|
|
|
type apiParent interface { |
|
|
|
logger.Writer |
|
|
|
logger.Writer |
|
|
|
apiConfigSet(conf *conf.Conf) |
|
|
|
APIConfigSet(conf *conf.Conf) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
type api struct { |
|
|
|
// API is an API server.
|
|
|
|
conf *conf.Conf |
|
|
|
type API struct { |
|
|
|
pathManager apiPathManager |
|
|
|
Address string |
|
|
|
rtspServer apiRTSPServer |
|
|
|
ReadTimeout conf.StringDuration |
|
|
|
rtspsServer apiRTSPServer |
|
|
|
Conf *conf.Conf |
|
|
|
rtmpServer apiRTMPServer |
|
|
|
PathManager PathManager |
|
|
|
rtmpsServer apiRTMPServer |
|
|
|
RTSPServer RTSPServer |
|
|
|
hlsManager apiHLSServer |
|
|
|
RTSPSServer RTSPServer |
|
|
|
webRTCServer apiWebRTCServer |
|
|
|
RTMPServer RTMPServer |
|
|
|
srtServer apiSRTServer |
|
|
|
RTMPSServer RTMPServer |
|
|
|
parent apiParent |
|
|
|
HLSServer HLSServer |
|
|
|
|
|
|
|
WebRTCServer WebRTCServer |
|
|
|
|
|
|
|
SRTServer SRTServer |
|
|
|
|
|
|
|
Parent apiParent |
|
|
|
|
|
|
|
|
|
|
|
httpServer *httpserv.WrappedServer |
|
|
|
httpServer *httpserv.WrappedServer |
|
|
|
mutex sync.Mutex |
|
|
|
mutex sync.Mutex |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func newAPI( |
|
|
|
// Initialize initializes API.
|
|
|
|
address string, |
|
|
|
func (a *API) Initialize() error { |
|
|
|
readTimeout conf.StringDuration, |
|
|
|
|
|
|
|
conf *conf.Conf, |
|
|
|
|
|
|
|
pathManager apiPathManager, |
|
|
|
|
|
|
|
rtspServer apiRTSPServer, |
|
|
|
|
|
|
|
rtspsServer apiRTSPServer, |
|
|
|
|
|
|
|
rtmpServer apiRTMPServer, |
|
|
|
|
|
|
|
rtmpsServer apiRTMPServer, |
|
|
|
|
|
|
|
hlsManager apiHLSServer, |
|
|
|
|
|
|
|
webRTCServer apiWebRTCServer, |
|
|
|
|
|
|
|
srtServer apiSRTServer, |
|
|
|
|
|
|
|
parent apiParent, |
|
|
|
|
|
|
|
) (*api, error) { |
|
|
|
|
|
|
|
a := &api{ |
|
|
|
|
|
|
|
conf: conf, |
|
|
|
|
|
|
|
pathManager: pathManager, |
|
|
|
|
|
|
|
rtspServer: rtspServer, |
|
|
|
|
|
|
|
rtspsServer: rtspsServer, |
|
|
|
|
|
|
|
rtmpServer: rtmpServer, |
|
|
|
|
|
|
|
rtmpsServer: rtmpsServer, |
|
|
|
|
|
|
|
hlsManager: hlsManager, |
|
|
|
|
|
|
|
webRTCServer: webRTCServer, |
|
|
|
|
|
|
|
srtServer: srtServer, |
|
|
|
|
|
|
|
parent: parent, |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
router := gin.New() |
|
|
|
router := gin.New() |
|
|
|
router.SetTrustedProxies(nil) //nolint:errcheck
|
|
|
|
router.SetTrustedProxies(nil) //nolint:errcheck
|
|
|
|
|
|
|
|
|
|
|
@ -202,12 +187,12 @@ func newAPI( |
|
|
|
group.GET("/v3/paths/list", a.onPathsList) |
|
|
|
group.GET("/v3/paths/list", a.onPathsList) |
|
|
|
group.GET("/v3/paths/get/*name", a.onPathsGet) |
|
|
|
group.GET("/v3/paths/get/*name", a.onPathsGet) |
|
|
|
|
|
|
|
|
|
|
|
if !interfaceIsEmpty(a.hlsManager) { |
|
|
|
if !interfaceIsEmpty(a.HLSServer) { |
|
|
|
group.GET("/v3/hlsmuxers/list", a.onHLSMuxersList) |
|
|
|
group.GET("/v3/hlsmuxers/list", a.onHLSMuxersList) |
|
|
|
group.GET("/v3/hlsmuxers/get/*name", a.onHLSMuxersGet) |
|
|
|
group.GET("/v3/hlsmuxers/get/*name", a.onHLSMuxersGet) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if !interfaceIsEmpty(a.rtspServer) { |
|
|
|
if !interfaceIsEmpty(a.RTSPServer) { |
|
|
|
group.GET("/v3/rtspconns/list", a.onRTSPConnsList) |
|
|
|
group.GET("/v3/rtspconns/list", a.onRTSPConnsList) |
|
|
|
group.GET("/v3/rtspconns/get/:id", a.onRTSPConnsGet) |
|
|
|
group.GET("/v3/rtspconns/get/:id", a.onRTSPConnsGet) |
|
|
|
group.GET("/v3/rtspsessions/list", a.onRTSPSessionsList) |
|
|
|
group.GET("/v3/rtspsessions/list", a.onRTSPSessionsList) |
|
|
@ -215,7 +200,7 @@ func newAPI( |
|
|
|
group.POST("/v3/rtspsessions/kick/:id", a.onRTSPSessionsKick) |
|
|
|
group.POST("/v3/rtspsessions/kick/:id", a.onRTSPSessionsKick) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if !interfaceIsEmpty(a.rtspsServer) { |
|
|
|
if !interfaceIsEmpty(a.RTSPSServer) { |
|
|
|
group.GET("/v3/rtspsconns/list", a.onRTSPSConnsList) |
|
|
|
group.GET("/v3/rtspsconns/list", a.onRTSPSConnsList) |
|
|
|
group.GET("/v3/rtspsconns/get/:id", a.onRTSPSConnsGet) |
|
|
|
group.GET("/v3/rtspsconns/get/:id", a.onRTSPSConnsGet) |
|
|
|
group.GET("/v3/rtspssessions/list", a.onRTSPSSessionsList) |
|
|
|
group.GET("/v3/rtspssessions/list", a.onRTSPSSessionsList) |
|
|
@ -223,63 +208,64 @@ func newAPI( |
|
|
|
group.POST("/v3/rtspssessions/kick/:id", a.onRTSPSSessionsKick) |
|
|
|
group.POST("/v3/rtspssessions/kick/:id", a.onRTSPSSessionsKick) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if !interfaceIsEmpty(a.rtmpServer) { |
|
|
|
if !interfaceIsEmpty(a.RTMPServer) { |
|
|
|
group.GET("/v3/rtmpconns/list", a.onRTMPConnsList) |
|
|
|
group.GET("/v3/rtmpconns/list", a.onRTMPConnsList) |
|
|
|
group.GET("/v3/rtmpconns/get/:id", a.onRTMPConnsGet) |
|
|
|
group.GET("/v3/rtmpconns/get/:id", a.onRTMPConnsGet) |
|
|
|
group.POST("/v3/rtmpconns/kick/:id", a.onRTMPConnsKick) |
|
|
|
group.POST("/v3/rtmpconns/kick/:id", a.onRTMPConnsKick) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if !interfaceIsEmpty(a.rtmpsServer) { |
|
|
|
if !interfaceIsEmpty(a.RTMPSServer) { |
|
|
|
group.GET("/v3/rtmpsconns/list", a.onRTMPSConnsList) |
|
|
|
group.GET("/v3/rtmpsconns/list", a.onRTMPSConnsList) |
|
|
|
group.GET("/v3/rtmpsconns/get/:id", a.onRTMPSConnsGet) |
|
|
|
group.GET("/v3/rtmpsconns/get/:id", a.onRTMPSConnsGet) |
|
|
|
group.POST("/v3/rtmpsconns/kick/:id", a.onRTMPSConnsKick) |
|
|
|
group.POST("/v3/rtmpsconns/kick/:id", a.onRTMPSConnsKick) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if !interfaceIsEmpty(a.webRTCServer) { |
|
|
|
if !interfaceIsEmpty(a.WebRTCServer) { |
|
|
|
group.GET("/v3/webrtcsessions/list", a.onWebRTCSessionsList) |
|
|
|
group.GET("/v3/webrtcsessions/list", a.onWebRTCSessionsList) |
|
|
|
group.GET("/v3/webrtcsessions/get/:id", a.onWebRTCSessionsGet) |
|
|
|
group.GET("/v3/webrtcsessions/get/:id", a.onWebRTCSessionsGet) |
|
|
|
group.POST("/v3/webrtcsessions/kick/:id", a.onWebRTCSessionsKick) |
|
|
|
group.POST("/v3/webrtcsessions/kick/:id", a.onWebRTCSessionsKick) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if !interfaceIsEmpty(a.srtServer) { |
|
|
|
if !interfaceIsEmpty(a.SRTServer) { |
|
|
|
group.GET("/v3/srtconns/list", a.onSRTConnsList) |
|
|
|
group.GET("/v3/srtconns/list", a.onSRTConnsList) |
|
|
|
group.GET("/v3/srtconns/get/:id", a.onSRTConnsGet) |
|
|
|
group.GET("/v3/srtconns/get/:id", a.onSRTConnsGet) |
|
|
|
group.POST("/v3/srtconns/kick/:id", a.onSRTConnsKick) |
|
|
|
group.POST("/v3/srtconns/kick/:id", a.onSRTConnsKick) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
network, address := restrictnetwork.Restrict("tcp", address) |
|
|
|
network, address := restrictnetwork.Restrict("tcp", a.Address) |
|
|
|
|
|
|
|
|
|
|
|
var err error |
|
|
|
var err error |
|
|
|
a.httpServer, err = httpserv.NewWrappedServer( |
|
|
|
a.httpServer, err = httpserv.NewWrappedServer( |
|
|
|
network, |
|
|
|
network, |
|
|
|
address, |
|
|
|
address, |
|
|
|
time.Duration(readTimeout), |
|
|
|
time.Duration(a.ReadTimeout), |
|
|
|
"", |
|
|
|
"", |
|
|
|
"", |
|
|
|
"", |
|
|
|
router, |
|
|
|
router, |
|
|
|
a, |
|
|
|
a, |
|
|
|
) |
|
|
|
) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
return nil, err |
|
|
|
return err |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
a.Log(logger.Info, "listener opened on "+address) |
|
|
|
a.Log(logger.Info, "listener opened on "+address) |
|
|
|
|
|
|
|
|
|
|
|
return a, nil |
|
|
|
return nil |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (a *api) close() { |
|
|
|
// Close closes the API.
|
|
|
|
|
|
|
|
func (a *API) Close() { |
|
|
|
a.Log(logger.Info, "listener is closing") |
|
|
|
a.Log(logger.Info, "listener is closing") |
|
|
|
a.httpServer.Close() |
|
|
|
a.httpServer.Close() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Log implements logger.Writer.
|
|
|
|
// Log implements logger.Writer.
|
|
|
|
func (a *api) Log(level logger.Level, format string, args ...interface{}) { |
|
|
|
func (a *API) Log(level logger.Level, format string, args ...interface{}) { |
|
|
|
a.parent.Log(level, "[API] "+format, args...) |
|
|
|
a.Parent.Log(level, "[API] "+format, args...) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// error coming from something the user inserted into the request.
|
|
|
|
// error coming from something the user inserted into the request.
|
|
|
|
func (a *api) writeError(ctx *gin.Context, status int, err error) { |
|
|
|
func (a *API) writeError(ctx *gin.Context, status int, err error) { |
|
|
|
// show error in logs
|
|
|
|
// show error in logs
|
|
|
|
a.Log(logger.Error, err.Error()) |
|
|
|
a.Log(logger.Error, err.Error()) |
|
|
|
|
|
|
|
|
|
|
@ -289,15 +275,15 @@ func (a *api) writeError(ctx *gin.Context, status int, err error) { |
|
|
|
}) |
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (a *api) onConfigGlobalGet(ctx *gin.Context) { |
|
|
|
func (a *API) onConfigGlobalGet(ctx *gin.Context) { |
|
|
|
a.mutex.Lock() |
|
|
|
a.mutex.Lock() |
|
|
|
c := a.conf |
|
|
|
c := a.Conf |
|
|
|
a.mutex.Unlock() |
|
|
|
a.mutex.Unlock() |
|
|
|
|
|
|
|
|
|
|
|
ctx.JSON(http.StatusOK, c.Global()) |
|
|
|
ctx.JSON(http.StatusOK, c.Global()) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (a *api) onConfigGlobalPatch(ctx *gin.Context) { |
|
|
|
func (a *API) onConfigGlobalPatch(ctx *gin.Context) { |
|
|
|
var c conf.OptionalGlobal |
|
|
|
var c conf.OptionalGlobal |
|
|
|
err := json.NewDecoder(ctx.Request.Body).Decode(&c) |
|
|
|
err := json.NewDecoder(ctx.Request.Body).Decode(&c) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
@ -308,7 +294,7 @@ func (a *api) onConfigGlobalPatch(ctx *gin.Context) { |
|
|
|
a.mutex.Lock() |
|
|
|
a.mutex.Lock() |
|
|
|
defer a.mutex.Unlock() |
|
|
|
defer a.mutex.Unlock() |
|
|
|
|
|
|
|
|
|
|
|
newConf := a.conf.Clone() |
|
|
|
newConf := a.Conf.Clone() |
|
|
|
|
|
|
|
|
|
|
|
newConf.PatchGlobal(&c) |
|
|
|
newConf.PatchGlobal(&c) |
|
|
|
|
|
|
|
|
|
|
@ -318,24 +304,24 @@ func (a *api) onConfigGlobalPatch(ctx *gin.Context) { |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
a.conf = newConf |
|
|
|
a.Conf = newConf |
|
|
|
|
|
|
|
|
|
|
|
// since reloading the configuration can cause the shutdown of the API,
|
|
|
|
// since reloading the configuration can cause the shutdown of the API,
|
|
|
|
// call it in a goroutine
|
|
|
|
// call it in a goroutine
|
|
|
|
go a.parent.apiConfigSet(newConf) |
|
|
|
go a.Parent.APIConfigSet(newConf) |
|
|
|
|
|
|
|
|
|
|
|
ctx.Status(http.StatusOK) |
|
|
|
ctx.Status(http.StatusOK) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (a *api) onConfigPathDefaultsGet(ctx *gin.Context) { |
|
|
|
func (a *API) onConfigPathDefaultsGet(ctx *gin.Context) { |
|
|
|
a.mutex.Lock() |
|
|
|
a.mutex.Lock() |
|
|
|
c := a.conf |
|
|
|
c := a.Conf |
|
|
|
a.mutex.Unlock() |
|
|
|
a.mutex.Unlock() |
|
|
|
|
|
|
|
|
|
|
|
ctx.JSON(http.StatusOK, c.PathDefaults) |
|
|
|
ctx.JSON(http.StatusOK, c.PathDefaults) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (a *api) onConfigPathDefaultsPatch(ctx *gin.Context) { |
|
|
|
func (a *API) onConfigPathDefaultsPatch(ctx *gin.Context) { |
|
|
|
var p conf.OptionalPath |
|
|
|
var p conf.OptionalPath |
|
|
|
err := json.NewDecoder(ctx.Request.Body).Decode(&p) |
|
|
|
err := json.NewDecoder(ctx.Request.Body).Decode(&p) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
@ -346,7 +332,7 @@ func (a *api) onConfigPathDefaultsPatch(ctx *gin.Context) { |
|
|
|
a.mutex.Lock() |
|
|
|
a.mutex.Lock() |
|
|
|
defer a.mutex.Unlock() |
|
|
|
defer a.mutex.Unlock() |
|
|
|
|
|
|
|
|
|
|
|
newConf := a.conf.Clone() |
|
|
|
newConf := a.Conf.Clone() |
|
|
|
|
|
|
|
|
|
|
|
newConf.PatchPathDefaults(&p) |
|
|
|
newConf.PatchPathDefaults(&p) |
|
|
|
|
|
|
|
|
|
|
@ -356,15 +342,15 @@ func (a *api) onConfigPathDefaultsPatch(ctx *gin.Context) { |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
a.conf = newConf |
|
|
|
a.Conf = newConf |
|
|
|
a.parent.apiConfigSet(newConf) |
|
|
|
a.Parent.APIConfigSet(newConf) |
|
|
|
|
|
|
|
|
|
|
|
ctx.Status(http.StatusOK) |
|
|
|
ctx.Status(http.StatusOK) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (a *api) onConfigPathsList(ctx *gin.Context) { |
|
|
|
func (a *API) onConfigPathsList(ctx *gin.Context) { |
|
|
|
a.mutex.Lock() |
|
|
|
a.mutex.Lock() |
|
|
|
c := a.conf |
|
|
|
c := a.Conf |
|
|
|
a.mutex.Unlock() |
|
|
|
a.mutex.Unlock() |
|
|
|
|
|
|
|
|
|
|
|
data := &defs.APIPathConfList{ |
|
|
|
data := &defs.APIPathConfList{ |
|
|
@ -386,7 +372,7 @@ func (a *api) onConfigPathsList(ctx *gin.Context) { |
|
|
|
ctx.JSON(http.StatusOK, data) |
|
|
|
ctx.JSON(http.StatusOK, data) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (a *api) onConfigPathsGet(ctx *gin.Context) { |
|
|
|
func (a *API) onConfigPathsGet(ctx *gin.Context) { |
|
|
|
name, ok := paramName(ctx) |
|
|
|
name, ok := paramName(ctx) |
|
|
|
if !ok { |
|
|
|
if !ok { |
|
|
|
a.writeError(ctx, http.StatusBadRequest, fmt.Errorf("invalid name")) |
|
|
|
a.writeError(ctx, http.StatusBadRequest, fmt.Errorf("invalid name")) |
|
|
@ -394,7 +380,7 @@ func (a *api) onConfigPathsGet(ctx *gin.Context) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
a.mutex.Lock() |
|
|
|
a.mutex.Lock() |
|
|
|
c := a.conf |
|
|
|
c := a.Conf |
|
|
|
a.mutex.Unlock() |
|
|
|
a.mutex.Unlock() |
|
|
|
|
|
|
|
|
|
|
|
p, ok := c.Paths[name] |
|
|
|
p, ok := c.Paths[name] |
|
|
@ -406,7 +392,7 @@ func (a *api) onConfigPathsGet(ctx *gin.Context) { |
|
|
|
ctx.JSON(http.StatusOK, p) |
|
|
|
ctx.JSON(http.StatusOK, p) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (a *api) onConfigPathsAdd(ctx *gin.Context) { //nolint:dupl
|
|
|
|
func (a *API) onConfigPathsAdd(ctx *gin.Context) { //nolint:dupl
|
|
|
|
name, ok := paramName(ctx) |
|
|
|
name, ok := paramName(ctx) |
|
|
|
if !ok { |
|
|
|
if !ok { |
|
|
|
a.writeError(ctx, http.StatusBadRequest, fmt.Errorf("invalid name")) |
|
|
|
a.writeError(ctx, http.StatusBadRequest, fmt.Errorf("invalid name")) |
|
|
@ -423,7 +409,7 @@ func (a *api) onConfigPathsAdd(ctx *gin.Context) { //nolint:dupl |
|
|
|
a.mutex.Lock() |
|
|
|
a.mutex.Lock() |
|
|
|
defer a.mutex.Unlock() |
|
|
|
defer a.mutex.Unlock() |
|
|
|
|
|
|
|
|
|
|
|
newConf := a.conf.Clone() |
|
|
|
newConf := a.Conf.Clone() |
|
|
|
|
|
|
|
|
|
|
|
err = newConf.AddPath(name, &p) |
|
|
|
err = newConf.AddPath(name, &p) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
@ -437,13 +423,13 @@ func (a *api) onConfigPathsAdd(ctx *gin.Context) { //nolint:dupl |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
a.conf = newConf |
|
|
|
a.Conf = newConf |
|
|
|
a.parent.apiConfigSet(newConf) |
|
|
|
a.Parent.APIConfigSet(newConf) |
|
|
|
|
|
|
|
|
|
|
|
ctx.Status(http.StatusOK) |
|
|
|
ctx.Status(http.StatusOK) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (a *api) onConfigPathsPatch(ctx *gin.Context) { //nolint:dupl
|
|
|
|
func (a *API) onConfigPathsPatch(ctx *gin.Context) { //nolint:dupl
|
|
|
|
name, ok := paramName(ctx) |
|
|
|
name, ok := paramName(ctx) |
|
|
|
if !ok { |
|
|
|
if !ok { |
|
|
|
a.writeError(ctx, http.StatusBadRequest, fmt.Errorf("invalid name")) |
|
|
|
a.writeError(ctx, http.StatusBadRequest, fmt.Errorf("invalid name")) |
|
|
@ -460,7 +446,7 @@ func (a *api) onConfigPathsPatch(ctx *gin.Context) { //nolint:dupl |
|
|
|
a.mutex.Lock() |
|
|
|
a.mutex.Lock() |
|
|
|
defer a.mutex.Unlock() |
|
|
|
defer a.mutex.Unlock() |
|
|
|
|
|
|
|
|
|
|
|
newConf := a.conf.Clone() |
|
|
|
newConf := a.Conf.Clone() |
|
|
|
|
|
|
|
|
|
|
|
err = newConf.PatchPath(name, &p) |
|
|
|
err = newConf.PatchPath(name, &p) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
@ -474,13 +460,13 @@ func (a *api) onConfigPathsPatch(ctx *gin.Context) { //nolint:dupl |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
a.conf = newConf |
|
|
|
a.Conf = newConf |
|
|
|
a.parent.apiConfigSet(newConf) |
|
|
|
a.Parent.APIConfigSet(newConf) |
|
|
|
|
|
|
|
|
|
|
|
ctx.Status(http.StatusOK) |
|
|
|
ctx.Status(http.StatusOK) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (a *api) onConfigPathsReplace(ctx *gin.Context) { //nolint:dupl
|
|
|
|
func (a *API) onConfigPathsReplace(ctx *gin.Context) { //nolint:dupl
|
|
|
|
name, ok := paramName(ctx) |
|
|
|
name, ok := paramName(ctx) |
|
|
|
if !ok { |
|
|
|
if !ok { |
|
|
|
a.writeError(ctx, http.StatusBadRequest, fmt.Errorf("invalid name")) |
|
|
|
a.writeError(ctx, http.StatusBadRequest, fmt.Errorf("invalid name")) |
|
|
@ -497,7 +483,7 @@ func (a *api) onConfigPathsReplace(ctx *gin.Context) { //nolint:dupl |
|
|
|
a.mutex.Lock() |
|
|
|
a.mutex.Lock() |
|
|
|
defer a.mutex.Unlock() |
|
|
|
defer a.mutex.Unlock() |
|
|
|
|
|
|
|
|
|
|
|
newConf := a.conf.Clone() |
|
|
|
newConf := a.Conf.Clone() |
|
|
|
|
|
|
|
|
|
|
|
err = newConf.ReplacePath(name, &p) |
|
|
|
err = newConf.ReplacePath(name, &p) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
@ -511,13 +497,13 @@ func (a *api) onConfigPathsReplace(ctx *gin.Context) { //nolint:dupl |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
a.conf = newConf |
|
|
|
a.Conf = newConf |
|
|
|
a.parent.apiConfigSet(newConf) |
|
|
|
a.Parent.APIConfigSet(newConf) |
|
|
|
|
|
|
|
|
|
|
|
ctx.Status(http.StatusOK) |
|
|
|
ctx.Status(http.StatusOK) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (a *api) onConfigPathsDelete(ctx *gin.Context) { |
|
|
|
func (a *API) onConfigPathsDelete(ctx *gin.Context) { |
|
|
|
name, ok := paramName(ctx) |
|
|
|
name, ok := paramName(ctx) |
|
|
|
if !ok { |
|
|
|
if !ok { |
|
|
|
a.writeError(ctx, http.StatusBadRequest, fmt.Errorf("invalid name")) |
|
|
|
a.writeError(ctx, http.StatusBadRequest, fmt.Errorf("invalid name")) |
|
|
@ -527,7 +513,7 @@ func (a *api) onConfigPathsDelete(ctx *gin.Context) { |
|
|
|
a.mutex.Lock() |
|
|
|
a.mutex.Lock() |
|
|
|
defer a.mutex.Unlock() |
|
|
|
defer a.mutex.Unlock() |
|
|
|
|
|
|
|
|
|
|
|
newConf := a.conf.Clone() |
|
|
|
newConf := a.Conf.Clone() |
|
|
|
|
|
|
|
|
|
|
|
err := newConf.RemovePath(name) |
|
|
|
err := newConf.RemovePath(name) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
@ -541,14 +527,14 @@ func (a *api) onConfigPathsDelete(ctx *gin.Context) { |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
a.conf = newConf |
|
|
|
a.Conf = newConf |
|
|
|
a.parent.apiConfigSet(newConf) |
|
|
|
a.Parent.APIConfigSet(newConf) |
|
|
|
|
|
|
|
|
|
|
|
ctx.Status(http.StatusOK) |
|
|
|
ctx.Status(http.StatusOK) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (a *api) onPathsList(ctx *gin.Context) { |
|
|
|
func (a *API) onPathsList(ctx *gin.Context) { |
|
|
|
data, err := a.pathManager.apiPathsList() |
|
|
|
data, err := a.PathManager.APIPathsList() |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
a.writeError(ctx, http.StatusInternalServerError, err) |
|
|
|
a.writeError(ctx, http.StatusInternalServerError, err) |
|
|
|
return |
|
|
|
return |
|
|
@ -565,14 +551,14 @@ func (a *api) onPathsList(ctx *gin.Context) { |
|
|
|
ctx.JSON(http.StatusOK, data) |
|
|
|
ctx.JSON(http.StatusOK, data) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (a *api) onPathsGet(ctx *gin.Context) { |
|
|
|
func (a *API) onPathsGet(ctx *gin.Context) { |
|
|
|
name, ok := paramName(ctx) |
|
|
|
name, ok := paramName(ctx) |
|
|
|
if !ok { |
|
|
|
if !ok { |
|
|
|
a.writeError(ctx, http.StatusBadRequest, fmt.Errorf("invalid name")) |
|
|
|
a.writeError(ctx, http.StatusBadRequest, fmt.Errorf("invalid name")) |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
data, err := a.pathManager.apiPathsGet(name) |
|
|
|
data, err := a.PathManager.APIPathsGet(name) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
a.writeError(ctx, http.StatusInternalServerError, err) |
|
|
|
a.writeError(ctx, http.StatusInternalServerError, err) |
|
|
|
return |
|
|
|
return |
|
|
@ -581,8 +567,8 @@ func (a *api) onPathsGet(ctx *gin.Context) { |
|
|
|
ctx.JSON(http.StatusOK, data) |
|
|
|
ctx.JSON(http.StatusOK, data) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (a *api) onRTSPConnsList(ctx *gin.Context) { |
|
|
|
func (a *API) onRTSPConnsList(ctx *gin.Context) { |
|
|
|
data, err := a.rtspServer.APIConnsList() |
|
|
|
data, err := a.RTSPServer.APIConnsList() |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
a.writeError(ctx, http.StatusInternalServerError, err) |
|
|
|
a.writeError(ctx, http.StatusInternalServerError, err) |
|
|
|
return |
|
|
|
return |
|
|
@ -599,14 +585,14 @@ func (a *api) onRTSPConnsList(ctx *gin.Context) { |
|
|
|
ctx.JSON(http.StatusOK, data) |
|
|
|
ctx.JSON(http.StatusOK, data) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (a *api) onRTSPConnsGet(ctx *gin.Context) { |
|
|
|
func (a *API) onRTSPConnsGet(ctx *gin.Context) { |
|
|
|
uuid, err := uuid.Parse(ctx.Param("id")) |
|
|
|
uuid, err := uuid.Parse(ctx.Param("id")) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
a.writeError(ctx, http.StatusBadRequest, err) |
|
|
|
a.writeError(ctx, http.StatusBadRequest, err) |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
data, err := a.rtspServer.APIConnsGet(uuid) |
|
|
|
data, err := a.RTSPServer.APIConnsGet(uuid) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
a.writeError(ctx, http.StatusInternalServerError, err) |
|
|
|
a.writeError(ctx, http.StatusInternalServerError, err) |
|
|
|
return |
|
|
|
return |
|
|
@ -615,8 +601,8 @@ func (a *api) onRTSPConnsGet(ctx *gin.Context) { |
|
|
|
ctx.JSON(http.StatusOK, data) |
|
|
|
ctx.JSON(http.StatusOK, data) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (a *api) onRTSPSessionsList(ctx *gin.Context) { |
|
|
|
func (a *API) onRTSPSessionsList(ctx *gin.Context) { |
|
|
|
data, err := a.rtspServer.APISessionsList() |
|
|
|
data, err := a.RTSPServer.APISessionsList() |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
a.writeError(ctx, http.StatusInternalServerError, err) |
|
|
|
a.writeError(ctx, http.StatusInternalServerError, err) |
|
|
|
return |
|
|
|
return |
|
|
@ -633,14 +619,14 @@ func (a *api) onRTSPSessionsList(ctx *gin.Context) { |
|
|
|
ctx.JSON(http.StatusOK, data) |
|
|
|
ctx.JSON(http.StatusOK, data) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (a *api) onRTSPSessionsGet(ctx *gin.Context) { |
|
|
|
func (a *API) onRTSPSessionsGet(ctx *gin.Context) { |
|
|
|
uuid, err := uuid.Parse(ctx.Param("id")) |
|
|
|
uuid, err := uuid.Parse(ctx.Param("id")) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
a.writeError(ctx, http.StatusBadRequest, err) |
|
|
|
a.writeError(ctx, http.StatusBadRequest, err) |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
data, err := a.rtspServer.APISessionsGet(uuid) |
|
|
|
data, err := a.RTSPServer.APISessionsGet(uuid) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
a.writeError(ctx, http.StatusInternalServerError, err) |
|
|
|
a.writeError(ctx, http.StatusInternalServerError, err) |
|
|
|
return |
|
|
|
return |
|
|
@ -649,14 +635,14 @@ func (a *api) onRTSPSessionsGet(ctx *gin.Context) { |
|
|
|
ctx.JSON(http.StatusOK, data) |
|
|
|
ctx.JSON(http.StatusOK, data) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (a *api) onRTSPSessionsKick(ctx *gin.Context) { |
|
|
|
func (a *API) onRTSPSessionsKick(ctx *gin.Context) { |
|
|
|
uuid, err := uuid.Parse(ctx.Param("id")) |
|
|
|
uuid, err := uuid.Parse(ctx.Param("id")) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
a.writeError(ctx, http.StatusBadRequest, err) |
|
|
|
a.writeError(ctx, http.StatusBadRequest, err) |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
err = a.rtspServer.APISessionsKick(uuid) |
|
|
|
err = a.RTSPServer.APISessionsKick(uuid) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
a.writeError(ctx, http.StatusInternalServerError, err) |
|
|
|
a.writeError(ctx, http.StatusInternalServerError, err) |
|
|
|
return |
|
|
|
return |
|
|
@ -665,8 +651,8 @@ func (a *api) onRTSPSessionsKick(ctx *gin.Context) { |
|
|
|
ctx.Status(http.StatusOK) |
|
|
|
ctx.Status(http.StatusOK) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (a *api) onRTSPSConnsList(ctx *gin.Context) { |
|
|
|
func (a *API) onRTSPSConnsList(ctx *gin.Context) { |
|
|
|
data, err := a.rtspsServer.APIConnsList() |
|
|
|
data, err := a.RTSPSServer.APIConnsList() |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
a.writeError(ctx, http.StatusInternalServerError, err) |
|
|
|
a.writeError(ctx, http.StatusInternalServerError, err) |
|
|
|
return |
|
|
|
return |
|
|
@ -683,14 +669,14 @@ func (a *api) onRTSPSConnsList(ctx *gin.Context) { |
|
|
|
ctx.JSON(http.StatusOK, data) |
|
|
|
ctx.JSON(http.StatusOK, data) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (a *api) onRTSPSConnsGet(ctx *gin.Context) { |
|
|
|
func (a *API) onRTSPSConnsGet(ctx *gin.Context) { |
|
|
|
uuid, err := uuid.Parse(ctx.Param("id")) |
|
|
|
uuid, err := uuid.Parse(ctx.Param("id")) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
a.writeError(ctx, http.StatusBadRequest, err) |
|
|
|
a.writeError(ctx, http.StatusBadRequest, err) |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
data, err := a.rtspsServer.APIConnsGet(uuid) |
|
|
|
data, err := a.RTSPSServer.APIConnsGet(uuid) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
a.writeError(ctx, http.StatusInternalServerError, err) |
|
|
|
a.writeError(ctx, http.StatusInternalServerError, err) |
|
|
|
return |
|
|
|
return |
|
|
@ -699,8 +685,8 @@ func (a *api) onRTSPSConnsGet(ctx *gin.Context) { |
|
|
|
ctx.JSON(http.StatusOK, data) |
|
|
|
ctx.JSON(http.StatusOK, data) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (a *api) onRTSPSSessionsList(ctx *gin.Context) { |
|
|
|
func (a *API) onRTSPSSessionsList(ctx *gin.Context) { |
|
|
|
data, err := a.rtspsServer.APISessionsList() |
|
|
|
data, err := a.RTSPSServer.APISessionsList() |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
a.writeError(ctx, http.StatusInternalServerError, err) |
|
|
|
a.writeError(ctx, http.StatusInternalServerError, err) |
|
|
|
return |
|
|
|
return |
|
|
@ -717,14 +703,14 @@ func (a *api) onRTSPSSessionsList(ctx *gin.Context) { |
|
|
|
ctx.JSON(http.StatusOK, data) |
|
|
|
ctx.JSON(http.StatusOK, data) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (a *api) onRTSPSSessionsGet(ctx *gin.Context) { |
|
|
|
func (a *API) onRTSPSSessionsGet(ctx *gin.Context) { |
|
|
|
uuid, err := uuid.Parse(ctx.Param("id")) |
|
|
|
uuid, err := uuid.Parse(ctx.Param("id")) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
a.writeError(ctx, http.StatusBadRequest, err) |
|
|
|
a.writeError(ctx, http.StatusBadRequest, err) |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
data, err := a.rtspsServer.APISessionsGet(uuid) |
|
|
|
data, err := a.RTSPSServer.APISessionsGet(uuid) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
a.writeError(ctx, http.StatusInternalServerError, err) |
|
|
|
a.writeError(ctx, http.StatusInternalServerError, err) |
|
|
|
return |
|
|
|
return |
|
|
@ -733,14 +719,14 @@ func (a *api) onRTSPSSessionsGet(ctx *gin.Context) { |
|
|
|
ctx.JSON(http.StatusOK, data) |
|
|
|
ctx.JSON(http.StatusOK, data) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (a *api) onRTSPSSessionsKick(ctx *gin.Context) { |
|
|
|
func (a *API) onRTSPSSessionsKick(ctx *gin.Context) { |
|
|
|
uuid, err := uuid.Parse(ctx.Param("id")) |
|
|
|
uuid, err := uuid.Parse(ctx.Param("id")) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
a.writeError(ctx, http.StatusBadRequest, err) |
|
|
|
a.writeError(ctx, http.StatusBadRequest, err) |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
err = a.rtspsServer.APISessionsKick(uuid) |
|
|
|
err = a.RTSPSServer.APISessionsKick(uuid) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
a.writeError(ctx, http.StatusInternalServerError, err) |
|
|
|
a.writeError(ctx, http.StatusInternalServerError, err) |
|
|
|
return |
|
|
|
return |
|
|
@ -749,8 +735,8 @@ func (a *api) onRTSPSSessionsKick(ctx *gin.Context) { |
|
|
|
ctx.Status(http.StatusOK) |
|
|
|
ctx.Status(http.StatusOK) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (a *api) onRTMPConnsList(ctx *gin.Context) { |
|
|
|
func (a *API) onRTMPConnsList(ctx *gin.Context) { |
|
|
|
data, err := a.rtmpServer.APIConnsList() |
|
|
|
data, err := a.RTMPServer.APIConnsList() |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
a.writeError(ctx, http.StatusInternalServerError, err) |
|
|
|
a.writeError(ctx, http.StatusInternalServerError, err) |
|
|
|
return |
|
|
|
return |
|
|
@ -767,14 +753,14 @@ func (a *api) onRTMPConnsList(ctx *gin.Context) { |
|
|
|
ctx.JSON(http.StatusOK, data) |
|
|
|
ctx.JSON(http.StatusOK, data) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (a *api) onRTMPConnsGet(ctx *gin.Context) { |
|
|
|
func (a *API) onRTMPConnsGet(ctx *gin.Context) { |
|
|
|
uuid, err := uuid.Parse(ctx.Param("id")) |
|
|
|
uuid, err := uuid.Parse(ctx.Param("id")) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
a.writeError(ctx, http.StatusBadRequest, err) |
|
|
|
a.writeError(ctx, http.StatusBadRequest, err) |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
data, err := a.rtmpServer.APIConnsGet(uuid) |
|
|
|
data, err := a.RTMPServer.APIConnsGet(uuid) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
a.writeError(ctx, http.StatusInternalServerError, err) |
|
|
|
a.writeError(ctx, http.StatusInternalServerError, err) |
|
|
|
return |
|
|
|
return |
|
|
@ -783,14 +769,14 @@ func (a *api) onRTMPConnsGet(ctx *gin.Context) { |
|
|
|
ctx.JSON(http.StatusOK, data) |
|
|
|
ctx.JSON(http.StatusOK, data) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (a *api) onRTMPConnsKick(ctx *gin.Context) { |
|
|
|
func (a *API) onRTMPConnsKick(ctx *gin.Context) { |
|
|
|
uuid, err := uuid.Parse(ctx.Param("id")) |
|
|
|
uuid, err := uuid.Parse(ctx.Param("id")) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
a.writeError(ctx, http.StatusBadRequest, err) |
|
|
|
a.writeError(ctx, http.StatusBadRequest, err) |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
err = a.rtmpServer.APIConnsKick(uuid) |
|
|
|
err = a.RTMPServer.APIConnsKick(uuid) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
a.writeError(ctx, http.StatusInternalServerError, err) |
|
|
|
a.writeError(ctx, http.StatusInternalServerError, err) |
|
|
|
return |
|
|
|
return |
|
|
@ -799,8 +785,8 @@ func (a *api) onRTMPConnsKick(ctx *gin.Context) { |
|
|
|
ctx.Status(http.StatusOK) |
|
|
|
ctx.Status(http.StatusOK) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (a *api) onRTMPSConnsList(ctx *gin.Context) { |
|
|
|
func (a *API) onRTMPSConnsList(ctx *gin.Context) { |
|
|
|
data, err := a.rtmpsServer.APIConnsList() |
|
|
|
data, err := a.RTMPSServer.APIConnsList() |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
a.writeError(ctx, http.StatusInternalServerError, err) |
|
|
|
a.writeError(ctx, http.StatusInternalServerError, err) |
|
|
|
return |
|
|
|
return |
|
|
@ -817,14 +803,14 @@ func (a *api) onRTMPSConnsList(ctx *gin.Context) { |
|
|
|
ctx.JSON(http.StatusOK, data) |
|
|
|
ctx.JSON(http.StatusOK, data) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (a *api) onRTMPSConnsGet(ctx *gin.Context) { |
|
|
|
func (a *API) onRTMPSConnsGet(ctx *gin.Context) { |
|
|
|
uuid, err := uuid.Parse(ctx.Param("id")) |
|
|
|
uuid, err := uuid.Parse(ctx.Param("id")) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
a.writeError(ctx, http.StatusBadRequest, err) |
|
|
|
a.writeError(ctx, http.StatusBadRequest, err) |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
data, err := a.rtmpsServer.APIConnsGet(uuid) |
|
|
|
data, err := a.RTMPSServer.APIConnsGet(uuid) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
a.writeError(ctx, http.StatusInternalServerError, err) |
|
|
|
a.writeError(ctx, http.StatusInternalServerError, err) |
|
|
|
return |
|
|
|
return |
|
|
@ -833,14 +819,14 @@ func (a *api) onRTMPSConnsGet(ctx *gin.Context) { |
|
|
|
ctx.JSON(http.StatusOK, data) |
|
|
|
ctx.JSON(http.StatusOK, data) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (a *api) onRTMPSConnsKick(ctx *gin.Context) { |
|
|
|
func (a *API) onRTMPSConnsKick(ctx *gin.Context) { |
|
|
|
uuid, err := uuid.Parse(ctx.Param("id")) |
|
|
|
uuid, err := uuid.Parse(ctx.Param("id")) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
a.writeError(ctx, http.StatusBadRequest, err) |
|
|
|
a.writeError(ctx, http.StatusBadRequest, err) |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
err = a.rtmpsServer.APIConnsKick(uuid) |
|
|
|
err = a.RTMPSServer.APIConnsKick(uuid) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
a.writeError(ctx, http.StatusInternalServerError, err) |
|
|
|
a.writeError(ctx, http.StatusInternalServerError, err) |
|
|
|
return |
|
|
|
return |
|
|
@ -849,8 +835,8 @@ func (a *api) onRTMPSConnsKick(ctx *gin.Context) { |
|
|
|
ctx.Status(http.StatusOK) |
|
|
|
ctx.Status(http.StatusOK) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (a *api) onHLSMuxersList(ctx *gin.Context) { |
|
|
|
func (a *API) onHLSMuxersList(ctx *gin.Context) { |
|
|
|
data, err := a.hlsManager.APIMuxersList() |
|
|
|
data, err := a.HLSServer.APIMuxersList() |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
a.writeError(ctx, http.StatusInternalServerError, err) |
|
|
|
a.writeError(ctx, http.StatusInternalServerError, err) |
|
|
|
return |
|
|
|
return |
|
|
@ -867,14 +853,14 @@ func (a *api) onHLSMuxersList(ctx *gin.Context) { |
|
|
|
ctx.JSON(http.StatusOK, data) |
|
|
|
ctx.JSON(http.StatusOK, data) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (a *api) onHLSMuxersGet(ctx *gin.Context) { |
|
|
|
func (a *API) onHLSMuxersGet(ctx *gin.Context) { |
|
|
|
name, ok := paramName(ctx) |
|
|
|
name, ok := paramName(ctx) |
|
|
|
if !ok { |
|
|
|
if !ok { |
|
|
|
a.writeError(ctx, http.StatusBadRequest, fmt.Errorf("invalid name")) |
|
|
|
a.writeError(ctx, http.StatusBadRequest, fmt.Errorf("invalid name")) |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
data, err := a.hlsManager.APIMuxersGet(name) |
|
|
|
data, err := a.HLSServer.APIMuxersGet(name) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
a.writeError(ctx, http.StatusInternalServerError, err) |
|
|
|
a.writeError(ctx, http.StatusInternalServerError, err) |
|
|
|
return |
|
|
|
return |
|
|
@ -883,8 +869,8 @@ func (a *api) onHLSMuxersGet(ctx *gin.Context) { |
|
|
|
ctx.JSON(http.StatusOK, data) |
|
|
|
ctx.JSON(http.StatusOK, data) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (a *api) onWebRTCSessionsList(ctx *gin.Context) { |
|
|
|
func (a *API) onWebRTCSessionsList(ctx *gin.Context) { |
|
|
|
data, err := a.webRTCServer.APISessionsList() |
|
|
|
data, err := a.WebRTCServer.APISessionsList() |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
a.writeError(ctx, http.StatusInternalServerError, err) |
|
|
|
a.writeError(ctx, http.StatusInternalServerError, err) |
|
|
|
return |
|
|
|
return |
|
|
@ -901,14 +887,14 @@ func (a *api) onWebRTCSessionsList(ctx *gin.Context) { |
|
|
|
ctx.JSON(http.StatusOK, data) |
|
|
|
ctx.JSON(http.StatusOK, data) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (a *api) onWebRTCSessionsGet(ctx *gin.Context) { |
|
|
|
func (a *API) onWebRTCSessionsGet(ctx *gin.Context) { |
|
|
|
uuid, err := uuid.Parse(ctx.Param("id")) |
|
|
|
uuid, err := uuid.Parse(ctx.Param("id")) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
a.writeError(ctx, http.StatusBadRequest, err) |
|
|
|
a.writeError(ctx, http.StatusBadRequest, err) |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
data, err := a.webRTCServer.APISessionsGet(uuid) |
|
|
|
data, err := a.WebRTCServer.APISessionsGet(uuid) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
a.writeError(ctx, http.StatusInternalServerError, err) |
|
|
|
a.writeError(ctx, http.StatusInternalServerError, err) |
|
|
|
return |
|
|
|
return |
|
|
@ -917,14 +903,14 @@ func (a *api) onWebRTCSessionsGet(ctx *gin.Context) { |
|
|
|
ctx.JSON(http.StatusOK, data) |
|
|
|
ctx.JSON(http.StatusOK, data) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (a *api) onWebRTCSessionsKick(ctx *gin.Context) { |
|
|
|
func (a *API) onWebRTCSessionsKick(ctx *gin.Context) { |
|
|
|
uuid, err := uuid.Parse(ctx.Param("id")) |
|
|
|
uuid, err := uuid.Parse(ctx.Param("id")) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
a.writeError(ctx, http.StatusBadRequest, err) |
|
|
|
a.writeError(ctx, http.StatusBadRequest, err) |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
err = a.webRTCServer.APISessionsKick(uuid) |
|
|
|
err = a.WebRTCServer.APISessionsKick(uuid) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
a.writeError(ctx, http.StatusInternalServerError, err) |
|
|
|
a.writeError(ctx, http.StatusInternalServerError, err) |
|
|
|
return |
|
|
|
return |
|
|
@ -933,8 +919,8 @@ func (a *api) onWebRTCSessionsKick(ctx *gin.Context) { |
|
|
|
ctx.Status(http.StatusOK) |
|
|
|
ctx.Status(http.StatusOK) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (a *api) onSRTConnsList(ctx *gin.Context) { |
|
|
|
func (a *API) onSRTConnsList(ctx *gin.Context) { |
|
|
|
data, err := a.srtServer.APIConnsList() |
|
|
|
data, err := a.SRTServer.APIConnsList() |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
a.writeError(ctx, http.StatusInternalServerError, err) |
|
|
|
a.writeError(ctx, http.StatusInternalServerError, err) |
|
|
|
return |
|
|
|
return |
|
|
@ -951,14 +937,14 @@ func (a *api) onSRTConnsList(ctx *gin.Context) { |
|
|
|
ctx.JSON(http.StatusOK, data) |
|
|
|
ctx.JSON(http.StatusOK, data) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (a *api) onSRTConnsGet(ctx *gin.Context) { |
|
|
|
func (a *API) onSRTConnsGet(ctx *gin.Context) { |
|
|
|
uuid, err := uuid.Parse(ctx.Param("id")) |
|
|
|
uuid, err := uuid.Parse(ctx.Param("id")) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
a.writeError(ctx, http.StatusBadRequest, err) |
|
|
|
a.writeError(ctx, http.StatusBadRequest, err) |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
data, err := a.srtServer.APIConnsGet(uuid) |
|
|
|
data, err := a.SRTServer.APIConnsGet(uuid) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
a.writeError(ctx, http.StatusInternalServerError, err) |
|
|
|
a.writeError(ctx, http.StatusInternalServerError, err) |
|
|
|
return |
|
|
|
return |
|
|
@ -967,14 +953,14 @@ func (a *api) onSRTConnsGet(ctx *gin.Context) { |
|
|
|
ctx.JSON(http.StatusOK, data) |
|
|
|
ctx.JSON(http.StatusOK, data) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (a *api) onSRTConnsKick(ctx *gin.Context) { |
|
|
|
func (a *API) onSRTConnsKick(ctx *gin.Context) { |
|
|
|
uuid, err := uuid.Parse(ctx.Param("id")) |
|
|
|
uuid, err := uuid.Parse(ctx.Param("id")) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
a.writeError(ctx, http.StatusBadRequest, err) |
|
|
|
a.writeError(ctx, http.StatusBadRequest, err) |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
err = a.srtServer.APIConnsKick(uuid) |
|
|
|
err = a.SRTServer.APIConnsKick(uuid) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
a.writeError(ctx, http.StatusInternalServerError, err) |
|
|
|
a.writeError(ctx, http.StatusInternalServerError, err) |
|
|
|
return |
|
|
|
return |
|
|
@ -983,9 +969,9 @@ func (a *api) onSRTConnsKick(ctx *gin.Context) { |
|
|
|
ctx.Status(http.StatusOK) |
|
|
|
ctx.Status(http.StatusOK) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// confReload is called by core.
|
|
|
|
// ReloadConf is called by core.
|
|
|
|
func (a *api) confReload(conf *conf.Conf) { |
|
|
|
func (a *API) ReloadConf(conf *conf.Conf) { |
|
|
|
a.mutex.Lock() |
|
|
|
a.mutex.Lock() |
|
|
|
defer a.mutex.Unlock() |
|
|
|
defer a.mutex.Unlock() |
|
|
|
a.conf = conf |
|
|
|
a.Conf = conf |
|
|
|
} |
|
|
|
} |