From 438a240069a759724d58099ccf9d5a6a8a563ee4 Mon Sep 17 00:00:00 2001 From: Paxx Date: Thu, 29 Jun 2023 16:54:33 +0200 Subject: [PATCH] improved the recording api's --- ovenmedia/ovenmedia.go | 21 ++++++++++++++------- ovenmedia/recording.go | 17 ++++++++++++++++- ovenmedia/response.go | 5 +++++ 3 files changed, 35 insertions(+), 8 deletions(-) diff --git a/ovenmedia/ovenmedia.go b/ovenmedia/ovenmedia.go index 3e7c03c..c39ff55 100644 --- a/ovenmedia/ovenmedia.go +++ b/ovenmedia/ovenmedia.go @@ -2,7 +2,6 @@ package ovenmedia import ( "github.com/go-resty/resty/v2" - "reflect" ) type ovenMedia struct { @@ -30,6 +29,7 @@ type IOvenMediaClient interface { StartRecording(vHost string, appName string, body RequestRecordingStart) (*ResponseRecordingStart, error) StopRecording(vHost string, appName string, body RequestRecordingStop) (*ResponseRecordingStart, error) GetRecordingState(vHost string, appName string, body *RequestRecordingStop) (*ResponseRecordingStart, error) + ListRecordingState(vHost string, appName string) (*ResponseRecordingStateList, error) // Stats GetStatsVhosts(vHost string) (*ResponseStats, error) GetStatsAppVhosts(vHost string, appName string) (*ResponseStats, error) @@ -53,15 +53,22 @@ func (o *ovenMedia) IsDebug() bool { // Resty Methods -func (o *ovenMedia) post(url string, body interface{}) (*resty.Response, error) { - r := o.restClient.R(). - SetHeader("Accept", "application/json") +func (o *ovenMedia) postNoBody(url string) (*resty.Response, error) { + resp, err := o.restClient.R(). + SetHeader("Accept", "application/json"). + Post(url) - if !reflect.ValueOf(body).IsNil() { - r.SetBody(body) + if err != nil { + return nil, err } + return resp, nil +} - resp, err := r.Post(url) +func (o *ovenMedia) post(url string, body interface{}) (*resty.Response, error) { + resp, err := o.restClient.R(). + SetHeader("Accept", "application/json"). + SetBody(body). + Post(url) if err != nil { return nil, err diff --git a/ovenmedia/recording.go b/ovenmedia/recording.go index 828bb61..30bb905 100644 --- a/ovenmedia/recording.go +++ b/ovenmedia/recording.go @@ -37,7 +37,22 @@ func (o *ovenMedia) StopRecording(vHost string, appName string, body RequestReco // -func (o *ovenMedia) GetRecordingState(vHost string, appName string, body *RequestRecordingStop) (*ResponseRecordingStart, error) { +func (o *ovenMedia) ListRecordingState(vHost string, appName string) (*ResponseRecordingStateList, error) { + // + resp, err := o.postNoBody(GET_VHOSTS_RECORDS_BY_NAME(vHost, appName)) + if err != nil { + return nil, err + } + // + var obj ResponseRecordingStateList + if err := json.Unmarshal(resp.Body(), &obj); err != nil { + return nil, err + } + // + return &obj, nil +} + +func (o *ovenMedia) GetRecordingState(vHost string, appName string, body RequestRecordingStop) (*ResponseRecordingStart, error) { // resp, err := o.post(GET_VHOSTS_RECORDS_BY_NAME(vHost, appName), body) if err != nil { diff --git a/ovenmedia/response.go b/ovenmedia/response.go index abc7cfb..239f9ea 100644 --- a/ovenmedia/response.go +++ b/ovenmedia/response.go @@ -195,6 +195,11 @@ type ResponseRecordingStart struct { Response ResponseRecording `json:"response"` } +type ResponseRecordingStateList struct { + BaseResponseOK + Response []ResponseRecording `json:"response"` +} + type ResponseRecording struct { State string `json:"state"` ID string `json:"id"`