Update protocol (#1075)

* update protocol

* auto egress ensure unique filename

* fix tests
This commit is contained in:
David Colburn
2022-10-10 10:38:46 -07:00
committed by GitHub
parent a5bed14d02
commit 78386c4669
4 changed files with 18 additions and 14 deletions
+10 -6
View File
@@ -5,7 +5,6 @@ import (
"errors"
"fmt"
"strings"
"time"
"github.com/livekit/livekit-server/pkg/rtc/types"
"github.com/livekit/livekit-server/pkg/telemetry"
@@ -53,7 +52,7 @@ func startTrackEgress(
) (*livekit.TrackEgressRequest, error) {
output := &livekit.DirectFileOutput{
Filepath: getFilePath(opts.FilePrefix, string(track.ID())),
Filepath: getFilePath(opts.Filepath),
}
switch out := opts.Output.(type) {
@@ -86,10 +85,15 @@ func startTrackEgress(
return req, err
}
func getFilePath(prefix, identifier string) string {
if prefix == "" || strings.HasSuffix(prefix, "/") {
return fmt.Sprintf("%s%s_%s", prefix, identifier, time.Now().Format("2006-01-02T150405"))
func getFilePath(filepath string) string {
if filepath == "" || strings.HasSuffix(filepath, "/") || strings.Contains(filepath, "{track_id}") {
return filepath
}
idx := strings.Index(filepath, ".")
if idx == -1 {
return fmt.Sprintf("%s-{track_id}", filepath)
} else {
return fmt.Sprintf("%s_%s_%s", prefix, identifier, time.Now().Format("2006-01-02T150405"))
return fmt.Sprintf("%s-%s%s", filepath[:idx], "{track_id}", filepath[idx:])
}
}
+2 -2
View File
@@ -26,14 +26,14 @@ func TestRoomInternal(t *testing.T) {
Name: "test_room",
}
internal := &livekit.RoomInternal{
TrackEgress: &livekit.AutoTrackEgress{FilePrefix: "egress"},
TrackEgress: &livekit.AutoTrackEgress{Filepath: "egress"},
}
require.NoError(t, rs.StoreRoom(ctx, room, internal))
actualRoom, actualInternal, err := rs.LoadRoom(ctx, livekit.RoomName(room.Name), true)
require.NoError(t, err)
require.Equal(t, room.Sid, actualRoom.Sid)
require.Equal(t, internal.TrackEgress.FilePrefix, actualInternal.TrackEgress.FilePrefix)
require.Equal(t, internal.TrackEgress.Filepath, actualInternal.TrackEgress.Filepath)
// remove internal
require.NoError(t, rs.StoreRoom(ctx, room, nil))