Add support for Ingress service (#868)
Also check for Join permission on ingress API calls
This commit is contained in:
@@ -176,6 +176,13 @@ keys:
|
|||||||
# # cert_file: /path/to/cert.pem
|
# # cert_file: /path/to/cert.pem
|
||||||
# # key_file: /path/to/key.pem
|
# # key_file: /path/to/key.pem
|
||||||
|
|
||||||
|
# ingress server
|
||||||
|
# ingress:
|
||||||
|
# # Prefix used to generate RTMP URLs for RTMP ingress.
|
||||||
|
# # The stream_key will be appended to this base and returned as part of the
|
||||||
|
# # ingress info
|
||||||
|
# rtmp_base_url: "rtmp://my.domain.com/live"
|
||||||
|
|
||||||
# Region of the current node. Required if using regionaware node selector
|
# Region of the current node. Required if using regionaware node selector
|
||||||
# region: us-west-2
|
# region: us-west-2
|
||||||
|
|
||||||
|
|||||||
+21
-6
@@ -25,7 +25,7 @@ type IngressService struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func NewIngressService(
|
func NewIngressService(
|
||||||
conf *config.IngressConfig,
|
conf *config.Config,
|
||||||
rpc ingress.RPC,
|
rpc ingress.RPC,
|
||||||
store IngressStore,
|
store IngressStore,
|
||||||
rs livekit.RoomService,
|
rs livekit.RoomService,
|
||||||
@@ -33,7 +33,7 @@ func NewIngressService(
|
|||||||
) *IngressService {
|
) *IngressService {
|
||||||
|
|
||||||
return &IngressService{
|
return &IngressService{
|
||||||
conf: conf,
|
conf: &conf.Ingress,
|
||||||
rpc: rpc,
|
rpc: rpc,
|
||||||
store: store,
|
store: store,
|
||||||
roomService: rs,
|
roomService: rs,
|
||||||
@@ -54,7 +54,11 @@ func (s *IngressService) Stop() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *IngressService) CreateIngress(ctx context.Context, req *livekit.CreateIngressRequest) (*livekit.IngressInfo, error) {
|
func (s *IngressService) CreateIngress(ctx context.Context, req *livekit.CreateIngressRequest) (*livekit.IngressInfo, error) {
|
||||||
if err := EnsureRecordPermission(ctx); err != nil {
|
roomName, err := EnsureJoinPermission(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return nil, twirpAuthError(err)
|
||||||
|
}
|
||||||
|
if req.RoomName != "" && req.RoomName != string(roomName) {
|
||||||
return nil, twirpAuthError(err)
|
return nil, twirpAuthError(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -86,9 +90,14 @@ func (s *IngressService) CreateIngress(ctx context.Context, req *livekit.CreateI
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *IngressService) UpdateIngress(ctx context.Context, req *livekit.UpdateIngressRequest) (*livekit.IngressInfo, error) {
|
func (s *IngressService) UpdateIngress(ctx context.Context, req *livekit.UpdateIngressRequest) (*livekit.IngressInfo, error) {
|
||||||
if err := EnsureRecordPermission(ctx); err != nil {
|
roomName, err := EnsureJoinPermission(ctx)
|
||||||
|
if err != nil {
|
||||||
return nil, twirpAuthError(err)
|
return nil, twirpAuthError(err)
|
||||||
}
|
}
|
||||||
|
if req.RoomName != "" && req.RoomName != string(roomName) {
|
||||||
|
return nil, twirpAuthError(err)
|
||||||
|
}
|
||||||
|
|
||||||
if s.rpc == nil {
|
if s.rpc == nil {
|
||||||
return nil, ErrIngressNotConnected
|
return nil, ErrIngressNotConnected
|
||||||
}
|
}
|
||||||
@@ -146,9 +155,14 @@ func (s *IngressService) UpdateIngress(ctx context.Context, req *livekit.UpdateI
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *IngressService) ListIngress(ctx context.Context, req *livekit.ListIngressRequest) (*livekit.ListIngressResponse, error) {
|
func (s *IngressService) ListIngress(ctx context.Context, req *livekit.ListIngressRequest) (*livekit.ListIngressResponse, error) {
|
||||||
if err := EnsureRecordPermission(ctx); err != nil {
|
roomName, err := EnsureJoinPermission(ctx)
|
||||||
|
if err != nil {
|
||||||
return nil, twirpAuthError(err)
|
return nil, twirpAuthError(err)
|
||||||
}
|
}
|
||||||
|
if req.RoomName != "" && req.RoomName != string(roomName) {
|
||||||
|
return nil, twirpAuthError(err)
|
||||||
|
}
|
||||||
|
|
||||||
if s.rpc == nil {
|
if s.rpc == nil {
|
||||||
return nil, ErrIngressNotConnected
|
return nil, ErrIngressNotConnected
|
||||||
}
|
}
|
||||||
@@ -163,9 +177,10 @@ func (s *IngressService) ListIngress(ctx context.Context, req *livekit.ListIngre
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *IngressService) DeleteIngress(ctx context.Context, req *livekit.DeleteIngressRequest) (*livekit.IngressInfo, error) {
|
func (s *IngressService) DeleteIngress(ctx context.Context, req *livekit.DeleteIngressRequest) (*livekit.IngressInfo, error) {
|
||||||
if err := EnsureRecordPermission(ctx); err != nil {
|
if _, err := EnsureJoinPermission(ctx); err != nil {
|
||||||
return nil, twirpAuthError(err)
|
return nil, twirpAuthError(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if s.rpc == nil {
|
if s.rpc == nil {
|
||||||
return nil, ErrIngressNotConnected
|
return nil, ErrIngressNotConnected
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ import (
|
|||||||
type LivekitServer struct {
|
type LivekitServer struct {
|
||||||
config *config.Config
|
config *config.Config
|
||||||
egressService *EgressService
|
egressService *EgressService
|
||||||
|
ingressService *IngressService
|
||||||
rtcService *RTCService
|
rtcService *RTCService
|
||||||
httpServer *http.Server
|
httpServer *http.Server
|
||||||
promServer *http.Server
|
promServer *http.Server
|
||||||
@@ -44,6 +45,7 @@ type LivekitServer struct {
|
|||||||
func NewLivekitServer(conf *config.Config,
|
func NewLivekitServer(conf *config.Config,
|
||||||
roomService livekit.RoomService,
|
roomService livekit.RoomService,
|
||||||
egressService *EgressService,
|
egressService *EgressService,
|
||||||
|
ingressService *IngressService,
|
||||||
rtcService *RTCService,
|
rtcService *RTCService,
|
||||||
keyProvider auth.KeyProvider,
|
keyProvider auth.KeyProvider,
|
||||||
router routing.Router,
|
router routing.Router,
|
||||||
@@ -54,6 +56,7 @@ func NewLivekitServer(conf *config.Config,
|
|||||||
s = &LivekitServer{
|
s = &LivekitServer{
|
||||||
config: conf,
|
config: conf,
|
||||||
egressService: egressService,
|
egressService: egressService,
|
||||||
|
ingressService: ingressService,
|
||||||
rtcService: rtcService,
|
rtcService: rtcService,
|
||||||
router: router,
|
router: router,
|
||||||
roomManager: roomManager,
|
roomManager: roomManager,
|
||||||
@@ -80,6 +83,7 @@ func NewLivekitServer(conf *config.Config,
|
|||||||
|
|
||||||
roomServer := livekit.NewRoomServiceServer(roomService)
|
roomServer := livekit.NewRoomServiceServer(roomService)
|
||||||
egressServer := livekit.NewEgressServer(egressService)
|
egressServer := livekit.NewEgressServer(egressService)
|
||||||
|
ingressServer := livekit.NewIngressServer(ingressService)
|
||||||
|
|
||||||
mux := http.NewServeMux()
|
mux := http.NewServeMux()
|
||||||
if conf.Development {
|
if conf.Development {
|
||||||
@@ -90,6 +94,7 @@ func NewLivekitServer(conf *config.Config,
|
|||||||
}
|
}
|
||||||
mux.Handle(roomServer.PathPrefix(), roomServer)
|
mux.Handle(roomServer.PathPrefix(), roomServer)
|
||||||
mux.Handle(egressServer.PathPrefix(), egressServer)
|
mux.Handle(egressServer.PathPrefix(), egressServer)
|
||||||
|
mux.Handle(ingressServer.PathPrefix(), ingressServer)
|
||||||
mux.Handle("/rtc", rtcService)
|
mux.Handle("/rtc", rtcService)
|
||||||
mux.HandleFunc("/rtc/validate", rtcService.Validate)
|
mux.HandleFunc("/rtc/validate", rtcService.Validate)
|
||||||
mux.HandleFunc("/", s.healthCheck)
|
mux.HandleFunc("/", s.healthCheck)
|
||||||
@@ -150,6 +155,8 @@ func (s *LivekitServer) Start() error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
s.ingressService.Start()
|
||||||
|
|
||||||
addresses := s.config.BindAddresses
|
addresses := s.config.BindAddresses
|
||||||
if addresses == nil {
|
if addresses == nil {
|
||||||
addresses = []string{""}
|
addresses = []string{""}
|
||||||
@@ -238,6 +245,7 @@ func (s *LivekitServer) Start() error {
|
|||||||
|
|
||||||
s.roomManager.Stop()
|
s.roomManager.Stop()
|
||||||
s.egressService.Stop()
|
s.egressService.Stop()
|
||||||
|
s.ingressService.Stop()
|
||||||
|
|
||||||
close(s.closedChan)
|
close(s.closedChan)
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ import (
|
|||||||
|
|
||||||
"github.com/livekit/protocol/auth"
|
"github.com/livekit/protocol/auth"
|
||||||
"github.com/livekit/protocol/egress"
|
"github.com/livekit/protocol/egress"
|
||||||
|
"github.com/livekit/protocol/ingress"
|
||||||
"github.com/livekit/protocol/livekit"
|
"github.com/livekit/protocol/livekit"
|
||||||
"github.com/livekit/protocol/logger"
|
"github.com/livekit/protocol/logger"
|
||||||
"github.com/livekit/protocol/webhook"
|
"github.com/livekit/protocol/webhook"
|
||||||
@@ -44,6 +45,9 @@ func InitializeServer(conf *config.Config, currentNode routing.LocalNode) (*Live
|
|||||||
egress.NewRedisRPCClient,
|
egress.NewRedisRPCClient,
|
||||||
getEgressStore,
|
getEgressStore,
|
||||||
NewEgressService,
|
NewEgressService,
|
||||||
|
ingress.NewRedisRPC,
|
||||||
|
getIngressStore,
|
||||||
|
NewIngressService,
|
||||||
NewRoomAllocator,
|
NewRoomAllocator,
|
||||||
NewRoomService,
|
NewRoomService,
|
||||||
NewRTCService,
|
NewRTCService,
|
||||||
@@ -175,6 +179,15 @@ func getEgressStore(s ObjectStore) EgressStore {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getIngressStore(s ObjectStore) IngressStore {
|
||||||
|
switch store := s.(type) {
|
||||||
|
case *RedisStore:
|
||||||
|
return store
|
||||||
|
default:
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func createClientConfiguration() clientconfiguration.ClientConfigurationManager {
|
func createClientConfiguration() clientconfiguration.ClientConfigurationManager {
|
||||||
return clientconfiguration.NewStaticClientConfigurationManager(clientconfiguration.StaticConfigurations)
|
return clientconfiguration.NewStaticClientConfigurationManager(clientconfiguration.StaticConfigurations)
|
||||||
}
|
}
|
||||||
|
|||||||
+14
-1
@@ -17,6 +17,7 @@ import (
|
|||||||
"github.com/livekit/livekit-server/pkg/telemetry"
|
"github.com/livekit/livekit-server/pkg/telemetry"
|
||||||
"github.com/livekit/protocol/auth"
|
"github.com/livekit/protocol/auth"
|
||||||
"github.com/livekit/protocol/egress"
|
"github.com/livekit/protocol/egress"
|
||||||
|
"github.com/livekit/protocol/ingress"
|
||||||
"github.com/livekit/protocol/livekit"
|
"github.com/livekit/protocol/livekit"
|
||||||
"github.com/livekit/protocol/logger"
|
"github.com/livekit/protocol/logger"
|
||||||
"github.com/livekit/protocol/webhook"
|
"github.com/livekit/protocol/webhook"
|
||||||
@@ -61,6 +62,9 @@ func InitializeServer(conf *config.Config, currentNode routing.LocalNode) (*Live
|
|||||||
analyticsService := telemetry.NewAnalyticsService(conf, currentNode)
|
analyticsService := telemetry.NewAnalyticsService(conf, currentNode)
|
||||||
telemetryService := telemetry.NewTelemetryService(notifier, analyticsService)
|
telemetryService := telemetry.NewTelemetryService(notifier, analyticsService)
|
||||||
egressService := NewEgressService(rpcClient, objectStore, egressStore, roomService, telemetryService)
|
egressService := NewEgressService(rpcClient, objectStore, egressStore, roomService, telemetryService)
|
||||||
|
rpc := ingress.NewRedisRPC(nodeID, client)
|
||||||
|
ingressStore := getIngressStore(objectStore)
|
||||||
|
ingressService := NewIngressService(conf, rpc, ingressStore, roomService, telemetryService)
|
||||||
rtcService := NewRTCService(conf, roomAllocator, objectStore, router, currentNode)
|
rtcService := NewRTCService(conf, roomAllocator, objectStore, router, currentNode)
|
||||||
clientConfigurationManager := createClientConfiguration()
|
clientConfigurationManager := createClientConfiguration()
|
||||||
roomManager, err := NewLocalRoomManager(conf, objectStore, currentNode, router, telemetryService, clientConfigurationManager)
|
roomManager, err := NewLocalRoomManager(conf, objectStore, currentNode, router, telemetryService, clientConfigurationManager)
|
||||||
@@ -72,7 +76,7 @@ func InitializeServer(conf *config.Config, currentNode routing.LocalNode) (*Live
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
livekitServer, err := NewLivekitServer(conf, roomService, egressService, rtcService, keyProvider, router, roomManager, server, currentNode)
|
livekitServer, err := NewLivekitServer(conf, roomService, egressService, ingressService, rtcService, keyProvider, router, roomManager, server, currentNode)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -201,6 +205,15 @@ func getEgressStore(s ObjectStore) EgressStore {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getIngressStore(s ObjectStore) IngressStore {
|
||||||
|
switch store := s.(type) {
|
||||||
|
case *RedisStore:
|
||||||
|
return store
|
||||||
|
default:
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func createClientConfiguration() clientconfiguration.ClientConfigurationManager {
|
func createClientConfiguration() clientconfiguration.ClientConfigurationManager {
|
||||||
return clientconfiguration.NewStaticClientConfigurationManager(clientconfiguration.StaticConfigurations)
|
return clientconfiguration.NewStaticClientConfigurationManager(clientconfiguration.StaticConfigurations)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user