github.com/livekit/protocol@v1.39.3/rpc/signal.psrpc.go (about)

     1  // Code generated by protoc-gen-psrpc v0.6.0, 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_6
    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  	// Close immediately, without waiting for pending RPCs
    27  	Close()
    28  }
    29  
    30  // ===========================
    31  // Signal ServerImpl Interface
    32  // ===========================
    33  
    34  type SignalServerImpl interface {
    35  	RelaySignal(psrpc.ServerStream[*RelaySignalResponse, *RelaySignalRequest]) error
    36  }
    37  
    38  // =======================
    39  // Signal Server Interface
    40  // =======================
    41  
    42  type SignalServer[NodeIdTopicType ~string] interface {
    43  	RegisterRelaySignalTopic(nodeId NodeIdTopicType) error
    44  	DeregisterRelaySignalTopic(nodeId NodeIdTopicType)
    45  	RegisterAllNodeTopics(nodeId NodeIdTopicType) error
    46  	DeregisterAllNodeTopics(nodeId NodeIdTopicType)
    47  
    48  	// Close and wait for pending RPCs to complete
    49  	Shutdown()
    50  
    51  	// Close immediately, without waiting for pending RPCs
    52  	Kill()
    53  }
    54  
    55  // =============
    56  // Signal Client
    57  // =============
    58  
    59  type signalClient[NodeIdTopicType ~string] struct {
    60  	client *client.RPCClient
    61  }
    62  
    63  // NewSignalClient creates a psrpc client that implements the SignalClient interface.
    64  func NewSignalClient[NodeIdTopicType ~string](bus psrpc.MessageBus, opts ...psrpc.ClientOption) (SignalClient[NodeIdTopicType], error) {
    65  	sd := &info.ServiceDefinition{
    66  		Name: "Signal",
    67  		ID:   rand.NewClientID(),
    68  	}
    69  
    70  	sd.RegisterMethod("RelaySignal", false, false, false, true)
    71  
    72  	rpcClient, err := client.NewRPCClientWithStreams(sd, bus, opts...)
    73  	if err != nil {
    74  		return nil, err
    75  	}
    76  
    77  	return &signalClient[NodeIdTopicType]{
    78  		client: rpcClient,
    79  	}, nil
    80  }
    81  
    82  func (c *signalClient[NodeIdTopicType]) RelaySignal(ctx context.Context, nodeId NodeIdTopicType, opts ...psrpc.RequestOption) (psrpc.ClientStream[*RelaySignalRequest, *RelaySignalResponse], error) {
    83  	return client.OpenStream[*RelaySignalRequest, *RelaySignalResponse](ctx, c.client, "RelaySignal", []string{string(nodeId)}, opts...)
    84  }
    85  
    86  func (s *signalClient[NodeIdTopicType]) Close() {
    87  	s.client.Close()
    88  }
    89  
    90  // =============
    91  // Signal Server
    92  // =============
    93  
    94  type signalServer[NodeIdTopicType ~string] struct {
    95  	svc SignalServerImpl
    96  	rpc *server.RPCServer
    97  }
    98  
    99  // NewSignalServer builds a RPCServer that will route requests
   100  // to the corresponding method in the provided svc implementation.
   101  func NewSignalServer[NodeIdTopicType ~string](svc SignalServerImpl, bus psrpc.MessageBus, opts ...psrpc.ServerOption) (SignalServer[NodeIdTopicType], error) {
   102  	sd := &info.ServiceDefinition{
   103  		Name: "Signal",
   104  		ID:   rand.NewServerID(),
   105  	}
   106  
   107  	s := server.NewRPCServer(sd, bus, opts...)
   108  
   109  	sd.RegisterMethod("RelaySignal", false, false, false, true)
   110  	return &signalServer[NodeIdTopicType]{
   111  		svc: svc,
   112  		rpc: s,
   113  	}, nil
   114  }
   115  
   116  func (s *signalServer[NodeIdTopicType]) RegisterRelaySignalTopic(nodeId NodeIdTopicType) error {
   117  	return server.RegisterStreamHandler(s.rpc, "RelaySignal", []string{string(nodeId)}, s.svc.RelaySignal, nil)
   118  }
   119  
   120  func (s *signalServer[NodeIdTopicType]) DeregisterRelaySignalTopic(nodeId NodeIdTopicType) {
   121  	s.rpc.DeregisterHandler("RelaySignal", []string{string(nodeId)})
   122  }
   123  
   124  func (s *signalServer[NodeIdTopicType]) allNodeTopicRegisterers() server.RegistererSlice {
   125  	return server.RegistererSlice{
   126  		server.NewRegisterer(s.RegisterRelaySignalTopic, s.DeregisterRelaySignalTopic),
   127  	}
   128  }
   129  
   130  func (s *signalServer[NodeIdTopicType]) RegisterAllNodeTopics(nodeId NodeIdTopicType) error {
   131  	return s.allNodeTopicRegisterers().Register(nodeId)
   132  }
   133  
   134  func (s *signalServer[NodeIdTopicType]) DeregisterAllNodeTopics(nodeId NodeIdTopicType) {
   135  	s.allNodeTopicRegisterers().Deregister(nodeId)
   136  }
   137  
   138  func (s *signalServer[NodeIdTopicType]) Shutdown() {
   139  	s.rpc.Close(false)
   140  }
   141  
   142  func (s *signalServer[NodeIdTopicType]) Kill() {
   143  	s.rpc.Close(true)
   144  }
   145  
   146  var psrpcFileDescriptor9 = []byte{
   147  	// 313 bytes of a gzipped FileDescriptorProto
   148  	0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x6c, 0x91, 0x4f, 0x4e, 0xf3, 0x30,
   149  	0x10, 0xc5, 0xe5, 0x2f, 0x69, 0xbf, 0xe2, 0x52, 0xa9, 0xb8, 0xd0, 0x9a, 0x48, 0x88, 0xd0, 0x55,
   150  	0x56, 0x8e, 0x14, 0xc4, 0x86, 0x25, 0x47, 0x70, 0x77, 0x6c, 0xa2, 0xd6, 0xb5, 0x8a, 0x45, 0xb0,
   151  	0x5d, 0x8f, 0x8b, 0xc4, 0x11, 0xb8, 0x0b, 0x2b, 0x4e, 0x88, 0x12, 0xf7, 0x4f, 0x50, 0xd8, 0x44,
   152  	0x33, 0xf3, 0x5e, 0xde, 0xcf, 0x1e, 0xe3, 0xb1, 0xb3, 0x22, 0x07, 0xb5, 0xd1, 0xcb, 0x8a, 0x59,
   153  	0x67, 0xbc, 0x21, 0x91, 0xb3, 0x22, 0x19, 0x19, 0xeb, 0x95, 0xd1, 0x10, 0x66, 0xc9, 0xb4, 0x52,
   154  	0xef, 0xf2, 0x55, 0xf9, 0x52, 0x69, 0x2f, 0xdd, 0xd1, 0x9b, 0x5c, 0x1c, 0xe6, 0xce, 0x8b, 0x30,
   155  	0x9a, 0x7f, 0x21, 0x4c, 0xb8, 0xac, 0x96, 0x1f, 0x8b, 0x26, 0x94, 0xcb, 0xed, 0x4e, 0x82, 0x27,
   156  	0x8f, 0x78, 0x04, 0x7e, 0xe9, 0x7c, 0x09, 0x12, 0x40, 0x19, 0x4d, 0x51, 0x8a, 0xb2, 0x61, 0x71,
   157  	0xc5, 0xf6, 0x09, 0x6c, 0x51, 0xab, 0x8b, 0x20, 0xf2, 0x73, 0x68, 0x75, 0xa4, 0xc0, 0x03, 0x17,
   158  	0x62, 0x80, 0x46, 0x69, 0x94, 0x0d, 0x8b, 0xe9, 0xe9, 0xb7, 0x36, 0x85, 0x1f, 0x7d, 0x64, 0x8c,
   159  	0x23, 0x90, 0x5b, 0x1a, 0xa7, 0x28, 0x8b, 0x79, 0x5d, 0x92, 0x4b, 0xdc, 0x13, 0x95, 0x01, 0x49,
   160  	0x7b, 0x29, 0xca, 0x06, 0x3c, 0x34, 0x73, 0x8f, 0x27, 0xbf, 0x4e, 0x0b, 0xd6, 0x68, 0x90, 0xe4,
   161  	0x01, 0x9f, 0xb9, 0x7d, 0x0d, 0xf4, 0x5f, 0xc3, 0x9c, 0x75, 0x98, 0x41, 0xe7, 0x27, 0xe7, 0x81,
   162  	0x1a, 0xfd, 0x41, 0x8d, 0x5b, 0xd4, 0x42, 0xe1, 0x7e, 0x08, 0x21, 0x25, 0x1e, 0xb6, 0xf8, 0x64,
   163  	0xc6, 0x9c, 0x15, 0xac, 0xbb, 0xbf, 0x84, 0x76, 0x85, 0x00, 0x9d, 0xdf, 0x7c, 0x7f, 0xa2, 0xeb,
   164  	0x31, 0x4a, 0x26, 0x38, 0xd6, 0x66, 0x2d, 0xc9, 0xff, 0xfa, 0x5b, 0xaa, 0x75, 0xbd, 0xe1, 0x14,
   165  	0x3d, 0xdd, 0x3d, 0xdf, 0x6e, 0x94, 0x7f, 0xd9, 0xad, 0x98, 0x30, 0x6f, 0xf9, 0xfe, 0x0a, 0x79,
   166  	0xf3, 0x56, 0xc2, 0x54, 0xb9, 0xb3, 0x62, 0xd5, 0x6f, 0xba, 0xfb, 0x9f, 0x00, 0x00, 0x00, 0xff,
   167  	0xff, 0xb2, 0x20, 0x3e, 0x1c, 0x0c, 0x02, 0x00, 0x00,
   168  }