github.com/livekit/protocol@v1.16.1-0.20240517185851-47e4c6bba773/rpc/signal.psrpc.go (about)

     1  // Code generated by protoc-gen-psrpc v0.5.1, DO NOT EDIT.
     2  // source: rpc/signal.proto
     3  
     4  package rpc
     5  
     6  import (
     7  	"context"
     8  
     9  	"github.com/livekit/psrpc"
    10  	"github.com/livekit/psrpc/pkg/client"
    11  	"github.com/livekit/psrpc/pkg/info"
    12  	"github.com/livekit/psrpc/pkg/rand"
    13  	"github.com/livekit/psrpc/pkg/server"
    14  	"github.com/livekit/psrpc/version"
    15  )
    16  
    17  var _ = version.PsrpcVersion_0_5
    18  
    19  // =======================
    20  // Signal Client Interface
    21  // =======================
    22  
    23  type SignalClient[NodeIdTopicType ~string] interface {
    24  	RelaySignal(ctx context.Context, nodeId NodeIdTopicType, opts ...psrpc.RequestOption) (psrpc.ClientStream[*RelaySignalRequest, *RelaySignalResponse], error)
    25  }
    26  
    27  // ===========================
    28  // Signal ServerImpl Interface
    29  // ===========================
    30  
    31  type SignalServerImpl interface {
    32  	RelaySignal(psrpc.ServerStream[*RelaySignalResponse, *RelaySignalRequest]) error
    33  }
    34  
    35  // =======================
    36  // Signal Server Interface
    37  // =======================
    38  
    39  type SignalServer[NodeIdTopicType ~string] interface {
    40  	RegisterRelaySignalTopic(nodeId NodeIdTopicType) error
    41  	DeregisterRelaySignalTopic(nodeId NodeIdTopicType)
    42  
    43  	// Close and wait for pending RPCs to complete
    44  	Shutdown()
    45  
    46  	// Close immediately, without waiting for pending RPCs
    47  	Kill()
    48  }
    49  
    50  // =============
    51  // Signal Client
    52  // =============
    53  
    54  type signalClient[NodeIdTopicType ~string] struct {
    55  	client *client.RPCClient
    56  }
    57  
    58  // NewSignalClient creates a psrpc client that implements the SignalClient interface.
    59  func NewSignalClient[NodeIdTopicType ~string](bus psrpc.MessageBus, opts ...psrpc.ClientOption) (SignalClient[NodeIdTopicType], error) {
    60  	sd := &info.ServiceDefinition{
    61  		Name: "Signal",
    62  		ID:   rand.NewClientID(),
    63  	}
    64  
    65  	sd.RegisterMethod("RelaySignal", false, false, false, true)
    66  
    67  	rpcClient, err := client.NewRPCClientWithStreams(sd, bus, opts...)
    68  	if err != nil {
    69  		return nil, err
    70  	}
    71  
    72  	return &signalClient[NodeIdTopicType]{
    73  		client: rpcClient,
    74  	}, nil
    75  }
    76  
    77  func (c *signalClient[NodeIdTopicType]) RelaySignal(ctx context.Context, nodeId NodeIdTopicType, opts ...psrpc.RequestOption) (psrpc.ClientStream[*RelaySignalRequest, *RelaySignalResponse], error) {
    78  	return client.OpenStream[*RelaySignalRequest, *RelaySignalResponse](ctx, c.client, "RelaySignal", []string{string(nodeId)}, opts...)
    79  }
    80  
    81  // =============
    82  // Signal Server
    83  // =============
    84  
    85  type signalServer[NodeIdTopicType ~string] struct {
    86  	svc SignalServerImpl
    87  	rpc *server.RPCServer
    88  }
    89  
    90  // NewSignalServer builds a RPCServer that will route requests
    91  // to the corresponding method in the provided svc implementation.
    92  func NewSignalServer[NodeIdTopicType ~string](svc SignalServerImpl, bus psrpc.MessageBus, opts ...psrpc.ServerOption) (SignalServer[NodeIdTopicType], error) {
    93  	sd := &info.ServiceDefinition{
    94  		Name: "Signal",
    95  		ID:   rand.NewServerID(),
    96  	}
    97  
    98  	s := server.NewRPCServer(sd, bus, opts...)
    99  
   100  	sd.RegisterMethod("RelaySignal", false, false, false, true)
   101  	return &signalServer[NodeIdTopicType]{
   102  		svc: svc,
   103  		rpc: s,
   104  	}, nil
   105  }
   106  
   107  func (s *signalServer[NodeIdTopicType]) RegisterRelaySignalTopic(nodeId NodeIdTopicType) error {
   108  	return server.RegisterStreamHandler(s.rpc, "RelaySignal", []string{string(nodeId)}, s.svc.RelaySignal, nil)
   109  }
   110  
   111  func (s *signalServer[NodeIdTopicType]) DeregisterRelaySignalTopic(nodeId NodeIdTopicType) {
   112  	s.rpc.DeregisterHandler("RelaySignal", []string{string(nodeId)})
   113  }
   114  
   115  func (s *signalServer[NodeIdTopicType]) Shutdown() {
   116  	s.rpc.Close(false)
   117  }
   118  
   119  func (s *signalServer[NodeIdTopicType]) Kill() {
   120  	s.rpc.Close(true)
   121  }
   122  
   123  var psrpcFileDescriptor7 = []byte{
   124  	// 307 bytes of a gzipped FileDescriptorProto
   125  	0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x6c, 0x91, 0xb1, 0x4e, 0xc3, 0x30,
   126  	0x10, 0x86, 0x65, 0xd2, 0x96, 0xe2, 0x52, 0xa9, 0xb8, 0xd0, 0x5a, 0x59, 0x08, 0x9d, 0x32, 0x39,
   127  	0x52, 0x10, 0x0b, 0x23, 0x8f, 0xe0, 0x4e, 0xb0, 0x54, 0xa9, 0x6b, 0x15, 0x8b, 0x60, 0xbb, 0x3e,
   128  	0x17, 0x89, 0x47, 0xe0, 0x5d, 0x98, 0x78, 0x42, 0x94, 0x38, 0x6d, 0x83, 0xc2, 0x76, 0x77, 0xff,
   129  	0xef, 0xff, 0x3b, 0x9d, 0xf1, 0xc4, 0x59, 0x91, 0x81, 0xda, 0xea, 0xa2, 0x64, 0xd6, 0x19, 0x6f,
   130  	0x48, 0xe4, 0xac, 0x88, 0xc7, 0xc6, 0x7a, 0x65, 0x34, 0x84, 0x59, 0x3c, 0x2b, 0xd5, 0x87, 0x7c,
   131  	0x53, 0x7e, 0xa5, 0xb4, 0x97, 0xee, 0xe8, 0x8d, 0xaf, 0x0e, 0x73, 0xe7, 0x45, 0x18, 0x2d, 0xbe,
   132  	0x11, 0x26, 0x5c, 0x96, 0xc5, 0xe7, 0xb2, 0x0e, 0xe5, 0x72, 0xb7, 0x97, 0xe0, 0xc9, 0x23, 0x1e,
   133  	0x83, 0x2f, 0x9c, 0x5f, 0x81, 0x04, 0x50, 0x46, 0x53, 0x94, 0xa0, 0x74, 0x94, 0xdf, 0xb0, 0x26,
   134  	0x81, 0x2d, 0x2b, 0x75, 0x19, 0x44, 0x7e, 0x09, 0xad, 0x8e, 0xe4, 0x78, 0xe8, 0x42, 0x0c, 0xd0,
   135  	0x28, 0x89, 0xd2, 0x51, 0x3e, 0x3b, 0x3d, 0x6b, 0x53, 0xf8, 0xd1, 0x47, 0x26, 0x38, 0x02, 0xb9,
   136  	0xa3, 0xbd, 0x04, 0xa5, 0x3d, 0x5e, 0x95, 0xe4, 0x1a, 0xf7, 0x45, 0x69, 0x40, 0xd2, 0x7e, 0x82,
   137  	0xd2, 0x21, 0x0f, 0xcd, 0xc2, 0xe3, 0xe9, 0x9f, 0x6d, 0xc1, 0x1a, 0x0d, 0x92, 0x3c, 0xe0, 0x0b,
   138  	0xd7, 0xd4, 0x40, 0xcf, 0x6a, 0xe6, 0xbc, 0xc3, 0x0c, 0x3a, 0x3f, 0x39, 0x0f, 0xd4, 0xe8, 0x1f,
   139  	0x6a, 0xaf, 0x45, 0xcd, 0x05, 0x1e, 0x84, 0x10, 0xf2, 0x8c, 0x47, 0x2d, 0x3e, 0x99, 0x33, 0x67,
   140  	0x05, 0xeb, 0xde, 0x2f, 0xa6, 0x5d, 0x21, 0x40, 0x17, 0xf3, 0x9f, 0x2f, 0x34, 0x9d, 0xa0, 0x78,
   141  	0x4c, 0xce, 0xb5, 0xd9, 0xc8, 0x95, 0xda, 0x54, 0xb7, 0x4d, 0xd0, 0xd3, 0xdd, 0xcb, 0xed, 0x56,
   142  	0xf9, 0xd7, 0xfd, 0x9a, 0x09, 0xf3, 0x9e, 0x35, 0xcb, 0x67, 0xf5, 0x2f, 0x09, 0x53, 0x66, 0xce,
   143  	0x8a, 0xf5, 0xa0, 0xee, 0xee, 0x7f, 0x03, 0x00, 0x00, 0xff, 0xff, 0x18, 0x2b, 0x54, 0xdb, 0x06,
   144  	0x02, 0x00, 0x00,
   145  }