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:])
}
}