github.com/whoyao/protocol@v0.0.0-20230519045905-2d8ace718ca5/rpc/signal.psrpc.go (about)

     1  // Code generated by protoc-gen-psrpc v0.3.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/server"
    13  	"github.com/livekit/psrpc/version"
    14  )
    15  
    16  var _ = version.PsrpcVersion_0_3_0
    17  
    18  // =======================
    19  // Signal Client Interface
    20  // =======================
    21  
    22  type SignalClient[NodeIdTopicType ~string] interface {
    23  	RelaySignal(ctx context.Context, nodeId NodeIdTopicType, opts ...psrpc.RequestOption) (psrpc.ClientStream[*RelaySignalRequest, *RelaySignalResponse], error)
    24  }
    25  
    26  // ===========================
    27  // Signal ServerImpl Interface
    28  // ===========================
    29  
    30  type SignalServerImpl interface {
    31  	RelaySignal(psrpc.ServerStream[*RelaySignalResponse, *RelaySignalRequest]) error
    32  }
    33  
    34  // =======================
    35  // Signal Server Interface
    36  // =======================
    37  
    38  type SignalServer[NodeIdTopicType ~string] interface {
    39  	RegisterRelaySignalTopic(nodeId NodeIdTopicType) error
    40  	DeregisterRelaySignalTopic(nodeId NodeIdTopicType)
    41  
    42  	// Close and wait for pending RPCs to complete
    43  	Shutdown()
    44  
    45  	// Close immediately, without waiting for pending RPCs
    46  	Kill()
    47  }
    48  
    49  // =============
    50  // Signal Client
    51  // =============
    52  
    53  type signalClient[NodeIdTopicType ~string] struct {
    54  	client *client.RPCClient
    55  }
    56  
    57  // NewSignalClient creates a psrpc client that implements the SignalClient interface.
    58  func NewSignalClient[NodeIdTopicType ~string](clientID string, bus psrpc.MessageBus, opts ...psrpc.ClientOption) (SignalClient[NodeIdTopicType], error) {
    59  	sd := &info.ServiceDefinition{
    60  		Name: "Signal",
    61  		ID:   clientID,
    62  	}
    63  
    64  	sd.RegisterMethod("RelaySignal", false, false, false)
    65  
    66  	rpcClient, err := client.NewRPCClientWithStreams(sd, bus, opts...)
    67  	if err != nil {
    68  		return nil, err
    69  	}
    70  
    71  	return &signalClient[NodeIdTopicType]{
    72  		client: rpcClient,
    73  	}, nil
    74  }
    75  
    76  func (c *signalClient[NodeIdTopicType]) RelaySignal(ctx context.Context, nodeId NodeIdTopicType, opts ...psrpc.RequestOption) (psrpc.ClientStream[*RelaySignalRequest, *RelaySignalResponse], error) {
    77  	return client.OpenStream[*RelaySignalRequest, *RelaySignalResponse](ctx, c.client, "RelaySignal", []string{string(nodeId)}, opts...)
    78  }
    79  
    80  // =============
    81  // Signal Server
    82  // =============
    83  
    84  type signalServer[NodeIdTopicType ~string] struct {
    85  	svc SignalServerImpl
    86  	rpc *server.RPCServer
    87  }
    88  
    89  // NewSignalServer builds a RPCServer that will route requests
    90  // to the corresponding method in the provided svc implementation.
    91  func NewSignalServer[NodeIdTopicType ~string](serverID string, svc SignalServerImpl, bus psrpc.MessageBus, opts ...psrpc.ServerOption) (SignalServer[NodeIdTopicType], error) {
    92  	sd := &info.ServiceDefinition{
    93  		Name: "Signal",
    94  		ID:   serverID,
    95  	}
    96  
    97  	s := server.NewRPCServer(sd, bus, opts...)
    98  
    99  	sd.RegisterMethod("RelaySignal", false, false, false)
   100  	return &signalServer[NodeIdTopicType]{
   101  		svc: svc,
   102  		rpc: s,
   103  	}, nil
   104  }
   105  
   106  func (s *signalServer[NodeIdTopicType]) RegisterRelaySignalTopic(nodeId NodeIdTopicType) error {
   107  	return server.RegisterStreamHandler(s.rpc, "RelaySignal", []string{string(nodeId)}, s.svc.RelaySignal, nil)
   108  }
   109  
   110  func (s *signalServer[NodeIdTopicType]) DeregisterRelaySignalTopic(nodeId NodeIdTopicType) {
   111  	s.rpc.DeregisterHandler("RelaySignal", []string{string(nodeId)})
   112  }
   113  
   114  func (s *signalServer[NodeIdTopicType]) Shutdown() {
   115  	s.rpc.Close(false)
   116  }
   117  
   118  func (s *signalServer[NodeIdTopicType]) Kill() {
   119  	s.rpc.Close(true)
   120  }
   121  
   122  var psrpcFileDescriptor3 = []byte{
   123  	// 315 bytes of a gzipped FileDescriptorProto
   124  	0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x6c, 0x91, 0x4f, 0x4e, 0xf3, 0x30,
   125  	0x10, 0xc5, 0xe5, 0x2f, 0x6d, 0xbf, 0xe2, 0x52, 0xa9, 0xb8, 0xd0, 0x5a, 0x59, 0x45, 0x59, 0x45,
   126  	0x08, 0x25, 0x28, 0x88, 0x0d, 0x4b, 0x8e, 0xe0, 0xae, 0x60, 0x53, 0xb5, 0xee, 0xa8, 0x58, 0x0d,
   127  	0xb6, 0xeb, 0x71, 0x2b, 0x71, 0x04, 0xee, 0xc2, 0x8a, 0x13, 0xa2, 0xd6, 0xfd, 0x13, 0x14, 0x56,
   128  	0x99, 0x99, 0xf7, 0xf2, 0x7e, 0xa3, 0x31, 0x1d, 0x38, 0x2b, 0x0b, 0x54, 0x4b, 0x3d, 0xab, 0x72,
   129  	0xeb, 0x8c, 0x37, 0x2c, 0x72, 0x56, 0xc6, 0x7d, 0x63, 0xbd, 0x32, 0x1a, 0xc3, 0x2c, 0x1e, 0x55,
   130  	0x6a, 0x0b, 0x2b, 0xe5, 0xa7, 0x4a, 0x7b, 0x70, 0x27, 0x6f, 0x7c, 0x75, 0x9c, 0x3b, 0x2f, 0xc3,
   131  	0x28, 0xfd, 0x22, 0x94, 0x09, 0xa8, 0x66, 0x1f, 0x93, 0x7d, 0xa8, 0x80, 0xf5, 0x06, 0xd0, 0xb3,
   132  	0x27, 0xda, 0x47, 0x3f, 0x73, 0x7e, 0x8a, 0x80, 0xa8, 0x8c, 0xe6, 0x24, 0x21, 0x59, 0xaf, 0xbc,
   133  	0xc9, 0x0f, 0x09, 0xf9, 0x64, 0xa7, 0x4e, 0x82, 0x28, 0x2e, 0xb1, 0xd6, 0xb1, 0x92, 0x76, 0x5d,
   134  	0x88, 0x41, 0x1e, 0x25, 0x51, 0xd6, 0x2b, 0x47, 0xe7, 0xdf, 0xea, 0x14, 0x71, 0xf2, 0xb1, 0x01,
   135  	0x8d, 0x10, 0xd6, 0xbc, 0x95, 0x90, 0xac, 0x25, 0x76, 0x25, 0xbb, 0xa6, 0x6d, 0x59, 0x19, 0x04,
   136  	0xde, 0x4e, 0x48, 0xd6, 0x15, 0xa1, 0x49, 0x3d, 0x1d, 0xfe, 0xda, 0x16, 0xad, 0xd1, 0x08, 0xec,
   137  	0x91, 0x5e, 0xb8, 0x43, 0x8d, 0xfc, 0xdf, 0x9e, 0x39, 0x6e, 0x30, 0x83, 0x2e, 0xce, 0xce, 0x23,
   138  	0x35, 0xfa, 0x83, 0xda, 0xaa, 0x51, 0x4b, 0x49, 0x3b, 0x21, 0x84, 0xbd, 0xd0, 0x5e, 0x8d, 0xcf,
   139  	0xc6, 0xb9, 0xb3, 0x32, 0x6f, 0xde, 0x2f, 0xe6, 0x4d, 0x21, 0x40, 0xd3, 0xf1, 0xf7, 0x27, 0x19,
   140  	0x72, 0x92, 0xf6, 0xd9, 0x7f, 0x6d, 0x16, 0x30, 0x55, 0x8b, 0xdd, 0x6d, 0xef, 0xc9, 0xf3, 0xdd,
   141  	0xeb, 0xed, 0x52, 0xf9, 0xb7, 0xcd, 0x3c, 0x97, 0xe6, 0xbd, 0x38, 0x2c, 0x7f, 0xfa, 0xda, 0xd5,
   142  	0xb2, 0x40, 0x70, 0x5b, 0x25, 0xa1, 0x70, 0x56, 0xce, 0x3b, 0xfb, 0xe7, 0x7b, 0xf8, 0x09, 0x00,
   143  	0x00, 0xff, 0xff, 0x5b, 0x73, 0x86, 0x5c, 0x11, 0x02, 0x00, 0x00,
   144  }