Updated egress rpc (#1252)

* updated egress rpc

* check if egress exists on stop

* fix static check

* remove old migration code

* rename

* regenerate, update test

* latest staticcheck

* update to psrpc 0.1.0

* fix tests

* dual write rpcs on running egress

* remove unused field

* fix race, change service for egress impl

* return nil if bus is nil

* id -> ids

* add affinityFunc to StartEgress
This commit is contained in:
David Colburn
2022-12-22 21:03:27 -08:00
committed by GitHub
parent 05132799a5
commit 6719a3c714
15 changed files with 1031 additions and 187 deletions
+295
View File
@@ -0,0 +1,295 @@
// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
// protoc-gen-go v1.27.1
// protoc v3.21.5
// source: pkg/service/rpc/egress.proto
package rpc
import (
livekit "github.com/livekit/protocol/livekit"
_ "github.com/livekit/psrpc/protoc-gen-psrpc/options"
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
reflect "reflect"
sync "sync"
)
const (
// Verify that this generated code is sufficiently up-to-date.
_ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion)
// Verify that runtime/protoimpl is sufficiently up-to-date.
_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20)
)
type Empty struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
}
func (x *Empty) Reset() {
*x = Empty{}
if protoimpl.UnsafeEnabled {
mi := &file_pkg_service_rpc_egress_proto_msgTypes[0]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *Empty) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*Empty) ProtoMessage() {}
func (x *Empty) ProtoReflect() protoreflect.Message {
mi := &file_pkg_service_rpc_egress_proto_msgTypes[0]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use Empty.ProtoReflect.Descriptor instead.
func (*Empty) Descriptor() ([]byte, []int) {
return file_pkg_service_rpc_egress_proto_rawDescGZIP(), []int{0}
}
type ListActiveEgressRequest struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
}
func (x *ListActiveEgressRequest) Reset() {
*x = ListActiveEgressRequest{}
if protoimpl.UnsafeEnabled {
mi := &file_pkg_service_rpc_egress_proto_msgTypes[1]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *ListActiveEgressRequest) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*ListActiveEgressRequest) ProtoMessage() {}
func (x *ListActiveEgressRequest) ProtoReflect() protoreflect.Message {
mi := &file_pkg_service_rpc_egress_proto_msgTypes[1]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use ListActiveEgressRequest.ProtoReflect.Descriptor instead.
func (*ListActiveEgressRequest) Descriptor() ([]byte, []int) {
return file_pkg_service_rpc_egress_proto_rawDescGZIP(), []int{1}
}
type ListActiveEgressResponse struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
EgressIds []string `protobuf:"bytes,1,rep,name=egress_ids,json=egressIds,proto3" json:"egress_ids,omitempty"`
}
func (x *ListActiveEgressResponse) Reset() {
*x = ListActiveEgressResponse{}
if protoimpl.UnsafeEnabled {
mi := &file_pkg_service_rpc_egress_proto_msgTypes[2]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *ListActiveEgressResponse) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*ListActiveEgressResponse) ProtoMessage() {}
func (x *ListActiveEgressResponse) ProtoReflect() protoreflect.Message {
mi := &file_pkg_service_rpc_egress_proto_msgTypes[2]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use ListActiveEgressResponse.ProtoReflect.Descriptor instead.
func (*ListActiveEgressResponse) Descriptor() ([]byte, []int) {
return file_pkg_service_rpc_egress_proto_rawDescGZIP(), []int{2}
}
func (x *ListActiveEgressResponse) GetEgressIds() []string {
if x != nil {
return x.EgressIds
}
return nil
}
var File_pkg_service_rpc_egress_proto protoreflect.FileDescriptor
var file_pkg_service_rpc_egress_proto_rawDesc = []byte{
0x0a, 0x1c, 0x70, 0x6b, 0x67, 0x2f, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x2f, 0x72, 0x70,
0x63, 0x2f, 0x65, 0x67, 0x72, 0x65, 0x73, 0x73, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x03,
0x72, 0x70, 0x63, 0x1a, 0x0d, 0x6f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2e, 0x70, 0x72, 0x6f,
0x74, 0x6f, 0x1a, 0x1a, 0x6c, 0x69, 0x76, 0x65, 0x6b, 0x69, 0x74, 0x5f, 0x72, 0x70, 0x63, 0x5f,
0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x14,
0x6c, 0x69, 0x76, 0x65, 0x6b, 0x69, 0x74, 0x5f, 0x65, 0x67, 0x72, 0x65, 0x73, 0x73, 0x2e, 0x70,
0x72, 0x6f, 0x74, 0x6f, 0x22, 0x07, 0x0a, 0x05, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x22, 0x19, 0x0a,
0x17, 0x4c, 0x69, 0x73, 0x74, 0x41, 0x63, 0x74, 0x69, 0x76, 0x65, 0x45, 0x67, 0x72, 0x65, 0x73,
0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x22, 0x39, 0x0a, 0x18, 0x4c, 0x69, 0x73, 0x74,
0x41, 0x63, 0x74, 0x69, 0x76, 0x65, 0x45, 0x67, 0x72, 0x65, 0x73, 0x73, 0x52, 0x65, 0x73, 0x70,
0x6f, 0x6e, 0x73, 0x65, 0x12, 0x1d, 0x0a, 0x0a, 0x65, 0x67, 0x72, 0x65, 0x73, 0x73, 0x5f, 0x69,
0x64, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x09, 0x52, 0x09, 0x65, 0x67, 0x72, 0x65, 0x73, 0x73,
0x49, 0x64, 0x73, 0x32, 0xb2, 0x01, 0x0a, 0x0e, 0x45, 0x67, 0x72, 0x65, 0x73, 0x73, 0x49, 0x6e,
0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x12, 0x47, 0x0a, 0x0b, 0x53, 0x74, 0x61, 0x72, 0x74, 0x45,
0x67, 0x72, 0x65, 0x73, 0x73, 0x12, 0x1b, 0x2e, 0x6c, 0x69, 0x76, 0x65, 0x6b, 0x69, 0x74, 0x2e,
0x53, 0x74, 0x61, 0x72, 0x74, 0x45, 0x67, 0x72, 0x65, 0x73, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65,
0x73, 0x74, 0x1a, 0x13, 0x2e, 0x6c, 0x69, 0x76, 0x65, 0x6b, 0x69, 0x74, 0x2e, 0x45, 0x67, 0x72,
0x65, 0x73, 0x73, 0x49, 0x6e, 0x66, 0x6f, 0x22, 0x06, 0xb2, 0x89, 0x01, 0x02, 0x20, 0x01, 0x12,
0x57, 0x0a, 0x10, 0x4c, 0x69, 0x73, 0x74, 0x41, 0x63, 0x74, 0x69, 0x76, 0x65, 0x45, 0x67, 0x72,
0x65, 0x73, 0x73, 0x12, 0x1c, 0x2e, 0x72, 0x70, 0x63, 0x2e, 0x4c, 0x69, 0x73, 0x74, 0x41, 0x63,
0x74, 0x69, 0x76, 0x65, 0x45, 0x67, 0x72, 0x65, 0x73, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73,
0x74, 0x1a, 0x1d, 0x2e, 0x72, 0x70, 0x63, 0x2e, 0x4c, 0x69, 0x73, 0x74, 0x41, 0x63, 0x74, 0x69,
0x76, 0x65, 0x45, 0x67, 0x72, 0x65, 0x73, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65,
0x22, 0x06, 0xb2, 0x89, 0x01, 0x02, 0x08, 0x01, 0x32, 0xd8, 0x01, 0x0a, 0x0d, 0x45, 0x67, 0x72,
0x65, 0x73, 0x73, 0x48, 0x61, 0x6e, 0x64, 0x6c, 0x65, 0x72, 0x12, 0x49, 0x0a, 0x0c, 0x55, 0x70,
0x64, 0x61, 0x74, 0x65, 0x53, 0x74, 0x72, 0x65, 0x61, 0x6d, 0x12, 0x1c, 0x2e, 0x6c, 0x69, 0x76,
0x65, 0x6b, 0x69, 0x74, 0x2e, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x53, 0x74, 0x72, 0x65, 0x61,
0x6d, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x13, 0x2e, 0x6c, 0x69, 0x76, 0x65, 0x6b,
0x69, 0x74, 0x2e, 0x45, 0x67, 0x72, 0x65, 0x73, 0x73, 0x49, 0x6e, 0x66, 0x6f, 0x22, 0x06, 0xb2,
0x89, 0x01, 0x02, 0x18, 0x01, 0x12, 0x45, 0x0a, 0x0a, 0x53, 0x74, 0x6f, 0x70, 0x45, 0x67, 0x72,
0x65, 0x73, 0x73, 0x12, 0x1a, 0x2e, 0x6c, 0x69, 0x76, 0x65, 0x6b, 0x69, 0x74, 0x2e, 0x53, 0x74,
0x6f, 0x70, 0x45, 0x67, 0x72, 0x65, 0x73, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a,
0x13, 0x2e, 0x6c, 0x69, 0x76, 0x65, 0x6b, 0x69, 0x74, 0x2e, 0x45, 0x67, 0x72, 0x65, 0x73, 0x73,
0x49, 0x6e, 0x66, 0x6f, 0x22, 0x06, 0xb2, 0x89, 0x01, 0x02, 0x18, 0x01, 0x12, 0x35, 0x0a, 0x0a,
0x49, 0x6e, 0x66, 0x6f, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x12, 0x0a, 0x2e, 0x72, 0x70, 0x63,
0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x1a, 0x13, 0x2e, 0x6c, 0x69, 0x76, 0x65, 0x6b, 0x69, 0x74,
0x2e, 0x45, 0x67, 0x72, 0x65, 0x73, 0x73, 0x49, 0x6e, 0x66, 0x6f, 0x22, 0x06, 0xb2, 0x89, 0x01,
0x02, 0x10, 0x01, 0x42, 0x2c, 0x5a, 0x2a, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f,
0x6d, 0x2f, 0x6c, 0x69, 0x76, 0x65, 0x6b, 0x69, 0x74, 0x2f, 0x6c, 0x69, 0x76, 0x65, 0x6b, 0x69,
0x74, 0x2f, 0x70, 0x6b, 0x67, 0x2f, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x2f, 0x72, 0x70,
0x63, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
}
var (
file_pkg_service_rpc_egress_proto_rawDescOnce sync.Once
file_pkg_service_rpc_egress_proto_rawDescData = file_pkg_service_rpc_egress_proto_rawDesc
)
func file_pkg_service_rpc_egress_proto_rawDescGZIP() []byte {
file_pkg_service_rpc_egress_proto_rawDescOnce.Do(func() {
file_pkg_service_rpc_egress_proto_rawDescData = protoimpl.X.CompressGZIP(file_pkg_service_rpc_egress_proto_rawDescData)
})
return file_pkg_service_rpc_egress_proto_rawDescData
}
var file_pkg_service_rpc_egress_proto_msgTypes = make([]protoimpl.MessageInfo, 3)
var file_pkg_service_rpc_egress_proto_goTypes = []interface{}{
(*Empty)(nil), // 0: rpc.Empty
(*ListActiveEgressRequest)(nil), // 1: rpc.ListActiveEgressRequest
(*ListActiveEgressResponse)(nil), // 2: rpc.ListActiveEgressResponse
(*livekit.StartEgressRequest)(nil), // 3: livekit.StartEgressRequest
(*livekit.UpdateStreamRequest)(nil), // 4: livekit.UpdateStreamRequest
(*livekit.StopEgressRequest)(nil), // 5: livekit.StopEgressRequest
(*livekit.EgressInfo)(nil), // 6: livekit.EgressInfo
}
var file_pkg_service_rpc_egress_proto_depIdxs = []int32{
3, // 0: rpc.EgressInternal.StartEgress:input_type -> livekit.StartEgressRequest
1, // 1: rpc.EgressInternal.ListActiveEgress:input_type -> rpc.ListActiveEgressRequest
4, // 2: rpc.EgressHandler.UpdateStream:input_type -> livekit.UpdateStreamRequest
5, // 3: rpc.EgressHandler.StopEgress:input_type -> livekit.StopEgressRequest
0, // 4: rpc.EgressHandler.InfoUpdate:input_type -> rpc.Empty
6, // 5: rpc.EgressInternal.StartEgress:output_type -> livekit.EgressInfo
2, // 6: rpc.EgressInternal.ListActiveEgress:output_type -> rpc.ListActiveEgressResponse
6, // 7: rpc.EgressHandler.UpdateStream:output_type -> livekit.EgressInfo
6, // 8: rpc.EgressHandler.StopEgress:output_type -> livekit.EgressInfo
6, // 9: rpc.EgressHandler.InfoUpdate:output_type -> livekit.EgressInfo
5, // [5:10] is the sub-list for method output_type
0, // [0:5] is the sub-list for method input_type
0, // [0:0] is the sub-list for extension type_name
0, // [0:0] is the sub-list for extension extendee
0, // [0:0] is the sub-list for field type_name
}
func init() { file_pkg_service_rpc_egress_proto_init() }
func file_pkg_service_rpc_egress_proto_init() {
if File_pkg_service_rpc_egress_proto != nil {
return
}
if !protoimpl.UnsafeEnabled {
file_pkg_service_rpc_egress_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*Empty); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
file_pkg_service_rpc_egress_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*ListActiveEgressRequest); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
file_pkg_service_rpc_egress_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*ListActiveEgressResponse); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
}
type x struct{}
out := protoimpl.TypeBuilder{
File: protoimpl.DescBuilder{
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_pkg_service_rpc_egress_proto_rawDesc,
NumEnums: 0,
NumMessages: 3,
NumExtensions: 0,
NumServices: 2,
},
GoTypes: file_pkg_service_rpc_egress_proto_goTypes,
DependencyIndexes: file_pkg_service_rpc_egress_proto_depIdxs,
MessageInfos: file_pkg_service_rpc_egress_proto_msgTypes,
}.Build()
File_pkg_service_rpc_egress_proto = out.File
file_pkg_service_rpc_egress_proto_rawDesc = nil
file_pkg_service_rpc_egress_proto_goTypes = nil
file_pkg_service_rpc_egress_proto_depIdxs = nil
}
+38
View File
@@ -0,0 +1,38 @@
syntax = "proto3";
package rpc;
option go_package = "github.com/livekit/livekit/pkg/service/rpc";
import "options.proto";
import "livekit_rpc_internal.proto";
import "livekit_egress.proto";
service EgressInternal {
rpc StartEgress(livekit.StartEgressRequest) returns (livekit.EgressInfo) {
option (psrpc.options).affinity_func = true;
};
rpc ListActiveEgress(ListActiveEgressRequest) returns (ListActiveEgressResponse) {
option (psrpc.options).multi = true;
}
}
service EgressHandler {
rpc UpdateStream(livekit.UpdateStreamRequest) returns (livekit.EgressInfo) {
option (psrpc.options).topics = true;
}
rpc StopEgress(livekit.StopEgressRequest) returns (livekit.EgressInfo) {
option (psrpc.options).topics = true;
}
rpc InfoUpdate(Empty) returns (livekit.EgressInfo) {
option (psrpc.options).subscription = true;
}
}
message Empty {}
message ListActiveEgressRequest {}
message ListActiveEgressResponse {
repeated string egress_ids = 1;
}
+232
View File
@@ -0,0 +1,232 @@
// Code generated by protoc-gen-psrpc v0.1.0, DO NOT EDIT.
// source: pkg/service/rpc/egress.proto
package rpc
import context "context"
import psrpc1 "github.com/livekit/psrpc"
import livekit "github.com/livekit/protocol/livekit"
import livekit3 "github.com/livekit/protocol/livekit"
// ===============================
// EgressInternal Client Interface
// ===============================
type EgressInternalClient interface {
StartEgress(context.Context, *livekit3.StartEgressRequest, ...psrpc1.RequestOpt) (*livekit.EgressInfo, error)
ListActiveEgress(context.Context, *ListActiveEgressRequest, ...psrpc1.RequestOpt) (<-chan *psrpc1.Response[*ListActiveEgressResponse], error)
}
// ===================================
// EgressInternal ServerImpl Interface
// ===================================
type EgressInternalServerImpl interface {
StartEgress(context.Context, *livekit3.StartEgressRequest) (*livekit.EgressInfo, error)
StartEgressAffinity(*livekit3.StartEgressRequest) float32
ListActiveEgress(context.Context, *ListActiveEgressRequest) (*ListActiveEgressResponse, error)
}
// ===============================
// EgressInternal Server Interface
// ===============================
type EgressInternalServer interface {
}
// =====================
// EgressInternal Client
// =====================
type egressInternalClient struct {
client psrpc1.RPCClient
}
// NewEgressInternalClient creates a psrpc client that implements the EgressInternalClient interface.
func NewEgressInternalClient(clientID string, bus psrpc1.MessageBus, opts ...psrpc1.ClientOpt) (EgressInternalClient, error) {
rpcClient, err := psrpc1.NewRPCClient("EgressInternal", clientID, bus, opts...)
if err != nil {
return nil, err
}
return &egressInternalClient{
client: rpcClient,
}, nil
}
func (c *egressInternalClient) StartEgress(ctx context.Context, req *livekit3.StartEgressRequest, opts ...psrpc1.RequestOpt) (*livekit.EgressInfo, error) {
return psrpc1.RequestTopicSingle[*livekit.EgressInfo](ctx, c.client, "StartEgress", "", req, opts...)
}
func (c *egressInternalClient) ListActiveEgress(ctx context.Context, req *ListActiveEgressRequest, opts ...psrpc1.RequestOpt) (<-chan *psrpc1.Response[*ListActiveEgressResponse], error) {
return psrpc1.RequestTopicAll[*ListActiveEgressResponse](ctx, c.client, "ListActiveEgress", "", req, opts...)
}
// =====================
// EgressInternal Server
// =====================
type egressInternalServer struct {
svc EgressInternalServerImpl
rpc psrpc1.RPCServer
}
// NewEgressInternalServer builds a RPCServer that can be used to handle
// requests that are routed to the right method in the provided svc implementation.
func NewEgressInternalServer(serverID string, svc EgressInternalServerImpl, bus psrpc1.MessageBus, opts ...psrpc1.ServerOpt) (EgressInternalServer, error) {
rpcServer := psrpc1.NewRPCServer("EgressInternal", serverID, bus, opts...)
var err error
err = rpcServer.RegisterHandler(psrpc1.NewHandlerWithAffinity("StartEgress", svc.StartEgress, svc.StartEgressAffinity))
if err != nil {
rpcServer.Close()
return nil, err
}
err = rpcServer.RegisterHandler(psrpc1.NewHandler("ListActiveEgress", svc.ListActiveEgress))
if err != nil {
rpcServer.Close()
return nil, err
}
return &egressInternalServer{
svc: svc,
rpc: rpcServer,
}, nil
}
// ==============================
// EgressHandler Client Interface
// ==============================
type EgressHandlerClient interface {
UpdateStream(context.Context, string, *livekit.UpdateStreamRequest, ...psrpc1.RequestOpt) (*livekit.EgressInfo, error)
StopEgress(context.Context, string, *livekit.StopEgressRequest, ...psrpc1.RequestOpt) (*livekit.EgressInfo, error)
SubscribeInfoUpdate(context.Context) (psrpc1.Subscription[*livekit.EgressInfo], error)
}
// ==================================
// EgressHandler ServerImpl Interface
// ==================================
type EgressHandlerServerImpl interface {
UpdateStream(context.Context, *livekit.UpdateStreamRequest) (*livekit.EgressInfo, error)
StopEgress(context.Context, *livekit.StopEgressRequest) (*livekit.EgressInfo, error)
}
// ==============================
// EgressHandler Server Interface
// ==============================
type EgressHandlerServer interface {
RegisterUpdateStreamTopic(string) error
DeregisterUpdateStreamTopic(string) error
RegisterStopEgressTopic(string) error
DeregisterStopEgressTopic(string) error
PublishInfoUpdate(context.Context, *livekit.EgressInfo) error
}
// ====================
// EgressHandler Client
// ====================
type egressHandlerClient struct {
client psrpc1.RPCClient
}
// NewEgressHandlerClient creates a psrpc client that implements the EgressHandlerClient interface.
func NewEgressHandlerClient(clientID string, bus psrpc1.MessageBus, opts ...psrpc1.ClientOpt) (EgressHandlerClient, error) {
rpcClient, err := psrpc1.NewRPCClient("EgressHandler", clientID, bus, opts...)
if err != nil {
return nil, err
}
return &egressHandlerClient{
client: rpcClient,
}, nil
}
func (c *egressHandlerClient) UpdateStream(ctx context.Context, topic string, req *livekit.UpdateStreamRequest, opts ...psrpc1.RequestOpt) (*livekit.EgressInfo, error) {
return psrpc1.RequestTopicSingle[*livekit.EgressInfo](ctx, c.client, "UpdateStream", topic, req, opts...)
}
func (c *egressHandlerClient) StopEgress(ctx context.Context, topic string, req *livekit.StopEgressRequest, opts ...psrpc1.RequestOpt) (*livekit.EgressInfo, error) {
return psrpc1.RequestTopicSingle[*livekit.EgressInfo](ctx, c.client, "StopEgress", topic, req, opts...)
}
func (c *egressHandlerClient) SubscribeInfoUpdate(ctx context.Context) (psrpc1.Subscription[*livekit.EgressInfo], error) {
return psrpc1.SubscribeTopicQueue[*livekit.EgressInfo](ctx, c.client, "InfoUpdate", "")
}
// ====================
// EgressHandler Server
// ====================
type egressHandlerServer struct {
svc EgressHandlerServerImpl
rpc psrpc1.RPCServer
}
// NewEgressHandlerServer builds a RPCServer that can be used to handle
// requests that are routed to the right method in the provided svc implementation.
func NewEgressHandlerServer(serverID string, svc EgressHandlerServerImpl, bus psrpc1.MessageBus, opts ...psrpc1.ServerOpt) (EgressHandlerServer, error) {
rpcServer := psrpc1.NewRPCServer("EgressHandler", serverID, bus, opts...)
return &egressHandlerServer{
svc: svc,
rpc: rpcServer,
}, nil
}
func (s *egressHandlerServer) RegisterUpdateStreamTopic(topic string) error {
return s.rpc.RegisterHandler(psrpc1.NewTopicHandler("UpdateStream", topic, s.svc.UpdateStream))
}
func (s *egressHandlerServer) DeregisterUpdateStreamTopic(topic string) error {
return s.rpc.DeregisterTopic("UpdateStream", topic)
}
func (s *egressHandlerServer) RegisterStopEgressTopic(topic string) error {
return s.rpc.RegisterHandler(psrpc1.NewTopicHandler("StopEgress", topic, s.svc.StopEgress))
}
func (s *egressHandlerServer) DeregisterStopEgressTopic(topic string) error {
return s.rpc.DeregisterTopic("StopEgress", topic)
}
func (s *egressHandlerServer) PublishInfoUpdate(ctx context.Context, msg *livekit.EgressInfo) error {
return s.rpc.PublishTopic(ctx, "InfoUpdate", "", msg)
}
var psrpcFileDescriptor0 = []byte{
// 329 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x52, 0xd1, 0x4a, 0x02, 0x41,
0x14, 0x65, 0x92, 0x2c, 0x6f, 0x19, 0x32, 0x05, 0xd9, 0xa6, 0x20, 0xfb, 0x14, 0x11, 0xbb, 0x60,
0xf4, 0xd0, 0x63, 0x81, 0x94, 0xd0, 0x93, 0x12, 0x41, 0x2f, 0xb2, 0xce, 0xde, 0x6c, 0x50, 0x77,
0xa6, 0x99, 0xab, 0xd0, 0x27, 0xf4, 0x3b, 0x7e, 0x4d, 0x9f, 0x13, 0xed, 0x8c, 0xb2, 0x18, 0x56,
0x4f, 0xc3, 0x9c, 0x73, 0xef, 0xb9, 0xe7, 0x70, 0x2f, 0x34, 0xf4, 0x78, 0x14, 0x5b, 0x34, 0x73,
0x29, 0x30, 0x36, 0x5a, 0xc4, 0x38, 0x32, 0x68, 0x6d, 0xa4, 0x8d, 0x22, 0xc5, 0x4b, 0x46, 0x8b,
0xa0, 0xaa, 0x34, 0x49, 0x95, 0x79, 0x2c, 0x08, 0x26, 0x72, 0x8e, 0x63, 0x49, 0x03, 0xa3, 0xc5,
0x40, 0x66, 0x84, 0x26, 0x4b, 0x26, 0x9e, 0x3b, 0x5a, 0x72, 0x45, 0x95, 0x70, 0x07, 0xb6, 0x3b,
0x53, 0x4d, 0xef, 0xe1, 0x09, 0x1c, 0x3f, 0x48, 0x4b, 0x37, 0x82, 0xe4, 0x1c, 0x3b, 0x79, 0x49,
0x0f, 0xdf, 0x66, 0x68, 0x29, 0xbc, 0x86, 0xfa, 0x4f, 0xca, 0x6a, 0x95, 0x59, 0xe4, 0x4d, 0x00,
0xa7, 0x37, 0x90, 0xa9, 0xad, 0xb3, 0x56, 0xe9, 0xac, 0xd2, 0xab, 0x38, 0xa4, 0x9b, 0xda, 0xf6,
0x82, 0xc1, 0x81, 0xeb, 0xe8, 0x7a, 0x37, 0xfc, 0x0e, 0xf6, 0xfa, 0x94, 0x18, 0x72, 0x30, 0x3f,
0x8d, 0xbc, 0xaf, 0xa8, 0x80, 0xfa, 0xc9, 0xc1, 0xe1, 0x8a, 0x5c, 0x8a, 0xbc, 0xa8, 0xb0, 0xbc,
0xf8, 0x60, 0x5b, 0x2d, 0xc6, 0x9f, 0xa0, 0xb6, 0x6e, 0x8b, 0x37, 0x22, 0xa3, 0x45, 0xb4, 0x21,
0x48, 0xd0, 0xdc, 0xc0, 0xba, 0x2c, 0x4e, 0x78, 0x97, 0xb5, 0x3f, 0x19, 0x54, 0x1d, 0x75, 0x9f,
0x64, 0xe9, 0x04, 0x0d, 0xef, 0xc2, 0xfe, 0xa3, 0x4e, 0x13, 0xc2, 0x3e, 0x19, 0x4c, 0xa6, 0xbc,
0xb1, 0xf2, 0x55, 0x84, 0xff, 0x76, 0x5d, 0x67, 0xbc, 0x03, 0xd0, 0x27, 0xa5, 0xbd, 0xdf, 0xa0,
0x90, 0x7e, 0x09, 0xfe, 0x4b, 0xe6, 0x0a, 0xe0, 0xfb, 0xef, 0xc6, 0x73, 0xc8, 0x83, 0xe5, 0x8b,
0xfc, 0xa5, 0xad, 0xc6, 0x6e, 0x2f, 0x9e, 0xcf, 0x47, 0x92, 0x5e, 0x67, 0xc3, 0x48, 0xa8, 0x69,
0xec, 0x0b, 0x57, 0xef, 0xda, 0xbd, 0x0d, 0xcb, 0xf9, 0x8d, 0x5c, 0x7e, 0x05, 0x00, 0x00, 0xff,
0xff, 0x26, 0x11, 0xba, 0xff, 0x89, 0x02, 0x00, 0x00,
}
+36
View File
@@ -0,0 +1,36 @@
package rpc
import (
"github.com/livekit/protocol/livekit"
"github.com/livekit/psrpc"
)
type EgressClient interface {
EgressInternalClient
EgressHandlerClient
}
type egressClient struct {
EgressInternalClient
EgressHandlerClient
}
func NewEgressClient(nodeID livekit.NodeID, bus psrpc.MessageBus) (EgressClient, error) {
if bus == nil {
return nil, nil
}
clientID := string(nodeID)
internalClient, err := NewEgressInternalClient(clientID, bus)
if err != nil {
return nil, err
}
handlerClient, err := NewEgressHandlerClient(clientID, bus)
if err != nil {
return nil, err
}
return &egressClient{
EgressInternalClient: internalClient,
EgressHandlerClient: handlerClient,
}, nil
}