|
|
|
@ -2,6 +2,7 @@ package core
@@ -2,6 +2,7 @@ package core
|
|
|
|
|
|
|
|
|
|
import ( |
|
|
|
|
"encoding/json" |
|
|
|
|
"errors" |
|
|
|
|
"net/http" |
|
|
|
|
"reflect" |
|
|
|
|
"strconv" |
|
|
|
@ -14,6 +15,8 @@ import (
@@ -14,6 +15,8 @@ import (
|
|
|
|
|
"github.com/bluenviron/mediamtx/internal/logger" |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
var errAPINotFound = errors.New("not found") |
|
|
|
|
|
|
|
|
|
func interfaceIsEmpty(i interface{}) bool { |
|
|
|
|
return reflect.ValueOf(i).Kind() != reflect.Ptr || reflect.ValueOf(i).IsNil() |
|
|
|
|
} |
|
|
|
@ -128,6 +131,14 @@ func paginate(itemsPtr interface{}, itemsPerPageStr string, pageStr string) (int
@@ -128,6 +131,14 @@ func paginate(itemsPtr interface{}, itemsPerPageStr string, pageStr string) (int
|
|
|
|
|
return paginate2(itemsPtr, itemsPerPage, page), nil |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func abortWithError(ctx *gin.Context, err error) { |
|
|
|
|
if err == errAPINotFound { |
|
|
|
|
ctx.AbortWithStatus(http.StatusNotFound) |
|
|
|
|
} else { |
|
|
|
|
ctx.AbortWithStatus(http.StatusInternalServerError) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
type apiPathManager interface { |
|
|
|
|
apiPathsList() (*apiPathsList, error) |
|
|
|
|
apiPathsGet(string) (*apiPath, error) |
|
|
|
@ -422,13 +433,12 @@ func (a *api) onConfigPathsDelete(ctx *gin.Context) {
@@ -422,13 +433,12 @@ func (a *api) onConfigPathsDelete(ctx *gin.Context) {
|
|
|
|
|
a.mutex.Lock() |
|
|
|
|
defer a.mutex.Unlock() |
|
|
|
|
|
|
|
|
|
newConf := a.conf.Clone() |
|
|
|
|
|
|
|
|
|
if _, ok := newConf.Paths[name]; !ok { |
|
|
|
|
ctx.AbortWithStatus(http.StatusBadRequest) |
|
|
|
|
if _, ok := a.conf.Paths[name]; !ok { |
|
|
|
|
ctx.AbortWithStatus(http.StatusNotFound) |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
newConf := a.conf.Clone() |
|
|
|
|
delete(newConf.Paths, name) |
|
|
|
|
|
|
|
|
|
err := newConf.Check() |
|
|
|
@ -467,11 +477,7 @@ func (a *api) onPathsList(ctx *gin.Context) {
@@ -467,11 +477,7 @@ func (a *api) onPathsList(ctx *gin.Context) {
|
|
|
|
|
func (a *api) onPathsGet(ctx *gin.Context) { |
|
|
|
|
data, err := a.pathManager.apiPathsGet(ctx.Param("name")) |
|
|
|
|
if err != nil { |
|
|
|
|
if err.Error() == "not found" { |
|
|
|
|
ctx.AbortWithStatus(http.StatusNotFound) |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
ctx.AbortWithStatus(http.StatusInternalServerError) |
|
|
|
|
abortWithError(ctx, err) |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -505,6 +511,7 @@ func (a *api) onRTSPConnsGet(ctx *gin.Context) {
@@ -505,6 +511,7 @@ func (a *api) onRTSPConnsGet(ctx *gin.Context) {
|
|
|
|
|
|
|
|
|
|
data, err := a.rtspServer.apiConnsGet(uuid) |
|
|
|
|
if err != nil { |
|
|
|
|
abortWithError(ctx, err) |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -538,6 +545,7 @@ func (a *api) onRTSPSessionsGet(ctx *gin.Context) {
@@ -538,6 +545,7 @@ func (a *api) onRTSPSessionsGet(ctx *gin.Context) {
|
|
|
|
|
|
|
|
|
|
data, err := a.rtspServer.apiSessionsGet(uuid) |
|
|
|
|
if err != nil { |
|
|
|
|
abortWithError(ctx, err) |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -553,6 +561,7 @@ func (a *api) onRTSPSessionsKick(ctx *gin.Context) {
@@ -553,6 +561,7 @@ func (a *api) onRTSPSessionsKick(ctx *gin.Context) {
|
|
|
|
|
|
|
|
|
|
err = a.rtspServer.apiSessionsKick(uuid) |
|
|
|
|
if err != nil { |
|
|
|
|
abortWithError(ctx, err) |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -586,6 +595,7 @@ func (a *api) onRTSPSConnsGet(ctx *gin.Context) {
@@ -586,6 +595,7 @@ func (a *api) onRTSPSConnsGet(ctx *gin.Context) {
|
|
|
|
|
|
|
|
|
|
data, err := a.rtspsServer.apiConnsGet(uuid) |
|
|
|
|
if err != nil { |
|
|
|
|
abortWithError(ctx, err) |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -619,6 +629,7 @@ func (a *api) onRTSPSSessionsGet(ctx *gin.Context) {
@@ -619,6 +629,7 @@ func (a *api) onRTSPSSessionsGet(ctx *gin.Context) {
|
|
|
|
|
|
|
|
|
|
data, err := a.rtspsServer.apiSessionsGet(uuid) |
|
|
|
|
if err != nil { |
|
|
|
|
abortWithError(ctx, err) |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -634,6 +645,7 @@ func (a *api) onRTSPSSessionsKick(ctx *gin.Context) {
@@ -634,6 +645,7 @@ func (a *api) onRTSPSSessionsKick(ctx *gin.Context) {
|
|
|
|
|
|
|
|
|
|
err = a.rtspsServer.apiSessionsKick(uuid) |
|
|
|
|
if err != nil { |
|
|
|
|
abortWithError(ctx, err) |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -667,6 +679,7 @@ func (a *api) onRTMPConnsGet(ctx *gin.Context) {
@@ -667,6 +679,7 @@ func (a *api) onRTMPConnsGet(ctx *gin.Context) {
|
|
|
|
|
|
|
|
|
|
data, err := a.rtmpServer.apiConnsGet(uuid) |
|
|
|
|
if err != nil { |
|
|
|
|
abortWithError(ctx, err) |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -682,6 +695,7 @@ func (a *api) onRTMPConnsKick(ctx *gin.Context) {
@@ -682,6 +695,7 @@ func (a *api) onRTMPConnsKick(ctx *gin.Context) {
|
|
|
|
|
|
|
|
|
|
err = a.rtmpServer.apiConnsKick(uuid) |
|
|
|
|
if err != nil { |
|
|
|
|
abortWithError(ctx, err) |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -715,6 +729,7 @@ func (a *api) onRTMPSConnsGet(ctx *gin.Context) {
@@ -715,6 +729,7 @@ func (a *api) onRTMPSConnsGet(ctx *gin.Context) {
|
|
|
|
|
|
|
|
|
|
data, err := a.rtmpsServer.apiConnsGet(uuid) |
|
|
|
|
if err != nil { |
|
|
|
|
abortWithError(ctx, err) |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -730,6 +745,7 @@ func (a *api) onRTMPSConnsKick(ctx *gin.Context) {
@@ -730,6 +745,7 @@ func (a *api) onRTMPSConnsKick(ctx *gin.Context) {
|
|
|
|
|
|
|
|
|
|
err = a.rtmpsServer.apiConnsKick(uuid) |
|
|
|
|
if err != nil { |
|
|
|
|
abortWithError(ctx, err) |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -757,7 +773,7 @@ func (a *api) onHLSMuxersList(ctx *gin.Context) {
@@ -757,7 +773,7 @@ func (a *api) onHLSMuxersList(ctx *gin.Context) {
|
|
|
|
|
func (a *api) onHLSMuxersGet(ctx *gin.Context) { |
|
|
|
|
data, err := a.hlsManager.apiMuxersGet(ctx.Param("name")) |
|
|
|
|
if err != nil { |
|
|
|
|
ctx.AbortWithStatus(http.StatusInternalServerError) |
|
|
|
|
abortWithError(ctx, err) |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -791,6 +807,7 @@ func (a *api) onWebRTCSessionsGet(ctx *gin.Context) {
@@ -791,6 +807,7 @@ func (a *api) onWebRTCSessionsGet(ctx *gin.Context) {
|
|
|
|
|
|
|
|
|
|
data, err := a.webRTCManager.apiSessionsGet(uuid) |
|
|
|
|
if err != nil { |
|
|
|
|
abortWithError(ctx, err) |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -806,6 +823,7 @@ func (a *api) onWebRTCSessionsKick(ctx *gin.Context) {
@@ -806,6 +823,7 @@ func (a *api) onWebRTCSessionsKick(ctx *gin.Context) {
|
|
|
|
|
|
|
|
|
|
err = a.webRTCManager.apiSessionsKick(uuid) |
|
|
|
|
if err != nil { |
|
|
|
|
abortWithError(ctx, err) |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|