Update protocol (#1075)
* update protocol * auto egress ensure unique filename * fix tests
This commit is contained in:
+10
-6
@@ -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:])
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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))
|
||||
|
||||
Reference in New Issue
Block a user