Skip to content

Commit a749a1c

Browse files
committed
allow downloading in progress recordings
1 parent ae38fe6 commit a749a1c

2 files changed

Lines changed: 9 additions & 9 deletions

File tree

server/cmd/api/api/api.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,17 +99,21 @@ func (s *ApiService) DownloadRecording(ctx context.Context, req oapi.DownloadRec
9999
return oapi.DownloadRecording404JSONResponse{NotFoundErrorJSONResponse: oapi.NotFoundErrorJSONResponse{Message: "no recording found"}}, nil
100100
}
101101

102-
if rec.IsRecording(ctx) {
103-
log.Warn("attempted to download recording while is still in progress")
104-
return oapi.DownloadRecording400JSONResponse{BadRequestErrorJSONResponse: oapi.BadRequestErrorJSONResponse{Message: "recording still in progress, please stop first"}}, nil
105-
}
106-
107102
out, meta, err := rec.Recording(ctx)
108103
if err != nil {
109104
log.Error("failed to get recording", "err", err)
110105
return oapi.DownloadRecording500JSONResponse{InternalErrorJSONResponse: oapi.InternalErrorJSONResponse{Message: "failed to get recording"}}, nil
111106
}
112107

108+
// short-circuit if the recording is still in progress and the file is arbitrary small
109+
if rec.IsRecording(ctx) && meta.Size <= 100 {
110+
return oapi.DownloadRecording202Response{
111+
Headers: oapi.DownloadRecording202ResponseHeaders{
112+
RetryAfter: 300,
113+
},
114+
}, nil
115+
}
116+
113117
log.Info("serving recording file for download", "size", meta.Size)
114118
return oapi.DownloadRecording200Videomp4Response{
115119
Body: out,

server/lib/recorder/ffmpeg.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -188,10 +188,6 @@ func (fr *FFmpegRecorder) IsRecording(ctx context.Context) bool {
188188

189189
// Recording returns the recording file as an io.ReadCloser.
190190
func (fr *FFmpegRecorder) Recording(ctx context.Context) (io.ReadCloser, *RecordingMetadata, error) {
191-
if fr.IsRecording(ctx) {
192-
return nil, nil, fmt.Errorf("recording still in progress, please call stop first")
193-
}
194-
195191
file, err := os.Open(fr.outputPath)
196192
if err != nil {
197193
return nil, nil, fmt.Errorf("failed to open recording file: %w", err)

0 commit comments

Comments
 (0)