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

     1  // Code generated by protoc-gen-psrpc v0.6.0, DO NOT EDIT.
     2  // source: rpc/room.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  import livekit1 "github.com/livekit/protocol/livekit"
    17  import livekit6 "github.com/livekit/protocol/livekit"
    18  
    19  var _ = version.PsrpcVersion_0_6
    20  
    21  // =====================
    22  // Room Client Interface
    23  // =====================
    24  
    25  type RoomClient[RoomTopicType ~string] interface {
    26  	DeleteRoom(ctx context.Context, room RoomTopicType, req *livekit6.DeleteRoomRequest, opts ...psrpc.RequestOption) (*livekit6.DeleteRoomResponse, error)
    27  
    28  	SendData(ctx context.Context, room RoomTopicType, req *livekit6.SendDataRequest, opts ...psrpc.RequestOption) (*livekit6.SendDataResponse, error)
    29  
    30  	UpdateRoomMetadata(ctx context.Context, room RoomTopicType, req *livekit6.UpdateRoomMetadataRequest, opts ...psrpc.RequestOption) (*livekit1.Room, error)
    31  
    32  	// Close immediately, without waiting for pending RPCs
    33  	Close()
    34  }
    35  
    36  // =========================
    37  // Room ServerImpl Interface
    38  // =========================
    39  
    40  type RoomServerImpl interface {
    41  	DeleteRoom(context.Context, *livekit6.DeleteRoomRequest) (*livekit6.DeleteRoomResponse, error)
    42  
    43  	SendData(context.Context, *livekit6.SendDataRequest) (*livekit6.SendDataResponse, error)
    44  
    45  	UpdateRoomMetadata(context.Context, *livekit6.UpdateRoomMetadataRequest) (*livekit1.Room, error)
    46  }
    47  
    48  // =====================
    49  // Room Server Interface
    50  // =====================
    51  
    52  type RoomServer[RoomTopicType ~string] interface {
    53  	RegisterDeleteRoomTopic(room RoomTopicType) error
    54  	DeregisterDeleteRoomTopic(room RoomTopicType)
    55  	RegisterSendDataTopic(room RoomTopicType) error
    56  	DeregisterSendDataTopic(room RoomTopicType)
    57  	RegisterUpdateRoomMetadataTopic(room RoomTopicType) error
    58  	DeregisterUpdateRoomMetadataTopic(room RoomTopicType)
    59  	RegisterAllRoomTopics(room RoomTopicType) error
    60  	DeregisterAllRoomTopics(room RoomTopicType)
    61  
    62  	// Close and wait for pending RPCs to complete
    63  	Shutdown()
    64  
    65  	// Close immediately, without waiting for pending RPCs
    66  	Kill()
    67  }
    68  
    69  // ===========
    70  // Room Client
    71  // ===========
    72  
    73  type roomClient[RoomTopicType ~string] struct {
    74  	client *client.RPCClient
    75  }
    76  
    77  // NewRoomClient creates a psrpc client that implements the RoomClient interface.
    78  func NewRoomClient[RoomTopicType ~string](bus psrpc.MessageBus, opts ...psrpc.ClientOption) (RoomClient[RoomTopicType], error) {
    79  	sd := &info.ServiceDefinition{
    80  		Name: "Room",
    81  		ID:   rand.NewClientID(),
    82  	}
    83  
    84  	sd.RegisterMethod("DeleteRoom", false, false, true, true)
    85  	sd.RegisterMethod("SendData", false, false, true, true)
    86  	sd.RegisterMethod("UpdateRoomMetadata", false, false, true, true)
    87  
    88  	rpcClient, err := client.NewRPCClient(sd, bus, opts...)
    89  	if err != nil {
    90  		return nil, err
    91  	}
    92  
    93  	return &roomClient[RoomTopicType]{
    94  		client: rpcClient,
    95  	}, nil
    96  }
    97  
    98  func (c *roomClient[RoomTopicType]) DeleteRoom(ctx context.Context, room RoomTopicType, req *livekit6.DeleteRoomRequest, opts ...psrpc.RequestOption) (*livekit6.DeleteRoomResponse, error) {
    99  	return client.RequestSingle[*livekit6.DeleteRoomResponse](ctx, c.client, "DeleteRoom", []string{string(room)}, req, opts...)
   100  }
   101  
   102  func (c *roomClient[RoomTopicType]) SendData(ctx context.Context, room RoomTopicType, req *livekit6.SendDataRequest, opts ...psrpc.RequestOption) (*livekit6.SendDataResponse, error) {
   103  	return client.RequestSingle[*livekit6.SendDataResponse](ctx, c.client, "SendData", []string{string(room)}, req, opts...)
   104  }
   105  
   106  func (c *roomClient[RoomTopicType]) UpdateRoomMetadata(ctx context.Context, room RoomTopicType, req *livekit6.UpdateRoomMetadataRequest, opts ...psrpc.RequestOption) (*livekit1.Room, error) {
   107  	return client.RequestSingle[*livekit1.Room](ctx, c.client, "UpdateRoomMetadata", []string{string(room)}, req, opts...)
   108  }
   109  
   110  func (s *roomClient[RoomTopicType]) Close() {
   111  	s.client.Close()
   112  }
   113  
   114  // ===========
   115  // Room Server
   116  // ===========
   117  
   118  type roomServer[RoomTopicType ~string] struct {
   119  	svc RoomServerImpl
   120  	rpc *server.RPCServer
   121  }
   122  
   123  // NewRoomServer builds a RPCServer that will route requests
   124  // to the corresponding method in the provided svc implementation.
   125  func NewRoomServer[RoomTopicType ~string](svc RoomServerImpl, bus psrpc.MessageBus, opts ...psrpc.ServerOption) (RoomServer[RoomTopicType], error) {
   126  	sd := &info.ServiceDefinition{
   127  		Name: "Room",
   128  		ID:   rand.NewServerID(),
   129  	}
   130  
   131  	s := server.NewRPCServer(sd, bus, opts...)
   132  
   133  	sd.RegisterMethod("DeleteRoom", false, false, true, true)
   134  	sd.RegisterMethod("SendData", false, false, true, true)
   135  	sd.RegisterMethod("UpdateRoomMetadata", false, false, true, true)
   136  	return &roomServer[RoomTopicType]{
   137  		svc: svc,
   138  		rpc: s,
   139  	}, nil
   140  }
   141  
   142  func (s *roomServer[RoomTopicType]) RegisterDeleteRoomTopic(room RoomTopicType) error {
   143  	return server.RegisterHandler(s.rpc, "DeleteRoom", []string{string(room)}, s.svc.DeleteRoom, nil)
   144  }
   145  
   146  func (s *roomServer[RoomTopicType]) DeregisterDeleteRoomTopic(room RoomTopicType) {
   147  	s.rpc.DeregisterHandler("DeleteRoom", []string{string(room)})
   148  }
   149  
   150  func (s *roomServer[RoomTopicType]) RegisterSendDataTopic(room RoomTopicType) error {
   151  	return server.RegisterHandler(s.rpc, "SendData", []string{string(room)}, s.svc.SendData, nil)
   152  }
   153  
   154  func (s *roomServer[RoomTopicType]) DeregisterSendDataTopic(room RoomTopicType) {
   155  	s.rpc.DeregisterHandler("SendData", []string{string(room)})
   156  }
   157  
   158  func (s *roomServer[RoomTopicType]) RegisterUpdateRoomMetadataTopic(room RoomTopicType) error {
   159  	return server.RegisterHandler(s.rpc, "UpdateRoomMetadata", []string{string(room)}, s.svc.UpdateRoomMetadata, nil)
   160  }
   161  
   162  func (s *roomServer[RoomTopicType]) DeregisterUpdateRoomMetadataTopic(room RoomTopicType) {
   163  	s.rpc.DeregisterHandler("UpdateRoomMetadata", []string{string(room)})
   164  }
   165  
   166  func (s *roomServer[RoomTopicType]) allRoomTopicRegisterers() server.RegistererSlice {
   167  	return server.RegistererSlice{
   168  		server.NewRegisterer(s.RegisterDeleteRoomTopic, s.DeregisterDeleteRoomTopic),
   169  		server.NewRegisterer(s.RegisterSendDataTopic, s.DeregisterSendDataTopic),
   170  		server.NewRegisterer(s.RegisterUpdateRoomMetadataTopic, s.DeregisterUpdateRoomMetadataTopic),
   171  	}
   172  }
   173  
   174  func (s *roomServer[RoomTopicType]) RegisterAllRoomTopics(room RoomTopicType) error {
   175  	return s.allRoomTopicRegisterers().Register(room)
   176  }
   177  
   178  func (s *roomServer[RoomTopicType]) DeregisterAllRoomTopics(room RoomTopicType) {
   179  	s.allRoomTopicRegisterers().Deregister(room)
   180  }
   181  
   182  func (s *roomServer[RoomTopicType]) Shutdown() {
   183  	s.rpc.Close(false)
   184  }
   185  
   186  func (s *roomServer[RoomTopicType]) Kill() {
   187  	s.rpc.Close(true)
   188  }
   189  
   190  var psrpcFileDescriptor7 = []byte{
   191  	// 230 bytes of a gzipped FileDescriptorProto
   192  	0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xe2, 0x2b, 0x2a, 0x48, 0xd6,
   193  	0x2f, 0xca, 0xcf, 0xcf, 0xd5, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x62, 0x2e, 0x2a, 0x48, 0x96,
   194  	0xe2, 0xcd, 0x2f, 0x28, 0xc9, 0xcc, 0xcf, 0x2b, 0x86, 0x88, 0x49, 0x89, 0xe4, 0x64, 0x96, 0xa5,
   195  	0x66, 0x67, 0x96, 0xc4, 0xe7, 0xe6, 0xa7, 0xa4, 0xe6, 0xc0, 0x44, 0x85, 0x60, 0xa2, 0x08, 0xdd,
   196  	0x46, 0xf3, 0x99, 0xb8, 0x58, 0x82, 0xf2, 0xf3, 0x73, 0x85, 0x62, 0xb9, 0xb8, 0x5c, 0x52, 0x73,
   197  	0x52, 0x4b, 0x52, 0xc1, 0x3c, 0x29, 0x3d, 0xa8, 0x5a, 0x3d, 0x84, 0x60, 0x50, 0x6a, 0x61, 0x69,
   198  	0x6a, 0x71, 0x89, 0x94, 0x34, 0x56, 0xb9, 0xe2, 0x82, 0xfc, 0xbc, 0xe2, 0x54, 0x25, 0xb1, 0x4d,
   199  	0x9d, 0x8c, 0x42, 0x02, 0x8c, 0x52, 0x7c, 0x5c, 0x2c, 0x20, 0x5b, 0x84, 0xc0, 0xa4, 0x04, 0xa3,
   200  	0x50, 0x38, 0x17, 0x47, 0x70, 0x6a, 0x5e, 0x8a, 0x4b, 0x62, 0x49, 0xa2, 0x90, 0x04, 0xdc, 0x00,
   201  	0x98, 0x10, 0xcc, 0x68, 0x49, 0x2c, 0x32, 0x04, 0x0c, 0x8e, 0xe7, 0x12, 0x0a, 0x2d, 0x48, 0x49,
   202  	0x84, 0x38, 0xc3, 0x37, 0xb5, 0x24, 0x31, 0x05, 0x64, 0x85, 0x12, 0xdc, 0x20, 0x4c, 0x49, 0x98,
   203  	0x65, 0xbc, 0x70, 0x35, 0x20, 0x59, 0x5c, 0x16, 0x38, 0x29, 0x46, 0xc9, 0xa7, 0x67, 0x96, 0x64,
   204  	0x94, 0x26, 0xe9, 0x25, 0xe7, 0xe7, 0xea, 0x43, 0xb5, 0xe8, 0x83, 0x43, 0x2f, 0x39, 0x3f, 0x47,
   205  	0xbf, 0xa8, 0x20, 0x39, 0x89, 0x0d, 0xcc, 0x33, 0x06, 0x04, 0x00, 0x00, 0xff, 0xff, 0xa6, 0x87,
   206  	0xc0, 0x3a, 0x9b, 0x01, 0x00, 0x00,
   207  }