diff --git a/README.md b/README.md index b8d4a060..e50cd748 100644 --- a/README.md +++ b/README.md @@ -492,7 +492,7 @@ api: yes The API listens on `apiAddress`, that by default is `127.0.0.1:9997`; for instance, to obtain a list of active paths, run: ``` -curl http://127.0.0.1:9997/v1/paths/list +curl http://127.0.0.1:9997/v2/paths/list ``` Full documentation of the API is available on the [dedicated site](https://bluenviron.github.io/mediamtx/). diff --git a/apidocs/openapi.yaml b/apidocs/openapi.yaml index d5170461..ab9f53e1 100644 --- a/apidocs/openapi.yaml +++ b/apidocs/openapi.yaml @@ -507,7 +507,7 @@ components: $ref: '#/components/schemas/WebRTCConn' paths: - /v1/config/get: + /v2/config/get: get: operationId: configGet summary: returns the configuration. @@ -524,11 +524,11 @@ paths: '500': description: internal server error. - /v1/config/set: + /v2/config/set: post: operationId: configSet summary: changes the configuration. - description: all fields are optional. paths can't be edited with this request, use /v1/config/paths/{operation}/{name} to edit them. + description: all fields are optional. paths can't be edited with this request, use /v2/config/paths/{operation}/{name} to edit them. requestBody: required: true content: @@ -543,7 +543,7 @@ paths: '500': description: internal server error. - /v1/config/paths/add/{name}: + /v2/config/paths/add/{name}: post: operationId: configPathsAdd summary: adds the configuration of a path. @@ -569,7 +569,7 @@ paths: '500': description: internal server error. - /v1/config/paths/edit/{name}: + /v2/config/paths/edit/{name}: post: operationId: configPathsEdit summary: changes the configuration of a path. @@ -595,7 +595,7 @@ paths: '500': description: internal server error. - /v1/config/paths/remove/{name}: + /v2/config/paths/remove/{name}: post: operationId: configPathsRemove summary: removes the configuration of a path. @@ -615,7 +615,7 @@ paths: '500': description: internal server error. - /v1/hlsmuxers/list: + /v2/hlsmuxers/list: get: operationId: hlsMuxersList summary: returns all HLS muxers. @@ -645,7 +645,7 @@ paths: '500': description: internal server error. - /v1/paths/list: + /v2/paths/list: get: operationId: pathsList summary: returns all paths. @@ -675,7 +675,7 @@ paths: '500': description: internal server error. - /v1/rtspconns/list: + /v2/rtspconns/list: get: operationId: rtspConnsList summary: returns all RTSP connections. @@ -705,7 +705,7 @@ paths: '500': description: internal server error. - /v1/rtspsessions/list: + /v2/rtspsessions/list: get: operationId: rtspSessionsList summary: returns all RTSP sessions. @@ -735,7 +735,7 @@ paths: '500': description: internal server error. - /v1/rtspsessions/kick/{id}: + /v2/rtspsessions/kick/{id}: post: operationId: rtspSessionsKick summary: kicks out a RTSP session from the server. @@ -755,7 +755,7 @@ paths: '500': description: internal server error. - /v1/rtspsconns/list: + /v2/rtspsconns/list: get: operationId: rtspsConnsList summary: returns all RTSPS connections. @@ -785,7 +785,7 @@ paths: '500': description: internal server error. - /v1/rtspssessions/list: + /v2/rtspssessions/list: get: operationId: rtspsSessionsList summary: returns all RTSPS sessions. @@ -815,7 +815,7 @@ paths: '500': description: internal server error. - /v1/rtspssessions/kick/{id}: + /v2/rtspssessions/kick/{id}: post: operationId: rtspsSessionsKick summary: kicks out a RTSPS session from the server. @@ -835,7 +835,7 @@ paths: '500': description: internal server error. - /v1/rtmpconns/list: + /v2/rtmpconns/list: get: operationId: rtmpConnsList summary: returns all RTMP connections. @@ -865,7 +865,7 @@ paths: '500': description: internal server error. - /v1/rtmpconns/kick/{id}: + /v2/rtmpconns/kick/{id}: post: operationId: rtmpConnsKick summary: kicks out a RTMP connection from the server. @@ -885,7 +885,7 @@ paths: '500': description: internal server error. - /v1/rtmpsconns/list: + /v2/rtmpsconns/list: get: operationId: rtmpsConnsList summary: returns all RTMPS connections. @@ -915,7 +915,7 @@ paths: '500': description: internal server error. - /v1/rtmpsconns/kick/{id}: + /v2/rtmpsconns/kick/{id}: post: operationId: rtmpsConnsKick summary: kicks out a RTMPS connection from the server. @@ -935,7 +935,7 @@ paths: '500': description: internal server error. - /v1/webrtcsessions/list: + /v2/webrtcsessions/list: get: operationId: webrtcSessionsList summary: returns all WebRTC connections. @@ -965,7 +965,7 @@ paths: '500': description: internal server error. - /v1/webrtcsessions/kick/{id}: + /v2/webrtcsessions/kick/{id}: post: operationId: webrtcSessionsKick summary: kicks out a WebRTC connection from the server. diff --git a/internal/core/api.go b/internal/core/api.go index 95b8e47e..18768772 100644 --- a/internal/core/api.go +++ b/internal/core/api.go @@ -201,43 +201,43 @@ func newAPI( router.NoRoute(mwLog, httpServerHeaderMiddleware) group := router.Group("/", mwLog, httpServerHeaderMiddleware) - group.GET("/v1/config/get", a.onConfigGet) - group.POST("/v1/config/set", a.onConfigSet) - group.POST("/v1/config/paths/add/*name", a.onConfigPathsAdd) - group.POST("/v1/config/paths/edit/*name", a.onConfigPathsEdit) - group.POST("/v1/config/paths/remove/*name", a.onConfigPathsDelete) + group.GET("/v2/config/get", a.onConfigGet) + group.POST("/v2/config/set", a.onConfigSet) + group.POST("/v2/config/paths/add/*name", a.onConfigPathsAdd) + group.POST("/v2/config/paths/edit/*name", a.onConfigPathsEdit) + group.POST("/v2/config/paths/remove/*name", a.onConfigPathsDelete) if !interfaceIsEmpty(a.hlsManager) { - group.GET("/v1/hlsmuxers/list", a.onHLSMuxersList) + group.GET("/v2/hlsmuxers/list", a.onHLSMuxersList) } - group.GET("/v1/paths/list", a.onPathsList) + group.GET("/v2/paths/list", a.onPathsList) if !interfaceIsEmpty(a.rtspServer) { - group.GET("/v1/rtspconns/list", a.onRTSPConnsList) - group.GET("/v1/rtspsessions/list", a.onRTSPSessionsList) - group.POST("/v1/rtspsessions/kick/:id", a.onRTSPSessionsKick) + group.GET("/v2/rtspconns/list", a.onRTSPConnsList) + group.GET("/v2/rtspsessions/list", a.onRTSPSessionsList) + group.POST("/v2/rtspsessions/kick/:id", a.onRTSPSessionsKick) } if !interfaceIsEmpty(a.rtspsServer) { - group.GET("/v1/rtspsconns/list", a.onRTSPSConnsList) - group.GET("/v1/rtspssessions/list", a.onRTSPSSessionsList) - group.POST("/v1/rtspssessions/kick/:id", a.onRTSPSSessionsKick) + group.GET("/v2/rtspsconns/list", a.onRTSPSConnsList) + group.GET("/v2/rtspssessions/list", a.onRTSPSSessionsList) + group.POST("/v2/rtspssessions/kick/:id", a.onRTSPSSessionsKick) } if !interfaceIsEmpty(a.rtmpServer) { - group.GET("/v1/rtmpconns/list", a.onRTMPConnsList) - group.POST("/v1/rtmpconns/kick/:id", a.onRTMPConnsKick) + group.GET("/v2/rtmpconns/list", a.onRTMPConnsList) + group.POST("/v2/rtmpconns/kick/:id", a.onRTMPConnsKick) } if !interfaceIsEmpty(a.rtmpsServer) { - group.GET("/v1/rtmpsconns/list", a.onRTMPSConnsList) - group.POST("/v1/rtmpsconns/kick/:id", a.onRTMPSConnsKick) + group.GET("/v2/rtmpsconns/list", a.onRTMPSConnsList) + group.POST("/v2/rtmpsconns/kick/:id", a.onRTMPSConnsKick) } if !interfaceIsEmpty(a.webRTCManager) { - group.GET("/v1/webrtcsessions/list", a.onWebRTCSessionsList) - group.POST("/v1/webrtcsessions/kick/:id", a.onWebRTCSessionsKick) + group.GET("/v2/webrtcsessions/list", a.onWebRTCSessionsList) + group.POST("/v2/webrtcsessions/kick/:id", a.onWebRTCSessionsKick) } var err error diff --git a/internal/core/api_test.go b/internal/core/api_test.go index d2eec0cf..539f116c 100644 --- a/internal/core/api_test.go +++ b/internal/core/api_test.go @@ -88,7 +88,7 @@ func TestAPIConfigGet(t *testing.T) { defer p.Close() var out map[string]interface{} - err := httpRequest(http.MethodGet, "http://localhost:9997/v1/config/get", nil, &out) + err := httpRequest(http.MethodGet, "http://localhost:9997/v2/config/get", nil, &out) require.NoError(t, err) require.Equal(t, true, out["api"]) } @@ -98,7 +98,7 @@ func TestAPIConfigSet(t *testing.T) { require.Equal(t, true, ok) defer p.Close() - err := httpRequest(http.MethodPost, "http://localhost:9997/v1/config/set", map[string]interface{}{ + err := httpRequest(http.MethodPost, "http://localhost:9997/v2/config/set", map[string]interface{}{ "rtmpDisable": true, "readTimeout": "7s", "protocols": []string{"tcp"}, @@ -108,7 +108,7 @@ func TestAPIConfigSet(t *testing.T) { time.Sleep(500 * time.Millisecond) var out map[string]interface{} - err = httpRequest(http.MethodGet, "http://localhost:9997/v1/config/get", nil, &out) + err = httpRequest(http.MethodGet, "http://localhost:9997/v2/config/get", nil, &out) require.NoError(t, err) require.Equal(t, true, out["rtmpDisable"]) require.Equal(t, "7s", out["readTimeout"]) @@ -120,14 +120,14 @@ func TestAPIConfigPathsAdd(t *testing.T) { require.Equal(t, true, ok) defer p.Close() - err := httpRequest(http.MethodPost, "http://localhost:9997/v1/config/paths/add/my/path", map[string]interface{}{ + err := httpRequest(http.MethodPost, "http://localhost:9997/v2/config/paths/add/my/path", map[string]interface{}{ "source": "rtsp://127.0.0.1:9999/mypath", "sourceOnDemand": true, }, nil) require.NoError(t, err) var out map[string]interface{} - err = httpRequest(http.MethodGet, "http://localhost:9997/v1/config/get", nil, &out) + err = httpRequest(http.MethodGet, "http://localhost:9997/v2/config/get", nil, &out) require.NoError(t, err) require.Equal(t, "rtsp://127.0.0.1:9999/mypath", out["paths"].(map[string]interface{})["my/path"].(map[string]interface{})["source"]) @@ -138,13 +138,13 @@ func TestAPIConfigPathsEdit(t *testing.T) { require.Equal(t, true, ok) defer p.Close() - err := httpRequest(http.MethodPost, "http://localhost:9997/v1/config/paths/add/my/path", map[string]interface{}{ + err := httpRequest(http.MethodPost, "http://localhost:9997/v2/config/paths/add/my/path", map[string]interface{}{ "source": "rtsp://127.0.0.1:9999/mypath", "sourceOnDemand": true, }, nil) require.NoError(t, err) - err = httpRequest(http.MethodPost, "http://localhost:9997/v1/config/paths/edit/my/path", map[string]interface{}{ + err = httpRequest(http.MethodPost, "http://localhost:9997/v2/config/paths/edit/my/path", map[string]interface{}{ "source": "rtsp://127.0.0.1:9998/mypath", "sourceOnDemand": true, }, nil) @@ -155,7 +155,7 @@ func TestAPIConfigPathsEdit(t *testing.T) { Source string `json:"source"` } `json:"paths"` } - err = httpRequest(http.MethodGet, "http://localhost:9997/v1/config/get", nil, &out) + err = httpRequest(http.MethodGet, "http://localhost:9997/v2/config/get", nil, &out) require.NoError(t, err) require.Equal(t, "rtsp://127.0.0.1:9998/mypath", out.Paths["my/path"].Source) } @@ -165,19 +165,19 @@ func TestAPIConfigPathsRemove(t *testing.T) { require.Equal(t, true, ok) defer p.Close() - err := httpRequest(http.MethodPost, "http://localhost:9997/v1/config/paths/add/my/path", map[string]interface{}{ + err := httpRequest(http.MethodPost, "http://localhost:9997/v2/config/paths/add/my/path", map[string]interface{}{ "source": "rtsp://127.0.0.1:9999/mypath", "sourceOnDemand": true, }, nil) require.NoError(t, err) - err = httpRequest(http.MethodPost, "http://localhost:9997/v1/config/paths/remove/my/path", nil, nil) + err = httpRequest(http.MethodPost, "http://localhost:9997/v2/config/paths/remove/my/path", nil, nil) require.NoError(t, err) var out struct { Paths map[string]interface{} `json:"paths"` } - err = httpRequest(http.MethodGet, "http://localhost:9997/v1/config/get", nil, &out) + err = httpRequest(http.MethodGet, "http://localhost:9997/v2/config/get", nil, &out) require.NoError(t, err) _, ok = out.Paths["my/path"] require.Equal(t, false, ok) @@ -242,7 +242,7 @@ func TestAPIPathsList(t *testing.T) { }) var out pathList - err = httpRequest(http.MethodGet, "http://localhost:9997/v1/paths/list", nil, &out) + err = httpRequest(http.MethodGet, "http://localhost:9997/v2/paths/list", nil, &out) require.NoError(t, err) require.Equal(t, pathList{ PageCount: 1, @@ -303,7 +303,7 @@ func TestAPIPathsList(t *testing.T) { defer source.Close() var out pathList - err = httpRequest(http.MethodGet, "http://localhost:9997/v1/paths/list", nil, &out) + err = httpRequest(http.MethodGet, "http://localhost:9997/v2/paths/list", nil, &out) require.NoError(t, err) require.Equal(t, pathList{ PageCount: 1, @@ -328,7 +328,7 @@ func TestAPIPathsList(t *testing.T) { defer p.Close() var out pathList - err := httpRequest(http.MethodGet, "http://localhost:9997/v1/paths/list", nil, &out) + err := httpRequest(http.MethodGet, "http://localhost:9997/v2/paths/list", nil, &out) require.NoError(t, err) require.Equal(t, pathList{ PageCount: 1, @@ -353,7 +353,7 @@ func TestAPIPathsList(t *testing.T) { defer p.Close() var out pathList - err := httpRequest(http.MethodGet, "http://localhost:9997/v1/paths/list", nil, &out) + err := httpRequest(http.MethodGet, "http://localhost:9997/v2/paths/list", nil, &out) require.NoError(t, err) require.Equal(t, pathList{ PageCount: 1, @@ -378,7 +378,7 @@ func TestAPIPathsList(t *testing.T) { defer p.Close() var out pathList - err := httpRequest(http.MethodGet, "http://localhost:9997/v1/paths/list", nil, &out) + err := httpRequest(http.MethodGet, "http://localhost:9997/v2/paths/list", nil, &out) require.NoError(t, err) require.Equal(t, pathList{ PageCount: 1, @@ -595,7 +595,7 @@ func TestAPIProtocolSpecificList(t *testing.T) { State string `json:"state"` } `json:"items"` } - err = httpRequest(http.MethodGet, "http://localhost:9997/v1/"+pa+"/list", nil, &out) + err = httpRequest(http.MethodGet, "http://localhost:9997/v2/"+pa+"/list", nil, &out) require.NoError(t, err) if ca != "rtsp conns" && ca != "rtsps conns" { @@ -609,7 +609,7 @@ func TestAPIProtocolSpecificList(t *testing.T) { LastRequest string `json:"lastRequest"` } `json:"items"` } - err = httpRequest(http.MethodGet, "http://localhost:9997/v1/hlsmuxers/list", nil, &out) + err = httpRequest(http.MethodGet, "http://localhost:9997/v2/hlsmuxers/list", nil, &out) require.NoError(t, err) s := fmt.Sprintf("^%d-", time.Now().Year()) @@ -631,7 +631,7 @@ func TestAPIProtocolSpecificList(t *testing.T) { PageCount int `json:"pageCount"` Items []item `json:"items"` } - err = httpRequest(http.MethodGet, "http://localhost:9997/v1/webrtcsessions/list", nil, &out) + err = httpRequest(http.MethodGet, "http://localhost:9997/v2/webrtcsessions/list", nil, &out) require.NoError(t, err) require.Equal(t, true, out.Items[0].PeerConnectionEstablished) @@ -733,10 +733,10 @@ func TestAPIKick(t *testing.T) { ID string `json:"id"` } `json:"items"` } - err = httpRequest(http.MethodGet, "http://localhost:9997/v1/"+pa+"/list", nil, &out1) + err = httpRequest(http.MethodGet, "http://localhost:9997/v2/"+pa+"/list", nil, &out1) require.NoError(t, err) - err = httpRequest(http.MethodPost, "http://localhost:9997/v1/"+pa+"/kick/"+out1.Items[0].ID, nil, nil) + err = httpRequest(http.MethodPost, "http://localhost:9997/v2/"+pa+"/kick/"+out1.Items[0].ID, nil, nil) require.NoError(t, err) var out2 struct { @@ -744,7 +744,7 @@ func TestAPIKick(t *testing.T) { ID string `json:"id"` } `json:"items"` } - err = httpRequest(http.MethodGet, "http://localhost:9997/v1/"+pa+"/list", nil, &out2) + err = httpRequest(http.MethodGet, "http://localhost:9997/v2/"+pa+"/list", nil, &out2) require.NoError(t, err) require.Equal(t, 0, len(out2.Items)) })