diff --git a/go.mod b/go.mod index b1d53bcec..e37e5bb7d 100644 --- a/go.mod +++ b/go.mod @@ -18,7 +18,7 @@ require ( github.com/jxskiss/base62 v1.1.0 github.com/livekit/mageutil v0.0.0-20230125210925-54e8a70427c1 github.com/livekit/mediatransportutil v0.0.0-20230326055817-ed569ca13d26 - github.com/livekit/protocol v1.5.3-0.20230410011118-30f8b4c081aa + github.com/livekit/protocol v1.5.3-0.20230412231617-f70173e98ef5 github.com/livekit/psrpc v0.2.11-0.20230405191830-d76f71512630 github.com/mackerelio/go-osstat v0.2.4 github.com/magefile/mage v1.14.0 diff --git a/go.sum b/go.sum index e763d9714..6a13f4899 100644 --- a/go.sum +++ b/go.sum @@ -235,8 +235,8 @@ github.com/livekit/mageutil v0.0.0-20230125210925-54e8a70427c1 h1:jm09419p0lqTkD github.com/livekit/mageutil v0.0.0-20230125210925-54e8a70427c1/go.mod h1:Rs3MhFwutWhGwmY1VQsygw28z5bWcnEYmS1OG9OxjOQ= github.com/livekit/mediatransportutil v0.0.0-20230326055817-ed569ca13d26 h1:QlQFyMwCDgjyySsrgmrMcVbEBA6KZcyTzvK+z346tUA= github.com/livekit/mediatransportutil v0.0.0-20230326055817-ed569ca13d26/go.mod h1:eDA41kiySZoG+wy4Etsjb3w0jjLx69i/vAmSjG4bteA= -github.com/livekit/protocol v1.5.3-0.20230410011118-30f8b4c081aa h1:s7ACG7CGvt12tiBYSsywSavYh3S/JLVZI7Ob3ot0rKs= -github.com/livekit/protocol v1.5.3-0.20230410011118-30f8b4c081aa/go.mod h1:GzQYVsW/eIsI7xdDTNUGed+SD7IpCI1dLdOlIqRmd2U= +github.com/livekit/protocol v1.5.3-0.20230412231617-f70173e98ef5 h1:0BaB2jtGxPDh/8p72MOJnsAUdqRiUvMU99Pm6q++DoM= +github.com/livekit/protocol v1.5.3-0.20230412231617-f70173e98ef5/go.mod h1:GzQYVsW/eIsI7xdDTNUGed+SD7IpCI1dLdOlIqRmd2U= github.com/livekit/psrpc v0.2.11-0.20230405191830-d76f71512630 h1:Rm5KLZgQxWnTidY+H8MsAV6sk1iiFxeXqPFgSLkMing= github.com/livekit/psrpc v0.2.11-0.20230405191830-d76f71512630/go.mod h1:K0j8f1PgLShR7Lx80KbmwFkDH2BvOnycXGV0OSRURKc= github.com/mackerelio/go-osstat v0.2.4 h1:qxGbdPkFo65PXOb/F/nhDKpF2nGmGaCFDLXoZjJTtUs= diff --git a/pkg/service/ingress.go b/pkg/service/ingress.go index 6d66474a9..52ff81e69 100644 --- a/pkg/service/ingress.go +++ b/pkg/service/ingress.go @@ -5,6 +5,7 @@ import ( "github.com/livekit/livekit-server/pkg/config" "github.com/livekit/livekit-server/pkg/telemetry" + "github.com/livekit/protocol/ingress" "github.com/livekit/protocol/livekit" "github.com/livekit/protocol/logger" "github.com/livekit/protocol/rpc" @@ -90,6 +91,10 @@ func (s *IngressService) CreateIngressWithUrlPrefix(ctx context.Context, urlPref State: &livekit.IngressState{}, } + if err := ingress.ValidateForSerialization(info); err != nil { + return nil, err + } + if err = s.store.StoreIngress(ctx, info); err != nil { logger.Errorw("could not write ingress info", err) return nil, err @@ -98,6 +103,33 @@ func (s *IngressService) CreateIngressWithUrlPrefix(ctx context.Context, urlPref return info, nil } +func updateInfoUsingRequest(req *livekit.UpdateIngressRequest, info *livekit.IngressInfo) error { + if req.Name != "" { + info.Name = req.Name + } + if req.RoomName != "" { + info.RoomName = req.RoomName + } + if req.ParticipantIdentity != "" { + info.ParticipantIdentity = req.ParticipantIdentity + } + if req.ParticipantName != "" { + info.ParticipantName = req.ParticipantName + } + if req.Audio != nil { + info.Audio = req.Audio + } + if req.Video != nil { + info.Video = req.Video + } + + if err := ingress.ValidateForSerialization(info); err != nil { + return err + } + + return nil +} + func (s *IngressService) UpdateIngress(ctx context.Context, req *livekit.UpdateIngressRequest) (*livekit.IngressInfo, error) { fields := []interface{}{ "ingress", req.IngressId, @@ -132,28 +164,19 @@ func (s *IngressService) UpdateIngress(ctx context.Context, req *livekit.UpdateI fallthrough case livekit.IngressState_ENDPOINT_INACTIVE: - if req.Name != "" { - info.Name = req.Name - } - if req.RoomName != "" { - info.RoomName = req.RoomName - } - if req.ParticipantIdentity != "" { - info.ParticipantIdentity = req.ParticipantIdentity - } - if req.ParticipantName != "" { - info.ParticipantName = req.ParticipantName - } - if req.Audio != nil { - info.Audio = req.Audio - } - if req.Video != nil { - info.Video = req.Video + err = updateInfoUsingRequest(req, info) + if err != nil { + return nil, err } case livekit.IngressState_ENDPOINT_BUFFERING, livekit.IngressState_ENDPOINT_PUBLISHING: - // Do not update store the returned state as the ingress service will do it + err := updateInfoUsingRequest(req, info) + if err != nil { + return nil, err + } + + // Do not store the returned state as the ingress service will do it if _, err = s.psrpcClient.UpdateIngress(ctx, req.IngressId, req); err != nil { logger.Warnw("could not update active ingress", err) }