From 6fca5647fdd87a1f380ddb77db1bc92805dc3eb0 Mon Sep 17 00:00:00 2001 From: David Colburn Date: Mon, 26 Jul 2021 23:43:57 -0700 Subject: [PATCH] update protocol --- go.mod | 2 +- go.sum | 4 ++-- pkg/recording/recording.go | 29 +++++------------------------ 3 files changed, 8 insertions(+), 27 deletions(-) diff --git a/go.mod b/go.mod index 80ad123fb..ccfe53004 100644 --- a/go.mod +++ b/go.mod @@ -11,7 +11,7 @@ require ( github.com/google/wire v0.5.0 github.com/gorilla/websocket v1.4.2 github.com/jxskiss/base62 v0.0.0-20191017122030-4f11678b909b - github.com/livekit/protocol v0.6.0 + github.com/livekit/protocol v0.6.1 github.com/magefile/mage v1.11.0 github.com/maxbrunsfeld/counterfeiter/v6 v6.3.0 github.com/mitchellh/go-homedir v1.1.0 diff --git a/go.sum b/go.sum index a93aa4702..e5ee9780b 100644 --- a/go.sum +++ b/go.sum @@ -237,8 +237,8 @@ github.com/lithammer/shortuuid/v3 v3.0.6 h1:pr15YQyvhiSX/qPxncFtqk+v4xLEpOZObbsY github.com/lithammer/shortuuid/v3 v3.0.6/go.mod h1:vMk8ke37EmiewwolSO1NLW8vP4ZaKlRuDIi8tWWmAts= github.com/livekit/ion-sfu v1.20.5 h1:2PltjaVWd4y3gUcBssHwa/V3jIp92z5vC0+6CzB7rz8= github.com/livekit/ion-sfu v1.20.5/go.mod h1:dEdOG4KSqIftr5HxxqciNKBIdu0v3OD0ZYL7A3J09KA= -github.com/livekit/protocol v0.6.0 h1:1tTwGMuA2WLwIaOXZHiuBZTjZMYY/t3TMK1zjQBvn7o= -github.com/livekit/protocol v0.6.0/go.mod h1:wo3CGfYB7XMF8GoVJAfTARrYSP/ombi+sbLl6AYdKP0= +github.com/livekit/protocol v0.6.1 h1:+AwPkBNZoUYCoGwmwGxsdNQN7bickSyVt1p1jQi3m2U= +github.com/livekit/protocol v0.6.1/go.mod h1:wo3CGfYB7XMF8GoVJAfTARrYSP/ombi+sbLl6AYdKP0= github.com/lucsky/cuid v1.0.2 h1:z4XlExeoderxoPj2/dxKOyPxe9RCOu7yNq9/XWxIUMQ= github.com/lucsky/cuid v1.0.2/go.mod h1:QaaJqckboimOmhRSJXSx/+IT+VTfxfPGSo/6mfgUfmE= github.com/lyft/protoc-gen-validate v0.0.13/go.mod h1:XbGvPuh87YZc5TdIa2/I4pLk0QoUACkjt2znoq26NVQ= diff --git a/pkg/recording/recording.go b/pkg/recording/recording.go index 8e0b1fd7c..3aa396052 100644 --- a/pkg/recording/recording.go +++ b/pkg/recording/recording.go @@ -16,13 +16,6 @@ type RoomRecorder struct { rc *redis.Client } -const ( - ReservationChannel = "RESERVE_RECORDER" - recorderTimeout = time.Second * 3 - // used by livekit-recorder - ReservationTimeout = time.Second * 2 -) - func NewRoomRecorder(rc *redis.Client) *RoomRecorder { if rc == nil { return nil @@ -43,10 +36,10 @@ func (s *RoomRecorder) ReserveRecorder(ctx context.Context, req *livekit.RecordR return "", err } - sub := s.rc.Subscribe(ctx, ResponseChannel(id)) + sub := s.rc.Subscribe(ctx, utils.ReservationResponseChannel(id)) defer sub.Close() - err = s.rc.Publish(ctx, ReservationChannel, string(b)).Err() + err = s.rc.Publish(ctx, utils.ReservationChannel, string(b)).Err() if err != nil { return "", err } @@ -54,27 +47,15 @@ func (s *RoomRecorder) ReserveRecorder(ctx context.Context, req *livekit.RecordR select { case <-sub.Channel(): return id, nil - case <-time.After(recorderTimeout): + case <-time.After(utils.RecorderTimeout): return "", errors.New("no recorders available") } } func (s *RoomRecorder) StartRecording(ctx context.Context, recordingID string) error { - return s.rc.Publish(ctx, StartRecordingChannel(recordingID), nil).Err() + return s.rc.Publish(ctx, utils.StartRecordingChannel(recordingID), nil).Err() } func (s *RoomRecorder) EndRecording(ctx context.Context, recordingID string) error { - return s.rc.Publish(ctx, EndRecordingChannel(recordingID), nil).Err() -} - -func ResponseChannel(id string) string { - return "RESPONSE_" + id -} - -func StartRecordingChannel(id string) string { - return "START_RECORDING_" + id -} - -func EndRecordingChannel(id string) string { - return "END_RECORDING_" + id + return s.rc.Publish(ctx, utils.EndRecordingChannel(recordingID), nil).Err() }