github.com/whoyao/protocol@v0.0.0-20230519045905-2d8ace718ca5/livekit/livekit_room.twirp.go (about)

     1  // Code generated by protoc-gen-twirp v8.1.3, DO NOT EDIT.
     2  // source: livekit_room.proto
     3  
     4  package livekit
     5  
     6  import context "context"
     7  import fmt "fmt"
     8  import http "net/http"
     9  import io "io"
    10  import json "encoding/json"
    11  import strconv "strconv"
    12  import strings "strings"
    13  
    14  import protojson "google.golang.org/protobuf/encoding/protojson"
    15  import proto "google.golang.org/protobuf/proto"
    16  import twirp "github.com/twitchtv/twirp"
    17  import ctxsetters "github.com/twitchtv/twirp/ctxsetters"
    18  
    19  // Version compatibility assertion.
    20  // If the constant is not defined in the package, that likely means
    21  // the package needs to be updated to work with this generated code.
    22  // See https://twitchtv.github.io/twirp/docs/version_matrix.html
    23  const _ = twirp.TwirpPackageMinVersion_8_1_0
    24  
    25  // =====================
    26  // RoomService Interface
    27  // =====================
    28  
    29  // Room service that can be performed on any node
    30  // they are Twirp-based HTTP req/responses
    31  type RoomService interface {
    32  	// Creates a room with settings. Requires `roomCreate` permission.
    33  	// This method is optional; rooms are automatically created when clients connect to them for the first time.
    34  	CreateRoom(context.Context, *CreateRoomRequest) (*Room, error)
    35  
    36  	// List rooms that are active on the server. Requires `roomList` permission.
    37  	ListRooms(context.Context, *ListRoomsRequest) (*ListRoomsResponse, error)
    38  
    39  	// Deletes an existing room by name or id. Requires `roomCreate` permission.
    40  	// DeleteRoom will disconnect all participants that are currently in the room.
    41  	DeleteRoom(context.Context, *DeleteRoomRequest) (*DeleteRoomResponse, error)
    42  
    43  	// Lists participants in a room, Requires `roomAdmin`
    44  	ListParticipants(context.Context, *ListParticipantsRequest) (*ListParticipantsResponse, error)
    45  
    46  	// Get information on a specific participant, Requires `roomAdmin`
    47  	GetParticipant(context.Context, *RoomParticipantIdentity) (*ParticipantInfo, error)
    48  
    49  	// Removes a participant from room. Requires `roomAdmin`
    50  	RemoveParticipant(context.Context, *RoomParticipantIdentity) (*RemoveParticipantResponse, error)
    51  
    52  	// Mute/unmute a participant's track, Requires `roomAdmin`
    53  	MutePublishedTrack(context.Context, *MuteRoomTrackRequest) (*MuteRoomTrackResponse, error)
    54  
    55  	// Update participant metadata, will cause updates to be broadcasted to everyone in the room. Requires `roomAdmin`
    56  	UpdateParticipant(context.Context, *UpdateParticipantRequest) (*ParticipantInfo, error)
    57  
    58  	// Subscribes or unsubscribe a participant from tracks. Requires `roomAdmin`
    59  	UpdateSubscriptions(context.Context, *UpdateSubscriptionsRequest) (*UpdateSubscriptionsResponse, error)
    60  
    61  	// Send data over data channel to participants in a room, Requires `roomAdmin`
    62  	SendData(context.Context, *SendDataRequest) (*SendDataResponse, error)
    63  
    64  	// Update room metadata, will cause updates to be broadcasted to everyone in the room, Requires `roomAdmin`
    65  	UpdateRoomMetadata(context.Context, *UpdateRoomMetadataRequest) (*Room, error)
    66  }
    67  
    68  // ===========================
    69  // RoomService Protobuf Client
    70  // ===========================
    71  
    72  type roomServiceProtobufClient struct {
    73  	client      HTTPClient
    74  	urls        [11]string
    75  	interceptor twirp.Interceptor
    76  	opts        twirp.ClientOptions
    77  }
    78  
    79  // NewRoomServiceProtobufClient creates a Protobuf client that implements the RoomService interface.
    80  // It communicates using Protobuf and can be configured with a custom HTTPClient.
    81  func NewRoomServiceProtobufClient(baseURL string, client HTTPClient, opts ...twirp.ClientOption) RoomService {
    82  	if c, ok := client.(*http.Client); ok {
    83  		client = withoutRedirects(c)
    84  	}
    85  
    86  	clientOpts := twirp.ClientOptions{}
    87  	for _, o := range opts {
    88  		o(&clientOpts)
    89  	}
    90  
    91  	// Using ReadOpt allows backwards and forwards compatibility with new options in the future
    92  	literalURLs := false
    93  	_ = clientOpts.ReadOpt("literalURLs", &literalURLs)
    94  	var pathPrefix string
    95  	if ok := clientOpts.ReadOpt("pathPrefix", &pathPrefix); !ok {
    96  		pathPrefix = "/twirp" // default prefix
    97  	}
    98  
    99  	// Build method URLs: <baseURL>[<prefix>]/<package>.<Service>/<Method>
   100  	serviceURL := sanitizeBaseURL(baseURL)
   101  	serviceURL += baseServicePath(pathPrefix, "livekit", "RoomService")
   102  	urls := [11]string{
   103  		serviceURL + "CreateRoom",
   104  		serviceURL + "ListRooms",
   105  		serviceURL + "DeleteRoom",
   106  		serviceURL + "ListParticipants",
   107  		serviceURL + "GetParticipant",
   108  		serviceURL + "RemoveParticipant",
   109  		serviceURL + "MutePublishedTrack",
   110  		serviceURL + "UpdateParticipant",
   111  		serviceURL + "UpdateSubscriptions",
   112  		serviceURL + "SendData",
   113  		serviceURL + "UpdateRoomMetadata",
   114  	}
   115  
   116  	return &roomServiceProtobufClient{
   117  		client:      client,
   118  		urls:        urls,
   119  		interceptor: twirp.ChainInterceptors(clientOpts.Interceptors...),
   120  		opts:        clientOpts,
   121  	}
   122  }
   123  
   124  func (c *roomServiceProtobufClient) CreateRoom(ctx context.Context, in *CreateRoomRequest) (*Room, error) {
   125  	ctx = ctxsetters.WithPackageName(ctx, "livekit")
   126  	ctx = ctxsetters.WithServiceName(ctx, "RoomService")
   127  	ctx = ctxsetters.WithMethodName(ctx, "CreateRoom")
   128  	caller := c.callCreateRoom
   129  	if c.interceptor != nil {
   130  		caller = func(ctx context.Context, req *CreateRoomRequest) (*Room, error) {
   131  			resp, err := c.interceptor(
   132  				func(ctx context.Context, req interface{}) (interface{}, error) {
   133  					typedReq, ok := req.(*CreateRoomRequest)
   134  					if !ok {
   135  						return nil, twirp.InternalError("failed type assertion req.(*CreateRoomRequest) when calling interceptor")
   136  					}
   137  					return c.callCreateRoom(ctx, typedReq)
   138  				},
   139  			)(ctx, req)
   140  			if resp != nil {
   141  				typedResp, ok := resp.(*Room)
   142  				if !ok {
   143  					return nil, twirp.InternalError("failed type assertion resp.(*Room) when calling interceptor")
   144  				}
   145  				return typedResp, err
   146  			}
   147  			return nil, err
   148  		}
   149  	}
   150  	return caller(ctx, in)
   151  }
   152  
   153  func (c *roomServiceProtobufClient) callCreateRoom(ctx context.Context, in *CreateRoomRequest) (*Room, error) {
   154  	out := new(Room)
   155  	ctx, err := doProtobufRequest(ctx, c.client, c.opts.Hooks, c.urls[0], in, out)
   156  	if err != nil {
   157  		twerr, ok := err.(twirp.Error)
   158  		if !ok {
   159  			twerr = twirp.InternalErrorWith(err)
   160  		}
   161  		callClientError(ctx, c.opts.Hooks, twerr)
   162  		return nil, err
   163  	}
   164  
   165  	callClientResponseReceived(ctx, c.opts.Hooks)
   166  
   167  	return out, nil
   168  }
   169  
   170  func (c *roomServiceProtobufClient) ListRooms(ctx context.Context, in *ListRoomsRequest) (*ListRoomsResponse, error) {
   171  	ctx = ctxsetters.WithPackageName(ctx, "livekit")
   172  	ctx = ctxsetters.WithServiceName(ctx, "RoomService")
   173  	ctx = ctxsetters.WithMethodName(ctx, "ListRooms")
   174  	caller := c.callListRooms
   175  	if c.interceptor != nil {
   176  		caller = func(ctx context.Context, req *ListRoomsRequest) (*ListRoomsResponse, error) {
   177  			resp, err := c.interceptor(
   178  				func(ctx context.Context, req interface{}) (interface{}, error) {
   179  					typedReq, ok := req.(*ListRoomsRequest)
   180  					if !ok {
   181  						return nil, twirp.InternalError("failed type assertion req.(*ListRoomsRequest) when calling interceptor")
   182  					}
   183  					return c.callListRooms(ctx, typedReq)
   184  				},
   185  			)(ctx, req)
   186  			if resp != nil {
   187  				typedResp, ok := resp.(*ListRoomsResponse)
   188  				if !ok {
   189  					return nil, twirp.InternalError("failed type assertion resp.(*ListRoomsResponse) when calling interceptor")
   190  				}
   191  				return typedResp, err
   192  			}
   193  			return nil, err
   194  		}
   195  	}
   196  	return caller(ctx, in)
   197  }
   198  
   199  func (c *roomServiceProtobufClient) callListRooms(ctx context.Context, in *ListRoomsRequest) (*ListRoomsResponse, error) {
   200  	out := new(ListRoomsResponse)
   201  	ctx, err := doProtobufRequest(ctx, c.client, c.opts.Hooks, c.urls[1], in, out)
   202  	if err != nil {
   203  		twerr, ok := err.(twirp.Error)
   204  		if !ok {
   205  			twerr = twirp.InternalErrorWith(err)
   206  		}
   207  		callClientError(ctx, c.opts.Hooks, twerr)
   208  		return nil, err
   209  	}
   210  
   211  	callClientResponseReceived(ctx, c.opts.Hooks)
   212  
   213  	return out, nil
   214  }
   215  
   216  func (c *roomServiceProtobufClient) DeleteRoom(ctx context.Context, in *DeleteRoomRequest) (*DeleteRoomResponse, error) {
   217  	ctx = ctxsetters.WithPackageName(ctx, "livekit")
   218  	ctx = ctxsetters.WithServiceName(ctx, "RoomService")
   219  	ctx = ctxsetters.WithMethodName(ctx, "DeleteRoom")
   220  	caller := c.callDeleteRoom
   221  	if c.interceptor != nil {
   222  		caller = func(ctx context.Context, req *DeleteRoomRequest) (*DeleteRoomResponse, error) {
   223  			resp, err := c.interceptor(
   224  				func(ctx context.Context, req interface{}) (interface{}, error) {
   225  					typedReq, ok := req.(*DeleteRoomRequest)
   226  					if !ok {
   227  						return nil, twirp.InternalError("failed type assertion req.(*DeleteRoomRequest) when calling interceptor")
   228  					}
   229  					return c.callDeleteRoom(ctx, typedReq)
   230  				},
   231  			)(ctx, req)
   232  			if resp != nil {
   233  				typedResp, ok := resp.(*DeleteRoomResponse)
   234  				if !ok {
   235  					return nil, twirp.InternalError("failed type assertion resp.(*DeleteRoomResponse) when calling interceptor")
   236  				}
   237  				return typedResp, err
   238  			}
   239  			return nil, err
   240  		}
   241  	}
   242  	return caller(ctx, in)
   243  }
   244  
   245  func (c *roomServiceProtobufClient) callDeleteRoom(ctx context.Context, in *DeleteRoomRequest) (*DeleteRoomResponse, error) {
   246  	out := new(DeleteRoomResponse)
   247  	ctx, err := doProtobufRequest(ctx, c.client, c.opts.Hooks, c.urls[2], in, out)
   248  	if err != nil {
   249  		twerr, ok := err.(twirp.Error)
   250  		if !ok {
   251  			twerr = twirp.InternalErrorWith(err)
   252  		}
   253  		callClientError(ctx, c.opts.Hooks, twerr)
   254  		return nil, err
   255  	}
   256  
   257  	callClientResponseReceived(ctx, c.opts.Hooks)
   258  
   259  	return out, nil
   260  }
   261  
   262  func (c *roomServiceProtobufClient) ListParticipants(ctx context.Context, in *ListParticipantsRequest) (*ListParticipantsResponse, error) {
   263  	ctx = ctxsetters.WithPackageName(ctx, "livekit")
   264  	ctx = ctxsetters.WithServiceName(ctx, "RoomService")
   265  	ctx = ctxsetters.WithMethodName(ctx, "ListParticipants")
   266  	caller := c.callListParticipants
   267  	if c.interceptor != nil {
   268  		caller = func(ctx context.Context, req *ListParticipantsRequest) (*ListParticipantsResponse, error) {
   269  			resp, err := c.interceptor(
   270  				func(ctx context.Context, req interface{}) (interface{}, error) {
   271  					typedReq, ok := req.(*ListParticipantsRequest)
   272  					if !ok {
   273  						return nil, twirp.InternalError("failed type assertion req.(*ListParticipantsRequest) when calling interceptor")
   274  					}
   275  					return c.callListParticipants(ctx, typedReq)
   276  				},
   277  			)(ctx, req)
   278  			if resp != nil {
   279  				typedResp, ok := resp.(*ListParticipantsResponse)
   280  				if !ok {
   281  					return nil, twirp.InternalError("failed type assertion resp.(*ListParticipantsResponse) when calling interceptor")
   282  				}
   283  				return typedResp, err
   284  			}
   285  			return nil, err
   286  		}
   287  	}
   288  	return caller(ctx, in)
   289  }
   290  
   291  func (c *roomServiceProtobufClient) callListParticipants(ctx context.Context, in *ListParticipantsRequest) (*ListParticipantsResponse, error) {
   292  	out := new(ListParticipantsResponse)
   293  	ctx, err := doProtobufRequest(ctx, c.client, c.opts.Hooks, c.urls[3], in, out)
   294  	if err != nil {
   295  		twerr, ok := err.(twirp.Error)
   296  		if !ok {
   297  			twerr = twirp.InternalErrorWith(err)
   298  		}
   299  		callClientError(ctx, c.opts.Hooks, twerr)
   300  		return nil, err
   301  	}
   302  
   303  	callClientResponseReceived(ctx, c.opts.Hooks)
   304  
   305  	return out, nil
   306  }
   307  
   308  func (c *roomServiceProtobufClient) GetParticipant(ctx context.Context, in *RoomParticipantIdentity) (*ParticipantInfo, error) {
   309  	ctx = ctxsetters.WithPackageName(ctx, "livekit")
   310  	ctx = ctxsetters.WithServiceName(ctx, "RoomService")
   311  	ctx = ctxsetters.WithMethodName(ctx, "GetParticipant")
   312  	caller := c.callGetParticipant
   313  	if c.interceptor != nil {
   314  		caller = func(ctx context.Context, req *RoomParticipantIdentity) (*ParticipantInfo, error) {
   315  			resp, err := c.interceptor(
   316  				func(ctx context.Context, req interface{}) (interface{}, error) {
   317  					typedReq, ok := req.(*RoomParticipantIdentity)
   318  					if !ok {
   319  						return nil, twirp.InternalError("failed type assertion req.(*RoomParticipantIdentity) when calling interceptor")
   320  					}
   321  					return c.callGetParticipant(ctx, typedReq)
   322  				},
   323  			)(ctx, req)
   324  			if resp != nil {
   325  				typedResp, ok := resp.(*ParticipantInfo)
   326  				if !ok {
   327  					return nil, twirp.InternalError("failed type assertion resp.(*ParticipantInfo) when calling interceptor")
   328  				}
   329  				return typedResp, err
   330  			}
   331  			return nil, err
   332  		}
   333  	}
   334  	return caller(ctx, in)
   335  }
   336  
   337  func (c *roomServiceProtobufClient) callGetParticipant(ctx context.Context, in *RoomParticipantIdentity) (*ParticipantInfo, error) {
   338  	out := new(ParticipantInfo)
   339  	ctx, err := doProtobufRequest(ctx, c.client, c.opts.Hooks, c.urls[4], in, out)
   340  	if err != nil {
   341  		twerr, ok := err.(twirp.Error)
   342  		if !ok {
   343  			twerr = twirp.InternalErrorWith(err)
   344  		}
   345  		callClientError(ctx, c.opts.Hooks, twerr)
   346  		return nil, err
   347  	}
   348  
   349  	callClientResponseReceived(ctx, c.opts.Hooks)
   350  
   351  	return out, nil
   352  }
   353  
   354  func (c *roomServiceProtobufClient) RemoveParticipant(ctx context.Context, in *RoomParticipantIdentity) (*RemoveParticipantResponse, error) {
   355  	ctx = ctxsetters.WithPackageName(ctx, "livekit")
   356  	ctx = ctxsetters.WithServiceName(ctx, "RoomService")
   357  	ctx = ctxsetters.WithMethodName(ctx, "RemoveParticipant")
   358  	caller := c.callRemoveParticipant
   359  	if c.interceptor != nil {
   360  		caller = func(ctx context.Context, req *RoomParticipantIdentity) (*RemoveParticipantResponse, error) {
   361  			resp, err := c.interceptor(
   362  				func(ctx context.Context, req interface{}) (interface{}, error) {
   363  					typedReq, ok := req.(*RoomParticipantIdentity)
   364  					if !ok {
   365  						return nil, twirp.InternalError("failed type assertion req.(*RoomParticipantIdentity) when calling interceptor")
   366  					}
   367  					return c.callRemoveParticipant(ctx, typedReq)
   368  				},
   369  			)(ctx, req)
   370  			if resp != nil {
   371  				typedResp, ok := resp.(*RemoveParticipantResponse)
   372  				if !ok {
   373  					return nil, twirp.InternalError("failed type assertion resp.(*RemoveParticipantResponse) when calling interceptor")
   374  				}
   375  				return typedResp, err
   376  			}
   377  			return nil, err
   378  		}
   379  	}
   380  	return caller(ctx, in)
   381  }
   382  
   383  func (c *roomServiceProtobufClient) callRemoveParticipant(ctx context.Context, in *RoomParticipantIdentity) (*RemoveParticipantResponse, error) {
   384  	out := new(RemoveParticipantResponse)
   385  	ctx, err := doProtobufRequest(ctx, c.client, c.opts.Hooks, c.urls[5], in, out)
   386  	if err != nil {
   387  		twerr, ok := err.(twirp.Error)
   388  		if !ok {
   389  			twerr = twirp.InternalErrorWith(err)
   390  		}
   391  		callClientError(ctx, c.opts.Hooks, twerr)
   392  		return nil, err
   393  	}
   394  
   395  	callClientResponseReceived(ctx, c.opts.Hooks)
   396  
   397  	return out, nil
   398  }
   399  
   400  func (c *roomServiceProtobufClient) MutePublishedTrack(ctx context.Context, in *MuteRoomTrackRequest) (*MuteRoomTrackResponse, error) {
   401  	ctx = ctxsetters.WithPackageName(ctx, "livekit")
   402  	ctx = ctxsetters.WithServiceName(ctx, "RoomService")
   403  	ctx = ctxsetters.WithMethodName(ctx, "MutePublishedTrack")
   404  	caller := c.callMutePublishedTrack
   405  	if c.interceptor != nil {
   406  		caller = func(ctx context.Context, req *MuteRoomTrackRequest) (*MuteRoomTrackResponse, error) {
   407  			resp, err := c.interceptor(
   408  				func(ctx context.Context, req interface{}) (interface{}, error) {
   409  					typedReq, ok := req.(*MuteRoomTrackRequest)
   410  					if !ok {
   411  						return nil, twirp.InternalError("failed type assertion req.(*MuteRoomTrackRequest) when calling interceptor")
   412  					}
   413  					return c.callMutePublishedTrack(ctx, typedReq)
   414  				},
   415  			)(ctx, req)
   416  			if resp != nil {
   417  				typedResp, ok := resp.(*MuteRoomTrackResponse)
   418  				if !ok {
   419  					return nil, twirp.InternalError("failed type assertion resp.(*MuteRoomTrackResponse) when calling interceptor")
   420  				}
   421  				return typedResp, err
   422  			}
   423  			return nil, err
   424  		}
   425  	}
   426  	return caller(ctx, in)
   427  }
   428  
   429  func (c *roomServiceProtobufClient) callMutePublishedTrack(ctx context.Context, in *MuteRoomTrackRequest) (*MuteRoomTrackResponse, error) {
   430  	out := new(MuteRoomTrackResponse)
   431  	ctx, err := doProtobufRequest(ctx, c.client, c.opts.Hooks, c.urls[6], in, out)
   432  	if err != nil {
   433  		twerr, ok := err.(twirp.Error)
   434  		if !ok {
   435  			twerr = twirp.InternalErrorWith(err)
   436  		}
   437  		callClientError(ctx, c.opts.Hooks, twerr)
   438  		return nil, err
   439  	}
   440  
   441  	callClientResponseReceived(ctx, c.opts.Hooks)
   442  
   443  	return out, nil
   444  }
   445  
   446  func (c *roomServiceProtobufClient) UpdateParticipant(ctx context.Context, in *UpdateParticipantRequest) (*ParticipantInfo, error) {
   447  	ctx = ctxsetters.WithPackageName(ctx, "livekit")
   448  	ctx = ctxsetters.WithServiceName(ctx, "RoomService")
   449  	ctx = ctxsetters.WithMethodName(ctx, "UpdateParticipant")
   450  	caller := c.callUpdateParticipant
   451  	if c.interceptor != nil {
   452  		caller = func(ctx context.Context, req *UpdateParticipantRequest) (*ParticipantInfo, error) {
   453  			resp, err := c.interceptor(
   454  				func(ctx context.Context, req interface{}) (interface{}, error) {
   455  					typedReq, ok := req.(*UpdateParticipantRequest)
   456  					if !ok {
   457  						return nil, twirp.InternalError("failed type assertion req.(*UpdateParticipantRequest) when calling interceptor")
   458  					}
   459  					return c.callUpdateParticipant(ctx, typedReq)
   460  				},
   461  			)(ctx, req)
   462  			if resp != nil {
   463  				typedResp, ok := resp.(*ParticipantInfo)
   464  				if !ok {
   465  					return nil, twirp.InternalError("failed type assertion resp.(*ParticipantInfo) when calling interceptor")
   466  				}
   467  				return typedResp, err
   468  			}
   469  			return nil, err
   470  		}
   471  	}
   472  	return caller(ctx, in)
   473  }
   474  
   475  func (c *roomServiceProtobufClient) callUpdateParticipant(ctx context.Context, in *UpdateParticipantRequest) (*ParticipantInfo, error) {
   476  	out := new(ParticipantInfo)
   477  	ctx, err := doProtobufRequest(ctx, c.client, c.opts.Hooks, c.urls[7], in, out)
   478  	if err != nil {
   479  		twerr, ok := err.(twirp.Error)
   480  		if !ok {
   481  			twerr = twirp.InternalErrorWith(err)
   482  		}
   483  		callClientError(ctx, c.opts.Hooks, twerr)
   484  		return nil, err
   485  	}
   486  
   487  	callClientResponseReceived(ctx, c.opts.Hooks)
   488  
   489  	return out, nil
   490  }
   491  
   492  func (c *roomServiceProtobufClient) UpdateSubscriptions(ctx context.Context, in *UpdateSubscriptionsRequest) (*UpdateSubscriptionsResponse, error) {
   493  	ctx = ctxsetters.WithPackageName(ctx, "livekit")
   494  	ctx = ctxsetters.WithServiceName(ctx, "RoomService")
   495  	ctx = ctxsetters.WithMethodName(ctx, "UpdateSubscriptions")
   496  	caller := c.callUpdateSubscriptions
   497  	if c.interceptor != nil {
   498  		caller = func(ctx context.Context, req *UpdateSubscriptionsRequest) (*UpdateSubscriptionsResponse, error) {
   499  			resp, err := c.interceptor(
   500  				func(ctx context.Context, req interface{}) (interface{}, error) {
   501  					typedReq, ok := req.(*UpdateSubscriptionsRequest)
   502  					if !ok {
   503  						return nil, twirp.InternalError("failed type assertion req.(*UpdateSubscriptionsRequest) when calling interceptor")
   504  					}
   505  					return c.callUpdateSubscriptions(ctx, typedReq)
   506  				},
   507  			)(ctx, req)
   508  			if resp != nil {
   509  				typedResp, ok := resp.(*UpdateSubscriptionsResponse)
   510  				if !ok {
   511  					return nil, twirp.InternalError("failed type assertion resp.(*UpdateSubscriptionsResponse) when calling interceptor")
   512  				}
   513  				return typedResp, err
   514  			}
   515  			return nil, err
   516  		}
   517  	}
   518  	return caller(ctx, in)
   519  }
   520  
   521  func (c *roomServiceProtobufClient) callUpdateSubscriptions(ctx context.Context, in *UpdateSubscriptionsRequest) (*UpdateSubscriptionsResponse, error) {
   522  	out := new(UpdateSubscriptionsResponse)
   523  	ctx, err := doProtobufRequest(ctx, c.client, c.opts.Hooks, c.urls[8], in, out)
   524  	if err != nil {
   525  		twerr, ok := err.(twirp.Error)
   526  		if !ok {
   527  			twerr = twirp.InternalErrorWith(err)
   528  		}
   529  		callClientError(ctx, c.opts.Hooks, twerr)
   530  		return nil, err
   531  	}
   532  
   533  	callClientResponseReceived(ctx, c.opts.Hooks)
   534  
   535  	return out, nil
   536  }
   537  
   538  func (c *roomServiceProtobufClient) SendData(ctx context.Context, in *SendDataRequest) (*SendDataResponse, error) {
   539  	ctx = ctxsetters.WithPackageName(ctx, "livekit")
   540  	ctx = ctxsetters.WithServiceName(ctx, "RoomService")
   541  	ctx = ctxsetters.WithMethodName(ctx, "SendData")
   542  	caller := c.callSendData
   543  	if c.interceptor != nil {
   544  		caller = func(ctx context.Context, req *SendDataRequest) (*SendDataResponse, error) {
   545  			resp, err := c.interceptor(
   546  				func(ctx context.Context, req interface{}) (interface{}, error) {
   547  					typedReq, ok := req.(*SendDataRequest)
   548  					if !ok {
   549  						return nil, twirp.InternalError("failed type assertion req.(*SendDataRequest) when calling interceptor")
   550  					}
   551  					return c.callSendData(ctx, typedReq)
   552  				},
   553  			)(ctx, req)
   554  			if resp != nil {
   555  				typedResp, ok := resp.(*SendDataResponse)
   556  				if !ok {
   557  					return nil, twirp.InternalError("failed type assertion resp.(*SendDataResponse) when calling interceptor")
   558  				}
   559  				return typedResp, err
   560  			}
   561  			return nil, err
   562  		}
   563  	}
   564  	return caller(ctx, in)
   565  }
   566  
   567  func (c *roomServiceProtobufClient) callSendData(ctx context.Context, in *SendDataRequest) (*SendDataResponse, error) {
   568  	out := new(SendDataResponse)
   569  	ctx, err := doProtobufRequest(ctx, c.client, c.opts.Hooks, c.urls[9], in, out)
   570  	if err != nil {
   571  		twerr, ok := err.(twirp.Error)
   572  		if !ok {
   573  			twerr = twirp.InternalErrorWith(err)
   574  		}
   575  		callClientError(ctx, c.opts.Hooks, twerr)
   576  		return nil, err
   577  	}
   578  
   579  	callClientResponseReceived(ctx, c.opts.Hooks)
   580  
   581  	return out, nil
   582  }
   583  
   584  func (c *roomServiceProtobufClient) UpdateRoomMetadata(ctx context.Context, in *UpdateRoomMetadataRequest) (*Room, error) {
   585  	ctx = ctxsetters.WithPackageName(ctx, "livekit")
   586  	ctx = ctxsetters.WithServiceName(ctx, "RoomService")
   587  	ctx = ctxsetters.WithMethodName(ctx, "UpdateRoomMetadata")
   588  	caller := c.callUpdateRoomMetadata
   589  	if c.interceptor != nil {
   590  		caller = func(ctx context.Context, req *UpdateRoomMetadataRequest) (*Room, error) {
   591  			resp, err := c.interceptor(
   592  				func(ctx context.Context, req interface{}) (interface{}, error) {
   593  					typedReq, ok := req.(*UpdateRoomMetadataRequest)
   594  					if !ok {
   595  						return nil, twirp.InternalError("failed type assertion req.(*UpdateRoomMetadataRequest) when calling interceptor")
   596  					}
   597  					return c.callUpdateRoomMetadata(ctx, typedReq)
   598  				},
   599  			)(ctx, req)
   600  			if resp != nil {
   601  				typedResp, ok := resp.(*Room)
   602  				if !ok {
   603  					return nil, twirp.InternalError("failed type assertion resp.(*Room) when calling interceptor")
   604  				}
   605  				return typedResp, err
   606  			}
   607  			return nil, err
   608  		}
   609  	}
   610  	return caller(ctx, in)
   611  }
   612  
   613  func (c *roomServiceProtobufClient) callUpdateRoomMetadata(ctx context.Context, in *UpdateRoomMetadataRequest) (*Room, error) {
   614  	out := new(Room)
   615  	ctx, err := doProtobufRequest(ctx, c.client, c.opts.Hooks, c.urls[10], in, out)
   616  	if err != nil {
   617  		twerr, ok := err.(twirp.Error)
   618  		if !ok {
   619  			twerr = twirp.InternalErrorWith(err)
   620  		}
   621  		callClientError(ctx, c.opts.Hooks, twerr)
   622  		return nil, err
   623  	}
   624  
   625  	callClientResponseReceived(ctx, c.opts.Hooks)
   626  
   627  	return out, nil
   628  }
   629  
   630  // =======================
   631  // RoomService JSON Client
   632  // =======================
   633  
   634  type roomServiceJSONClient struct {
   635  	client      HTTPClient
   636  	urls        [11]string
   637  	interceptor twirp.Interceptor
   638  	opts        twirp.ClientOptions
   639  }
   640  
   641  // NewRoomServiceJSONClient creates a JSON client that implements the RoomService interface.
   642  // It communicates using JSON and can be configured with a custom HTTPClient.
   643  func NewRoomServiceJSONClient(baseURL string, client HTTPClient, opts ...twirp.ClientOption) RoomService {
   644  	if c, ok := client.(*http.Client); ok {
   645  		client = withoutRedirects(c)
   646  	}
   647  
   648  	clientOpts := twirp.ClientOptions{}
   649  	for _, o := range opts {
   650  		o(&clientOpts)
   651  	}
   652  
   653  	// Using ReadOpt allows backwards and forwards compatibility with new options in the future
   654  	literalURLs := false
   655  	_ = clientOpts.ReadOpt("literalURLs", &literalURLs)
   656  	var pathPrefix string
   657  	if ok := clientOpts.ReadOpt("pathPrefix", &pathPrefix); !ok {
   658  		pathPrefix = "/twirp" // default prefix
   659  	}
   660  
   661  	// Build method URLs: <baseURL>[<prefix>]/<package>.<Service>/<Method>
   662  	serviceURL := sanitizeBaseURL(baseURL)
   663  	serviceURL += baseServicePath(pathPrefix, "livekit", "RoomService")
   664  	urls := [11]string{
   665  		serviceURL + "CreateRoom",
   666  		serviceURL + "ListRooms",
   667  		serviceURL + "DeleteRoom",
   668  		serviceURL + "ListParticipants",
   669  		serviceURL + "GetParticipant",
   670  		serviceURL + "RemoveParticipant",
   671  		serviceURL + "MutePublishedTrack",
   672  		serviceURL + "UpdateParticipant",
   673  		serviceURL + "UpdateSubscriptions",
   674  		serviceURL + "SendData",
   675  		serviceURL + "UpdateRoomMetadata",
   676  	}
   677  
   678  	return &roomServiceJSONClient{
   679  		client:      client,
   680  		urls:        urls,
   681  		interceptor: twirp.ChainInterceptors(clientOpts.Interceptors...),
   682  		opts:        clientOpts,
   683  	}
   684  }
   685  
   686  func (c *roomServiceJSONClient) CreateRoom(ctx context.Context, in *CreateRoomRequest) (*Room, error) {
   687  	ctx = ctxsetters.WithPackageName(ctx, "livekit")
   688  	ctx = ctxsetters.WithServiceName(ctx, "RoomService")
   689  	ctx = ctxsetters.WithMethodName(ctx, "CreateRoom")
   690  	caller := c.callCreateRoom
   691  	if c.interceptor != nil {
   692  		caller = func(ctx context.Context, req *CreateRoomRequest) (*Room, error) {
   693  			resp, err := c.interceptor(
   694  				func(ctx context.Context, req interface{}) (interface{}, error) {
   695  					typedReq, ok := req.(*CreateRoomRequest)
   696  					if !ok {
   697  						return nil, twirp.InternalError("failed type assertion req.(*CreateRoomRequest) when calling interceptor")
   698  					}
   699  					return c.callCreateRoom(ctx, typedReq)
   700  				},
   701  			)(ctx, req)
   702  			if resp != nil {
   703  				typedResp, ok := resp.(*Room)
   704  				if !ok {
   705  					return nil, twirp.InternalError("failed type assertion resp.(*Room) when calling interceptor")
   706  				}
   707  				return typedResp, err
   708  			}
   709  			return nil, err
   710  		}
   711  	}
   712  	return caller(ctx, in)
   713  }
   714  
   715  func (c *roomServiceJSONClient) callCreateRoom(ctx context.Context, in *CreateRoomRequest) (*Room, error) {
   716  	out := new(Room)
   717  	ctx, err := doJSONRequest(ctx, c.client, c.opts.Hooks, c.urls[0], in, out)
   718  	if err != nil {
   719  		twerr, ok := err.(twirp.Error)
   720  		if !ok {
   721  			twerr = twirp.InternalErrorWith(err)
   722  		}
   723  		callClientError(ctx, c.opts.Hooks, twerr)
   724  		return nil, err
   725  	}
   726  
   727  	callClientResponseReceived(ctx, c.opts.Hooks)
   728  
   729  	return out, nil
   730  }
   731  
   732  func (c *roomServiceJSONClient) ListRooms(ctx context.Context, in *ListRoomsRequest) (*ListRoomsResponse, error) {
   733  	ctx = ctxsetters.WithPackageName(ctx, "livekit")
   734  	ctx = ctxsetters.WithServiceName(ctx, "RoomService")
   735  	ctx = ctxsetters.WithMethodName(ctx, "ListRooms")
   736  	caller := c.callListRooms
   737  	if c.interceptor != nil {
   738  		caller = func(ctx context.Context, req *ListRoomsRequest) (*ListRoomsResponse, error) {
   739  			resp, err := c.interceptor(
   740  				func(ctx context.Context, req interface{}) (interface{}, error) {
   741  					typedReq, ok := req.(*ListRoomsRequest)
   742  					if !ok {
   743  						return nil, twirp.InternalError("failed type assertion req.(*ListRoomsRequest) when calling interceptor")
   744  					}
   745  					return c.callListRooms(ctx, typedReq)
   746  				},
   747  			)(ctx, req)
   748  			if resp != nil {
   749  				typedResp, ok := resp.(*ListRoomsResponse)
   750  				if !ok {
   751  					return nil, twirp.InternalError("failed type assertion resp.(*ListRoomsResponse) when calling interceptor")
   752  				}
   753  				return typedResp, err
   754  			}
   755  			return nil, err
   756  		}
   757  	}
   758  	return caller(ctx, in)
   759  }
   760  
   761  func (c *roomServiceJSONClient) callListRooms(ctx context.Context, in *ListRoomsRequest) (*ListRoomsResponse, error) {
   762  	out := new(ListRoomsResponse)
   763  	ctx, err := doJSONRequest(ctx, c.client, c.opts.Hooks, c.urls[1], in, out)
   764  	if err != nil {
   765  		twerr, ok := err.(twirp.Error)
   766  		if !ok {
   767  			twerr = twirp.InternalErrorWith(err)
   768  		}
   769  		callClientError(ctx, c.opts.Hooks, twerr)
   770  		return nil, err
   771  	}
   772  
   773  	callClientResponseReceived(ctx, c.opts.Hooks)
   774  
   775  	return out, nil
   776  }
   777  
   778  func (c *roomServiceJSONClient) DeleteRoom(ctx context.Context, in *DeleteRoomRequest) (*DeleteRoomResponse, error) {
   779  	ctx = ctxsetters.WithPackageName(ctx, "livekit")
   780  	ctx = ctxsetters.WithServiceName(ctx, "RoomService")
   781  	ctx = ctxsetters.WithMethodName(ctx, "DeleteRoom")
   782  	caller := c.callDeleteRoom
   783  	if c.interceptor != nil {
   784  		caller = func(ctx context.Context, req *DeleteRoomRequest) (*DeleteRoomResponse, error) {
   785  			resp, err := c.interceptor(
   786  				func(ctx context.Context, req interface{}) (interface{}, error) {
   787  					typedReq, ok := req.(*DeleteRoomRequest)
   788  					if !ok {
   789  						return nil, twirp.InternalError("failed type assertion req.(*DeleteRoomRequest) when calling interceptor")
   790  					}
   791  					return c.callDeleteRoom(ctx, typedReq)
   792  				},
   793  			)(ctx, req)
   794  			if resp != nil {
   795  				typedResp, ok := resp.(*DeleteRoomResponse)
   796  				if !ok {
   797  					return nil, twirp.InternalError("failed type assertion resp.(*DeleteRoomResponse) when calling interceptor")
   798  				}
   799  				return typedResp, err
   800  			}
   801  			return nil, err
   802  		}
   803  	}
   804  	return caller(ctx, in)
   805  }
   806  
   807  func (c *roomServiceJSONClient) callDeleteRoom(ctx context.Context, in *DeleteRoomRequest) (*DeleteRoomResponse, error) {
   808  	out := new(DeleteRoomResponse)
   809  	ctx, err := doJSONRequest(ctx, c.client, c.opts.Hooks, c.urls[2], in, out)
   810  	if err != nil {
   811  		twerr, ok := err.(twirp.Error)
   812  		if !ok {
   813  			twerr = twirp.InternalErrorWith(err)
   814  		}
   815  		callClientError(ctx, c.opts.Hooks, twerr)
   816  		return nil, err
   817  	}
   818  
   819  	callClientResponseReceived(ctx, c.opts.Hooks)
   820  
   821  	return out, nil
   822  }
   823  
   824  func (c *roomServiceJSONClient) ListParticipants(ctx context.Context, in *ListParticipantsRequest) (*ListParticipantsResponse, error) {
   825  	ctx = ctxsetters.WithPackageName(ctx, "livekit")
   826  	ctx = ctxsetters.WithServiceName(ctx, "RoomService")
   827  	ctx = ctxsetters.WithMethodName(ctx, "ListParticipants")
   828  	caller := c.callListParticipants
   829  	if c.interceptor != nil {
   830  		caller = func(ctx context.Context, req *ListParticipantsRequest) (*ListParticipantsResponse, error) {
   831  			resp, err := c.interceptor(
   832  				func(ctx context.Context, req interface{}) (interface{}, error) {
   833  					typedReq, ok := req.(*ListParticipantsRequest)
   834  					if !ok {
   835  						return nil, twirp.InternalError("failed type assertion req.(*ListParticipantsRequest) when calling interceptor")
   836  					}
   837  					return c.callListParticipants(ctx, typedReq)
   838  				},
   839  			)(ctx, req)
   840  			if resp != nil {
   841  				typedResp, ok := resp.(*ListParticipantsResponse)
   842  				if !ok {
   843  					return nil, twirp.InternalError("failed type assertion resp.(*ListParticipantsResponse) when calling interceptor")
   844  				}
   845  				return typedResp, err
   846  			}
   847  			return nil, err
   848  		}
   849  	}
   850  	return caller(ctx, in)
   851  }
   852  
   853  func (c *roomServiceJSONClient) callListParticipants(ctx context.Context, in *ListParticipantsRequest) (*ListParticipantsResponse, error) {
   854  	out := new(ListParticipantsResponse)
   855  	ctx, err := doJSONRequest(ctx, c.client, c.opts.Hooks, c.urls[3], in, out)
   856  	if err != nil {
   857  		twerr, ok := err.(twirp.Error)
   858  		if !ok {
   859  			twerr = twirp.InternalErrorWith(err)
   860  		}
   861  		callClientError(ctx, c.opts.Hooks, twerr)
   862  		return nil, err
   863  	}
   864  
   865  	callClientResponseReceived(ctx, c.opts.Hooks)
   866  
   867  	return out, nil
   868  }
   869  
   870  func (c *roomServiceJSONClient) GetParticipant(ctx context.Context, in *RoomParticipantIdentity) (*ParticipantInfo, error) {
   871  	ctx = ctxsetters.WithPackageName(ctx, "livekit")
   872  	ctx = ctxsetters.WithServiceName(ctx, "RoomService")
   873  	ctx = ctxsetters.WithMethodName(ctx, "GetParticipant")
   874  	caller := c.callGetParticipant
   875  	if c.interceptor != nil {
   876  		caller = func(ctx context.Context, req *RoomParticipantIdentity) (*ParticipantInfo, error) {
   877  			resp, err := c.interceptor(
   878  				func(ctx context.Context, req interface{}) (interface{}, error) {
   879  					typedReq, ok := req.(*RoomParticipantIdentity)
   880  					if !ok {
   881  						return nil, twirp.InternalError("failed type assertion req.(*RoomParticipantIdentity) when calling interceptor")
   882  					}
   883  					return c.callGetParticipant(ctx, typedReq)
   884  				},
   885  			)(ctx, req)
   886  			if resp != nil {
   887  				typedResp, ok := resp.(*ParticipantInfo)
   888  				if !ok {
   889  					return nil, twirp.InternalError("failed type assertion resp.(*ParticipantInfo) when calling interceptor")
   890  				}
   891  				return typedResp, err
   892  			}
   893  			return nil, err
   894  		}
   895  	}
   896  	return caller(ctx, in)
   897  }
   898  
   899  func (c *roomServiceJSONClient) callGetParticipant(ctx context.Context, in *RoomParticipantIdentity) (*ParticipantInfo, error) {
   900  	out := new(ParticipantInfo)
   901  	ctx, err := doJSONRequest(ctx, c.client, c.opts.Hooks, c.urls[4], in, out)
   902  	if err != nil {
   903  		twerr, ok := err.(twirp.Error)
   904  		if !ok {
   905  			twerr = twirp.InternalErrorWith(err)
   906  		}
   907  		callClientError(ctx, c.opts.Hooks, twerr)
   908  		return nil, err
   909  	}
   910  
   911  	callClientResponseReceived(ctx, c.opts.Hooks)
   912  
   913  	return out, nil
   914  }
   915  
   916  func (c *roomServiceJSONClient) RemoveParticipant(ctx context.Context, in *RoomParticipantIdentity) (*RemoveParticipantResponse, error) {
   917  	ctx = ctxsetters.WithPackageName(ctx, "livekit")
   918  	ctx = ctxsetters.WithServiceName(ctx, "RoomService")
   919  	ctx = ctxsetters.WithMethodName(ctx, "RemoveParticipant")
   920  	caller := c.callRemoveParticipant
   921  	if c.interceptor != nil {
   922  		caller = func(ctx context.Context, req *RoomParticipantIdentity) (*RemoveParticipantResponse, error) {
   923  			resp, err := c.interceptor(
   924  				func(ctx context.Context, req interface{}) (interface{}, error) {
   925  					typedReq, ok := req.(*RoomParticipantIdentity)
   926  					if !ok {
   927  						return nil, twirp.InternalError("failed type assertion req.(*RoomParticipantIdentity) when calling interceptor")
   928  					}
   929  					return c.callRemoveParticipant(ctx, typedReq)
   930  				},
   931  			)(ctx, req)
   932  			if resp != nil {
   933  				typedResp, ok := resp.(*RemoveParticipantResponse)
   934  				if !ok {
   935  					return nil, twirp.InternalError("failed type assertion resp.(*RemoveParticipantResponse) when calling interceptor")
   936  				}
   937  				return typedResp, err
   938  			}
   939  			return nil, err
   940  		}
   941  	}
   942  	return caller(ctx, in)
   943  }
   944  
   945  func (c *roomServiceJSONClient) callRemoveParticipant(ctx context.Context, in *RoomParticipantIdentity) (*RemoveParticipantResponse, error) {
   946  	out := new(RemoveParticipantResponse)
   947  	ctx, err := doJSONRequest(ctx, c.client, c.opts.Hooks, c.urls[5], in, out)
   948  	if err != nil {
   949  		twerr, ok := err.(twirp.Error)
   950  		if !ok {
   951  			twerr = twirp.InternalErrorWith(err)
   952  		}
   953  		callClientError(ctx, c.opts.Hooks, twerr)
   954  		return nil, err
   955  	}
   956  
   957  	callClientResponseReceived(ctx, c.opts.Hooks)
   958  
   959  	return out, nil
   960  }
   961  
   962  func (c *roomServiceJSONClient) MutePublishedTrack(ctx context.Context, in *MuteRoomTrackRequest) (*MuteRoomTrackResponse, error) {
   963  	ctx = ctxsetters.WithPackageName(ctx, "livekit")
   964  	ctx = ctxsetters.WithServiceName(ctx, "RoomService")
   965  	ctx = ctxsetters.WithMethodName(ctx, "MutePublishedTrack")
   966  	caller := c.callMutePublishedTrack
   967  	if c.interceptor != nil {
   968  		caller = func(ctx context.Context, req *MuteRoomTrackRequest) (*MuteRoomTrackResponse, error) {
   969  			resp, err := c.interceptor(
   970  				func(ctx context.Context, req interface{}) (interface{}, error) {
   971  					typedReq, ok := req.(*MuteRoomTrackRequest)
   972  					if !ok {
   973  						return nil, twirp.InternalError("failed type assertion req.(*MuteRoomTrackRequest) when calling interceptor")
   974  					}
   975  					return c.callMutePublishedTrack(ctx, typedReq)
   976  				},
   977  			)(ctx, req)
   978  			if resp != nil {
   979  				typedResp, ok := resp.(*MuteRoomTrackResponse)
   980  				if !ok {
   981  					return nil, twirp.InternalError("failed type assertion resp.(*MuteRoomTrackResponse) when calling interceptor")
   982  				}
   983  				return typedResp, err
   984  			}
   985  			return nil, err
   986  		}
   987  	}
   988  	return caller(ctx, in)
   989  }
   990  
   991  func (c *roomServiceJSONClient) callMutePublishedTrack(ctx context.Context, in *MuteRoomTrackRequest) (*MuteRoomTrackResponse, error) {
   992  	out := new(MuteRoomTrackResponse)
   993  	ctx, err := doJSONRequest(ctx, c.client, c.opts.Hooks, c.urls[6], in, out)
   994  	if err != nil {
   995  		twerr, ok := err.(twirp.Error)
   996  		if !ok {
   997  			twerr = twirp.InternalErrorWith(err)
   998  		}
   999  		callClientError(ctx, c.opts.Hooks, twerr)
  1000  		return nil, err
  1001  	}
  1002  
  1003  	callClientResponseReceived(ctx, c.opts.Hooks)
  1004  
  1005  	return out, nil
  1006  }
  1007  
  1008  func (c *roomServiceJSONClient) UpdateParticipant(ctx context.Context, in *UpdateParticipantRequest) (*ParticipantInfo, error) {
  1009  	ctx = ctxsetters.WithPackageName(ctx, "livekit")
  1010  	ctx = ctxsetters.WithServiceName(ctx, "RoomService")
  1011  	ctx = ctxsetters.WithMethodName(ctx, "UpdateParticipant")
  1012  	caller := c.callUpdateParticipant
  1013  	if c.interceptor != nil {
  1014  		caller = func(ctx context.Context, req *UpdateParticipantRequest) (*ParticipantInfo, error) {
  1015  			resp, err := c.interceptor(
  1016  				func(ctx context.Context, req interface{}) (interface{}, error) {
  1017  					typedReq, ok := req.(*UpdateParticipantRequest)
  1018  					if !ok {
  1019  						return nil, twirp.InternalError("failed type assertion req.(*UpdateParticipantRequest) when calling interceptor")
  1020  					}
  1021  					return c.callUpdateParticipant(ctx, typedReq)
  1022  				},
  1023  			)(ctx, req)
  1024  			if resp != nil {
  1025  				typedResp, ok := resp.(*ParticipantInfo)
  1026  				if !ok {
  1027  					return nil, twirp.InternalError("failed type assertion resp.(*ParticipantInfo) when calling interceptor")
  1028  				}
  1029  				return typedResp, err
  1030  			}
  1031  			return nil, err
  1032  		}
  1033  	}
  1034  	return caller(ctx, in)
  1035  }
  1036  
  1037  func (c *roomServiceJSONClient) callUpdateParticipant(ctx context.Context, in *UpdateParticipantRequest) (*ParticipantInfo, error) {
  1038  	out := new(ParticipantInfo)
  1039  	ctx, err := doJSONRequest(ctx, c.client, c.opts.Hooks, c.urls[7], in, out)
  1040  	if err != nil {
  1041  		twerr, ok := err.(twirp.Error)
  1042  		if !ok {
  1043  			twerr = twirp.InternalErrorWith(err)
  1044  		}
  1045  		callClientError(ctx, c.opts.Hooks, twerr)
  1046  		return nil, err
  1047  	}
  1048  
  1049  	callClientResponseReceived(ctx, c.opts.Hooks)
  1050  
  1051  	return out, nil
  1052  }
  1053  
  1054  func (c *roomServiceJSONClient) UpdateSubscriptions(ctx context.Context, in *UpdateSubscriptionsRequest) (*UpdateSubscriptionsResponse, error) {
  1055  	ctx = ctxsetters.WithPackageName(ctx, "livekit")
  1056  	ctx = ctxsetters.WithServiceName(ctx, "RoomService")
  1057  	ctx = ctxsetters.WithMethodName(ctx, "UpdateSubscriptions")
  1058  	caller := c.callUpdateSubscriptions
  1059  	if c.interceptor != nil {
  1060  		caller = func(ctx context.Context, req *UpdateSubscriptionsRequest) (*UpdateSubscriptionsResponse, error) {
  1061  			resp, err := c.interceptor(
  1062  				func(ctx context.Context, req interface{}) (interface{}, error) {
  1063  					typedReq, ok := req.(*UpdateSubscriptionsRequest)
  1064  					if !ok {
  1065  						return nil, twirp.InternalError("failed type assertion req.(*UpdateSubscriptionsRequest) when calling interceptor")
  1066  					}
  1067  					return c.callUpdateSubscriptions(ctx, typedReq)
  1068  				},
  1069  			)(ctx, req)
  1070  			if resp != nil {
  1071  				typedResp, ok := resp.(*UpdateSubscriptionsResponse)
  1072  				if !ok {
  1073  					return nil, twirp.InternalError("failed type assertion resp.(*UpdateSubscriptionsResponse) when calling interceptor")
  1074  				}
  1075  				return typedResp, err
  1076  			}
  1077  			return nil, err
  1078  		}
  1079  	}
  1080  	return caller(ctx, in)
  1081  }
  1082  
  1083  func (c *roomServiceJSONClient) callUpdateSubscriptions(ctx context.Context, in *UpdateSubscriptionsRequest) (*UpdateSubscriptionsResponse, error) {
  1084  	out := new(UpdateSubscriptionsResponse)
  1085  	ctx, err := doJSONRequest(ctx, c.client, c.opts.Hooks, c.urls[8], in, out)
  1086  	if err != nil {
  1087  		twerr, ok := err.(twirp.Error)
  1088  		if !ok {
  1089  			twerr = twirp.InternalErrorWith(err)
  1090  		}
  1091  		callClientError(ctx, c.opts.Hooks, twerr)
  1092  		return nil, err
  1093  	}
  1094  
  1095  	callClientResponseReceived(ctx, c.opts.Hooks)
  1096  
  1097  	return out, nil
  1098  }
  1099  
  1100  func (c *roomServiceJSONClient) SendData(ctx context.Context, in *SendDataRequest) (*SendDataResponse, error) {
  1101  	ctx = ctxsetters.WithPackageName(ctx, "livekit")
  1102  	ctx = ctxsetters.WithServiceName(ctx, "RoomService")
  1103  	ctx = ctxsetters.WithMethodName(ctx, "SendData")
  1104  	caller := c.callSendData
  1105  	if c.interceptor != nil {
  1106  		caller = func(ctx context.Context, req *SendDataRequest) (*SendDataResponse, error) {
  1107  			resp, err := c.interceptor(
  1108  				func(ctx context.Context, req interface{}) (interface{}, error) {
  1109  					typedReq, ok := req.(*SendDataRequest)
  1110  					if !ok {
  1111  						return nil, twirp.InternalError("failed type assertion req.(*SendDataRequest) when calling interceptor")
  1112  					}
  1113  					return c.callSendData(ctx, typedReq)
  1114  				},
  1115  			)(ctx, req)
  1116  			if resp != nil {
  1117  				typedResp, ok := resp.(*SendDataResponse)
  1118  				if !ok {
  1119  					return nil, twirp.InternalError("failed type assertion resp.(*SendDataResponse) when calling interceptor")
  1120  				}
  1121  				return typedResp, err
  1122  			}
  1123  			return nil, err
  1124  		}
  1125  	}
  1126  	return caller(ctx, in)
  1127  }
  1128  
  1129  func (c *roomServiceJSONClient) callSendData(ctx context.Context, in *SendDataRequest) (*SendDataResponse, error) {
  1130  	out := new(SendDataResponse)
  1131  	ctx, err := doJSONRequest(ctx, c.client, c.opts.Hooks, c.urls[9], in, out)
  1132  	if err != nil {
  1133  		twerr, ok := err.(twirp.Error)
  1134  		if !ok {
  1135  			twerr = twirp.InternalErrorWith(err)
  1136  		}
  1137  		callClientError(ctx, c.opts.Hooks, twerr)
  1138  		return nil, err
  1139  	}
  1140  
  1141  	callClientResponseReceived(ctx, c.opts.Hooks)
  1142  
  1143  	return out, nil
  1144  }
  1145  
  1146  func (c *roomServiceJSONClient) UpdateRoomMetadata(ctx context.Context, in *UpdateRoomMetadataRequest) (*Room, error) {
  1147  	ctx = ctxsetters.WithPackageName(ctx, "livekit")
  1148  	ctx = ctxsetters.WithServiceName(ctx, "RoomService")
  1149  	ctx = ctxsetters.WithMethodName(ctx, "UpdateRoomMetadata")
  1150  	caller := c.callUpdateRoomMetadata
  1151  	if c.interceptor != nil {
  1152  		caller = func(ctx context.Context, req *UpdateRoomMetadataRequest) (*Room, error) {
  1153  			resp, err := c.interceptor(
  1154  				func(ctx context.Context, req interface{}) (interface{}, error) {
  1155  					typedReq, ok := req.(*UpdateRoomMetadataRequest)
  1156  					if !ok {
  1157  						return nil, twirp.InternalError("failed type assertion req.(*UpdateRoomMetadataRequest) when calling interceptor")
  1158  					}
  1159  					return c.callUpdateRoomMetadata(ctx, typedReq)
  1160  				},
  1161  			)(ctx, req)
  1162  			if resp != nil {
  1163  				typedResp, ok := resp.(*Room)
  1164  				if !ok {
  1165  					return nil, twirp.InternalError("failed type assertion resp.(*Room) when calling interceptor")
  1166  				}
  1167  				return typedResp, err
  1168  			}
  1169  			return nil, err
  1170  		}
  1171  	}
  1172  	return caller(ctx, in)
  1173  }
  1174  
  1175  func (c *roomServiceJSONClient) callUpdateRoomMetadata(ctx context.Context, in *UpdateRoomMetadataRequest) (*Room, error) {
  1176  	out := new(Room)
  1177  	ctx, err := doJSONRequest(ctx, c.client, c.opts.Hooks, c.urls[10], in, out)
  1178  	if err != nil {
  1179  		twerr, ok := err.(twirp.Error)
  1180  		if !ok {
  1181  			twerr = twirp.InternalErrorWith(err)
  1182  		}
  1183  		callClientError(ctx, c.opts.Hooks, twerr)
  1184  		return nil, err
  1185  	}
  1186  
  1187  	callClientResponseReceived(ctx, c.opts.Hooks)
  1188  
  1189  	return out, nil
  1190  }
  1191  
  1192  // ==========================
  1193  // RoomService Server Handler
  1194  // ==========================
  1195  
  1196  type roomServiceServer struct {
  1197  	RoomService
  1198  	interceptor      twirp.Interceptor
  1199  	hooks            *twirp.ServerHooks
  1200  	pathPrefix       string // prefix for routing
  1201  	jsonSkipDefaults bool   // do not include unpopulated fields (default values) in the response
  1202  	jsonCamelCase    bool   // JSON fields are serialized as lowerCamelCase rather than keeping the original proto names
  1203  }
  1204  
  1205  // NewRoomServiceServer builds a TwirpServer that can be used as an http.Handler to handle
  1206  // HTTP requests that are routed to the right method in the provided svc implementation.
  1207  // The opts are twirp.ServerOption modifiers, for example twirp.WithServerHooks(hooks).
  1208  func NewRoomServiceServer(svc RoomService, opts ...interface{}) TwirpServer {
  1209  	serverOpts := newServerOpts(opts)
  1210  
  1211  	// Using ReadOpt allows backwards and forwards compatibility with new options in the future
  1212  	jsonSkipDefaults := false
  1213  	_ = serverOpts.ReadOpt("jsonSkipDefaults", &jsonSkipDefaults)
  1214  	jsonCamelCase := false
  1215  	_ = serverOpts.ReadOpt("jsonCamelCase", &jsonCamelCase)
  1216  	var pathPrefix string
  1217  	if ok := serverOpts.ReadOpt("pathPrefix", &pathPrefix); !ok {
  1218  		pathPrefix = "/twirp" // default prefix
  1219  	}
  1220  
  1221  	return &roomServiceServer{
  1222  		RoomService:      svc,
  1223  		hooks:            serverOpts.Hooks,
  1224  		interceptor:      twirp.ChainInterceptors(serverOpts.Interceptors...),
  1225  		pathPrefix:       pathPrefix,
  1226  		jsonSkipDefaults: jsonSkipDefaults,
  1227  		jsonCamelCase:    jsonCamelCase,
  1228  	}
  1229  }
  1230  
  1231  // writeError writes an HTTP response with a valid Twirp error format, and triggers hooks.
  1232  // If err is not a twirp.Error, it will get wrapped with twirp.InternalErrorWith(err)
  1233  func (s *roomServiceServer) writeError(ctx context.Context, resp http.ResponseWriter, err error) {
  1234  	writeError(ctx, resp, err, s.hooks)
  1235  }
  1236  
  1237  // handleRequestBodyError is used to handle error when the twirp server cannot read request
  1238  func (s *roomServiceServer) handleRequestBodyError(ctx context.Context, resp http.ResponseWriter, msg string, err error) {
  1239  	if context.Canceled == ctx.Err() {
  1240  		s.writeError(ctx, resp, twirp.NewError(twirp.Canceled, "failed to read request: context canceled"))
  1241  		return
  1242  	}
  1243  	if context.DeadlineExceeded == ctx.Err() {
  1244  		s.writeError(ctx, resp, twirp.NewError(twirp.DeadlineExceeded, "failed to read request: deadline exceeded"))
  1245  		return
  1246  	}
  1247  	s.writeError(ctx, resp, twirp.WrapError(malformedRequestError(msg), err))
  1248  }
  1249  
  1250  // RoomServicePathPrefix is a convenience constant that may identify URL paths.
  1251  // Should be used with caution, it only matches routes generated by Twirp Go clients,
  1252  // with the default "/twirp" prefix and default CamelCase service and method names.
  1253  // More info: https://twitchtv.github.io/twirp/docs/routing.html
  1254  const RoomServicePathPrefix = "/twirp/livekit.RoomService/"
  1255  
  1256  func (s *roomServiceServer) ServeHTTP(resp http.ResponseWriter, req *http.Request) {
  1257  	ctx := req.Context()
  1258  	ctx = ctxsetters.WithPackageName(ctx, "livekit")
  1259  	ctx = ctxsetters.WithServiceName(ctx, "RoomService")
  1260  	ctx = ctxsetters.WithResponseWriter(ctx, resp)
  1261  
  1262  	var err error
  1263  	ctx, err = callRequestReceived(ctx, s.hooks)
  1264  	if err != nil {
  1265  		s.writeError(ctx, resp, err)
  1266  		return
  1267  	}
  1268  
  1269  	if req.Method != "POST" {
  1270  		msg := fmt.Sprintf("unsupported method %q (only POST is allowed)", req.Method)
  1271  		s.writeError(ctx, resp, badRouteError(msg, req.Method, req.URL.Path))
  1272  		return
  1273  	}
  1274  
  1275  	// Verify path format: [<prefix>]/<package>.<Service>/<Method>
  1276  	prefix, pkgService, method := parseTwirpPath(req.URL.Path)
  1277  	if pkgService != "livekit.RoomService" {
  1278  		msg := fmt.Sprintf("no handler for path %q", req.URL.Path)
  1279  		s.writeError(ctx, resp, badRouteError(msg, req.Method, req.URL.Path))
  1280  		return
  1281  	}
  1282  	if prefix != s.pathPrefix {
  1283  		msg := fmt.Sprintf("invalid path prefix %q, expected %q, on path %q", prefix, s.pathPrefix, req.URL.Path)
  1284  		s.writeError(ctx, resp, badRouteError(msg, req.Method, req.URL.Path))
  1285  		return
  1286  	}
  1287  
  1288  	switch method {
  1289  	case "CreateRoom":
  1290  		s.serveCreateRoom(ctx, resp, req)
  1291  		return
  1292  	case "ListRooms":
  1293  		s.serveListRooms(ctx, resp, req)
  1294  		return
  1295  	case "DeleteRoom":
  1296  		s.serveDeleteRoom(ctx, resp, req)
  1297  		return
  1298  	case "ListParticipants":
  1299  		s.serveListParticipants(ctx, resp, req)
  1300  		return
  1301  	case "GetParticipant":
  1302  		s.serveGetParticipant(ctx, resp, req)
  1303  		return
  1304  	case "RemoveParticipant":
  1305  		s.serveRemoveParticipant(ctx, resp, req)
  1306  		return
  1307  	case "MutePublishedTrack":
  1308  		s.serveMutePublishedTrack(ctx, resp, req)
  1309  		return
  1310  	case "UpdateParticipant":
  1311  		s.serveUpdateParticipant(ctx, resp, req)
  1312  		return
  1313  	case "UpdateSubscriptions":
  1314  		s.serveUpdateSubscriptions(ctx, resp, req)
  1315  		return
  1316  	case "SendData":
  1317  		s.serveSendData(ctx, resp, req)
  1318  		return
  1319  	case "UpdateRoomMetadata":
  1320  		s.serveUpdateRoomMetadata(ctx, resp, req)
  1321  		return
  1322  	default:
  1323  		msg := fmt.Sprintf("no handler for path %q", req.URL.Path)
  1324  		s.writeError(ctx, resp, badRouteError(msg, req.Method, req.URL.Path))
  1325  		return
  1326  	}
  1327  }
  1328  
  1329  func (s *roomServiceServer) serveCreateRoom(ctx context.Context, resp http.ResponseWriter, req *http.Request) {
  1330  	header := req.Header.Get("Content-Type")
  1331  	i := strings.Index(header, ";")
  1332  	if i == -1 {
  1333  		i = len(header)
  1334  	}
  1335  	switch strings.TrimSpace(strings.ToLower(header[:i])) {
  1336  	case "application/json":
  1337  		s.serveCreateRoomJSON(ctx, resp, req)
  1338  	case "application/protobuf":
  1339  		s.serveCreateRoomProtobuf(ctx, resp, req)
  1340  	default:
  1341  		msg := fmt.Sprintf("unexpected Content-Type: %q", req.Header.Get("Content-Type"))
  1342  		twerr := badRouteError(msg, req.Method, req.URL.Path)
  1343  		s.writeError(ctx, resp, twerr)
  1344  	}
  1345  }
  1346  
  1347  func (s *roomServiceServer) serveCreateRoomJSON(ctx context.Context, resp http.ResponseWriter, req *http.Request) {
  1348  	var err error
  1349  	ctx = ctxsetters.WithMethodName(ctx, "CreateRoom")
  1350  	ctx, err = callRequestRouted(ctx, s.hooks)
  1351  	if err != nil {
  1352  		s.writeError(ctx, resp, err)
  1353  		return
  1354  	}
  1355  
  1356  	d := json.NewDecoder(req.Body)
  1357  	rawReqBody := json.RawMessage{}
  1358  	if err := d.Decode(&rawReqBody); err != nil {
  1359  		s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err)
  1360  		return
  1361  	}
  1362  	reqContent := new(CreateRoomRequest)
  1363  	unmarshaler := protojson.UnmarshalOptions{DiscardUnknown: true}
  1364  	if err = unmarshaler.Unmarshal(rawReqBody, reqContent); err != nil {
  1365  		s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err)
  1366  		return
  1367  	}
  1368  
  1369  	handler := s.RoomService.CreateRoom
  1370  	if s.interceptor != nil {
  1371  		handler = func(ctx context.Context, req *CreateRoomRequest) (*Room, error) {
  1372  			resp, err := s.interceptor(
  1373  				func(ctx context.Context, req interface{}) (interface{}, error) {
  1374  					typedReq, ok := req.(*CreateRoomRequest)
  1375  					if !ok {
  1376  						return nil, twirp.InternalError("failed type assertion req.(*CreateRoomRequest) when calling interceptor")
  1377  					}
  1378  					return s.RoomService.CreateRoom(ctx, typedReq)
  1379  				},
  1380  			)(ctx, req)
  1381  			if resp != nil {
  1382  				typedResp, ok := resp.(*Room)
  1383  				if !ok {
  1384  					return nil, twirp.InternalError("failed type assertion resp.(*Room) when calling interceptor")
  1385  				}
  1386  				return typedResp, err
  1387  			}
  1388  			return nil, err
  1389  		}
  1390  	}
  1391  
  1392  	// Call service method
  1393  	var respContent *Room
  1394  	func() {
  1395  		defer ensurePanicResponses(ctx, resp, s.hooks)
  1396  		respContent, err = handler(ctx, reqContent)
  1397  	}()
  1398  
  1399  	if err != nil {
  1400  		s.writeError(ctx, resp, err)
  1401  		return
  1402  	}
  1403  	if respContent == nil {
  1404  		s.writeError(ctx, resp, twirp.InternalError("received a nil *Room and nil error while calling CreateRoom. nil responses are not supported"))
  1405  		return
  1406  	}
  1407  
  1408  	ctx = callResponsePrepared(ctx, s.hooks)
  1409  
  1410  	marshaler := &protojson.MarshalOptions{UseProtoNames: !s.jsonCamelCase, EmitUnpopulated: !s.jsonSkipDefaults}
  1411  	respBytes, err := marshaler.Marshal(respContent)
  1412  	if err != nil {
  1413  		s.writeError(ctx, resp, wrapInternal(err, "failed to marshal json response"))
  1414  		return
  1415  	}
  1416  
  1417  	ctx = ctxsetters.WithStatusCode(ctx, http.StatusOK)
  1418  	resp.Header().Set("Content-Type", "application/json")
  1419  	resp.Header().Set("Content-Length", strconv.Itoa(len(respBytes)))
  1420  	resp.WriteHeader(http.StatusOK)
  1421  
  1422  	if n, err := resp.Write(respBytes); err != nil {
  1423  		msg := fmt.Sprintf("failed to write response, %d of %d bytes written: %s", n, len(respBytes), err.Error())
  1424  		twerr := twirp.NewError(twirp.Unknown, msg)
  1425  		ctx = callError(ctx, s.hooks, twerr)
  1426  	}
  1427  	callResponseSent(ctx, s.hooks)
  1428  }
  1429  
  1430  func (s *roomServiceServer) serveCreateRoomProtobuf(ctx context.Context, resp http.ResponseWriter, req *http.Request) {
  1431  	var err error
  1432  	ctx = ctxsetters.WithMethodName(ctx, "CreateRoom")
  1433  	ctx, err = callRequestRouted(ctx, s.hooks)
  1434  	if err != nil {
  1435  		s.writeError(ctx, resp, err)
  1436  		return
  1437  	}
  1438  
  1439  	buf, err := io.ReadAll(req.Body)
  1440  	if err != nil {
  1441  		s.handleRequestBodyError(ctx, resp, "failed to read request body", err)
  1442  		return
  1443  	}
  1444  	reqContent := new(CreateRoomRequest)
  1445  	if err = proto.Unmarshal(buf, reqContent); err != nil {
  1446  		s.writeError(ctx, resp, malformedRequestError("the protobuf request could not be decoded"))
  1447  		return
  1448  	}
  1449  
  1450  	handler := s.RoomService.CreateRoom
  1451  	if s.interceptor != nil {
  1452  		handler = func(ctx context.Context, req *CreateRoomRequest) (*Room, error) {
  1453  			resp, err := s.interceptor(
  1454  				func(ctx context.Context, req interface{}) (interface{}, error) {
  1455  					typedReq, ok := req.(*CreateRoomRequest)
  1456  					if !ok {
  1457  						return nil, twirp.InternalError("failed type assertion req.(*CreateRoomRequest) when calling interceptor")
  1458  					}
  1459  					return s.RoomService.CreateRoom(ctx, typedReq)
  1460  				},
  1461  			)(ctx, req)
  1462  			if resp != nil {
  1463  				typedResp, ok := resp.(*Room)
  1464  				if !ok {
  1465  					return nil, twirp.InternalError("failed type assertion resp.(*Room) when calling interceptor")
  1466  				}
  1467  				return typedResp, err
  1468  			}
  1469  			return nil, err
  1470  		}
  1471  	}
  1472  
  1473  	// Call service method
  1474  	var respContent *Room
  1475  	func() {
  1476  		defer ensurePanicResponses(ctx, resp, s.hooks)
  1477  		respContent, err = handler(ctx, reqContent)
  1478  	}()
  1479  
  1480  	if err != nil {
  1481  		s.writeError(ctx, resp, err)
  1482  		return
  1483  	}
  1484  	if respContent == nil {
  1485  		s.writeError(ctx, resp, twirp.InternalError("received a nil *Room and nil error while calling CreateRoom. nil responses are not supported"))
  1486  		return
  1487  	}
  1488  
  1489  	ctx = callResponsePrepared(ctx, s.hooks)
  1490  
  1491  	respBytes, err := proto.Marshal(respContent)
  1492  	if err != nil {
  1493  		s.writeError(ctx, resp, wrapInternal(err, "failed to marshal proto response"))
  1494  		return
  1495  	}
  1496  
  1497  	ctx = ctxsetters.WithStatusCode(ctx, http.StatusOK)
  1498  	resp.Header().Set("Content-Type", "application/protobuf")
  1499  	resp.Header().Set("Content-Length", strconv.Itoa(len(respBytes)))
  1500  	resp.WriteHeader(http.StatusOK)
  1501  	if n, err := resp.Write(respBytes); err != nil {
  1502  		msg := fmt.Sprintf("failed to write response, %d of %d bytes written: %s", n, len(respBytes), err.Error())
  1503  		twerr := twirp.NewError(twirp.Unknown, msg)
  1504  		ctx = callError(ctx, s.hooks, twerr)
  1505  	}
  1506  	callResponseSent(ctx, s.hooks)
  1507  }
  1508  
  1509  func (s *roomServiceServer) serveListRooms(ctx context.Context, resp http.ResponseWriter, req *http.Request) {
  1510  	header := req.Header.Get("Content-Type")
  1511  	i := strings.Index(header, ";")
  1512  	if i == -1 {
  1513  		i = len(header)
  1514  	}
  1515  	switch strings.TrimSpace(strings.ToLower(header[:i])) {
  1516  	case "application/json":
  1517  		s.serveListRoomsJSON(ctx, resp, req)
  1518  	case "application/protobuf":
  1519  		s.serveListRoomsProtobuf(ctx, resp, req)
  1520  	default:
  1521  		msg := fmt.Sprintf("unexpected Content-Type: %q", req.Header.Get("Content-Type"))
  1522  		twerr := badRouteError(msg, req.Method, req.URL.Path)
  1523  		s.writeError(ctx, resp, twerr)
  1524  	}
  1525  }
  1526  
  1527  func (s *roomServiceServer) serveListRoomsJSON(ctx context.Context, resp http.ResponseWriter, req *http.Request) {
  1528  	var err error
  1529  	ctx = ctxsetters.WithMethodName(ctx, "ListRooms")
  1530  	ctx, err = callRequestRouted(ctx, s.hooks)
  1531  	if err != nil {
  1532  		s.writeError(ctx, resp, err)
  1533  		return
  1534  	}
  1535  
  1536  	d := json.NewDecoder(req.Body)
  1537  	rawReqBody := json.RawMessage{}
  1538  	if err := d.Decode(&rawReqBody); err != nil {
  1539  		s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err)
  1540  		return
  1541  	}
  1542  	reqContent := new(ListRoomsRequest)
  1543  	unmarshaler := protojson.UnmarshalOptions{DiscardUnknown: true}
  1544  	if err = unmarshaler.Unmarshal(rawReqBody, reqContent); err != nil {
  1545  		s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err)
  1546  		return
  1547  	}
  1548  
  1549  	handler := s.RoomService.ListRooms
  1550  	if s.interceptor != nil {
  1551  		handler = func(ctx context.Context, req *ListRoomsRequest) (*ListRoomsResponse, error) {
  1552  			resp, err := s.interceptor(
  1553  				func(ctx context.Context, req interface{}) (interface{}, error) {
  1554  					typedReq, ok := req.(*ListRoomsRequest)
  1555  					if !ok {
  1556  						return nil, twirp.InternalError("failed type assertion req.(*ListRoomsRequest) when calling interceptor")
  1557  					}
  1558  					return s.RoomService.ListRooms(ctx, typedReq)
  1559  				},
  1560  			)(ctx, req)
  1561  			if resp != nil {
  1562  				typedResp, ok := resp.(*ListRoomsResponse)
  1563  				if !ok {
  1564  					return nil, twirp.InternalError("failed type assertion resp.(*ListRoomsResponse) when calling interceptor")
  1565  				}
  1566  				return typedResp, err
  1567  			}
  1568  			return nil, err
  1569  		}
  1570  	}
  1571  
  1572  	// Call service method
  1573  	var respContent *ListRoomsResponse
  1574  	func() {
  1575  		defer ensurePanicResponses(ctx, resp, s.hooks)
  1576  		respContent, err = handler(ctx, reqContent)
  1577  	}()
  1578  
  1579  	if err != nil {
  1580  		s.writeError(ctx, resp, err)
  1581  		return
  1582  	}
  1583  	if respContent == nil {
  1584  		s.writeError(ctx, resp, twirp.InternalError("received a nil *ListRoomsResponse and nil error while calling ListRooms. nil responses are not supported"))
  1585  		return
  1586  	}
  1587  
  1588  	ctx = callResponsePrepared(ctx, s.hooks)
  1589  
  1590  	marshaler := &protojson.MarshalOptions{UseProtoNames: !s.jsonCamelCase, EmitUnpopulated: !s.jsonSkipDefaults}
  1591  	respBytes, err := marshaler.Marshal(respContent)
  1592  	if err != nil {
  1593  		s.writeError(ctx, resp, wrapInternal(err, "failed to marshal json response"))
  1594  		return
  1595  	}
  1596  
  1597  	ctx = ctxsetters.WithStatusCode(ctx, http.StatusOK)
  1598  	resp.Header().Set("Content-Type", "application/json")
  1599  	resp.Header().Set("Content-Length", strconv.Itoa(len(respBytes)))
  1600  	resp.WriteHeader(http.StatusOK)
  1601  
  1602  	if n, err := resp.Write(respBytes); err != nil {
  1603  		msg := fmt.Sprintf("failed to write response, %d of %d bytes written: %s", n, len(respBytes), err.Error())
  1604  		twerr := twirp.NewError(twirp.Unknown, msg)
  1605  		ctx = callError(ctx, s.hooks, twerr)
  1606  	}
  1607  	callResponseSent(ctx, s.hooks)
  1608  }
  1609  
  1610  func (s *roomServiceServer) serveListRoomsProtobuf(ctx context.Context, resp http.ResponseWriter, req *http.Request) {
  1611  	var err error
  1612  	ctx = ctxsetters.WithMethodName(ctx, "ListRooms")
  1613  	ctx, err = callRequestRouted(ctx, s.hooks)
  1614  	if err != nil {
  1615  		s.writeError(ctx, resp, err)
  1616  		return
  1617  	}
  1618  
  1619  	buf, err := io.ReadAll(req.Body)
  1620  	if err != nil {
  1621  		s.handleRequestBodyError(ctx, resp, "failed to read request body", err)
  1622  		return
  1623  	}
  1624  	reqContent := new(ListRoomsRequest)
  1625  	if err = proto.Unmarshal(buf, reqContent); err != nil {
  1626  		s.writeError(ctx, resp, malformedRequestError("the protobuf request could not be decoded"))
  1627  		return
  1628  	}
  1629  
  1630  	handler := s.RoomService.ListRooms
  1631  	if s.interceptor != nil {
  1632  		handler = func(ctx context.Context, req *ListRoomsRequest) (*ListRoomsResponse, error) {
  1633  			resp, err := s.interceptor(
  1634  				func(ctx context.Context, req interface{}) (interface{}, error) {
  1635  					typedReq, ok := req.(*ListRoomsRequest)
  1636  					if !ok {
  1637  						return nil, twirp.InternalError("failed type assertion req.(*ListRoomsRequest) when calling interceptor")
  1638  					}
  1639  					return s.RoomService.ListRooms(ctx, typedReq)
  1640  				},
  1641  			)(ctx, req)
  1642  			if resp != nil {
  1643  				typedResp, ok := resp.(*ListRoomsResponse)
  1644  				if !ok {
  1645  					return nil, twirp.InternalError("failed type assertion resp.(*ListRoomsResponse) when calling interceptor")
  1646  				}
  1647  				return typedResp, err
  1648  			}
  1649  			return nil, err
  1650  		}
  1651  	}
  1652  
  1653  	// Call service method
  1654  	var respContent *ListRoomsResponse
  1655  	func() {
  1656  		defer ensurePanicResponses(ctx, resp, s.hooks)
  1657  		respContent, err = handler(ctx, reqContent)
  1658  	}()
  1659  
  1660  	if err != nil {
  1661  		s.writeError(ctx, resp, err)
  1662  		return
  1663  	}
  1664  	if respContent == nil {
  1665  		s.writeError(ctx, resp, twirp.InternalError("received a nil *ListRoomsResponse and nil error while calling ListRooms. nil responses are not supported"))
  1666  		return
  1667  	}
  1668  
  1669  	ctx = callResponsePrepared(ctx, s.hooks)
  1670  
  1671  	respBytes, err := proto.Marshal(respContent)
  1672  	if err != nil {
  1673  		s.writeError(ctx, resp, wrapInternal(err, "failed to marshal proto response"))
  1674  		return
  1675  	}
  1676  
  1677  	ctx = ctxsetters.WithStatusCode(ctx, http.StatusOK)
  1678  	resp.Header().Set("Content-Type", "application/protobuf")
  1679  	resp.Header().Set("Content-Length", strconv.Itoa(len(respBytes)))
  1680  	resp.WriteHeader(http.StatusOK)
  1681  	if n, err := resp.Write(respBytes); err != nil {
  1682  		msg := fmt.Sprintf("failed to write response, %d of %d bytes written: %s", n, len(respBytes), err.Error())
  1683  		twerr := twirp.NewError(twirp.Unknown, msg)
  1684  		ctx = callError(ctx, s.hooks, twerr)
  1685  	}
  1686  	callResponseSent(ctx, s.hooks)
  1687  }
  1688  
  1689  func (s *roomServiceServer) serveDeleteRoom(ctx context.Context, resp http.ResponseWriter, req *http.Request) {
  1690  	header := req.Header.Get("Content-Type")
  1691  	i := strings.Index(header, ";")
  1692  	if i == -1 {
  1693  		i = len(header)
  1694  	}
  1695  	switch strings.TrimSpace(strings.ToLower(header[:i])) {
  1696  	case "application/json":
  1697  		s.serveDeleteRoomJSON(ctx, resp, req)
  1698  	case "application/protobuf":
  1699  		s.serveDeleteRoomProtobuf(ctx, resp, req)
  1700  	default:
  1701  		msg := fmt.Sprintf("unexpected Content-Type: %q", req.Header.Get("Content-Type"))
  1702  		twerr := badRouteError(msg, req.Method, req.URL.Path)
  1703  		s.writeError(ctx, resp, twerr)
  1704  	}
  1705  }
  1706  
  1707  func (s *roomServiceServer) serveDeleteRoomJSON(ctx context.Context, resp http.ResponseWriter, req *http.Request) {
  1708  	var err error
  1709  	ctx = ctxsetters.WithMethodName(ctx, "DeleteRoom")
  1710  	ctx, err = callRequestRouted(ctx, s.hooks)
  1711  	if err != nil {
  1712  		s.writeError(ctx, resp, err)
  1713  		return
  1714  	}
  1715  
  1716  	d := json.NewDecoder(req.Body)
  1717  	rawReqBody := json.RawMessage{}
  1718  	if err := d.Decode(&rawReqBody); err != nil {
  1719  		s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err)
  1720  		return
  1721  	}
  1722  	reqContent := new(DeleteRoomRequest)
  1723  	unmarshaler := protojson.UnmarshalOptions{DiscardUnknown: true}
  1724  	if err = unmarshaler.Unmarshal(rawReqBody, reqContent); err != nil {
  1725  		s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err)
  1726  		return
  1727  	}
  1728  
  1729  	handler := s.RoomService.DeleteRoom
  1730  	if s.interceptor != nil {
  1731  		handler = func(ctx context.Context, req *DeleteRoomRequest) (*DeleteRoomResponse, error) {
  1732  			resp, err := s.interceptor(
  1733  				func(ctx context.Context, req interface{}) (interface{}, error) {
  1734  					typedReq, ok := req.(*DeleteRoomRequest)
  1735  					if !ok {
  1736  						return nil, twirp.InternalError("failed type assertion req.(*DeleteRoomRequest) when calling interceptor")
  1737  					}
  1738  					return s.RoomService.DeleteRoom(ctx, typedReq)
  1739  				},
  1740  			)(ctx, req)
  1741  			if resp != nil {
  1742  				typedResp, ok := resp.(*DeleteRoomResponse)
  1743  				if !ok {
  1744  					return nil, twirp.InternalError("failed type assertion resp.(*DeleteRoomResponse) when calling interceptor")
  1745  				}
  1746  				return typedResp, err
  1747  			}
  1748  			return nil, err
  1749  		}
  1750  	}
  1751  
  1752  	// Call service method
  1753  	var respContent *DeleteRoomResponse
  1754  	func() {
  1755  		defer ensurePanicResponses(ctx, resp, s.hooks)
  1756  		respContent, err = handler(ctx, reqContent)
  1757  	}()
  1758  
  1759  	if err != nil {
  1760  		s.writeError(ctx, resp, err)
  1761  		return
  1762  	}
  1763  	if respContent == nil {
  1764  		s.writeError(ctx, resp, twirp.InternalError("received a nil *DeleteRoomResponse and nil error while calling DeleteRoom. nil responses are not supported"))
  1765  		return
  1766  	}
  1767  
  1768  	ctx = callResponsePrepared(ctx, s.hooks)
  1769  
  1770  	marshaler := &protojson.MarshalOptions{UseProtoNames: !s.jsonCamelCase, EmitUnpopulated: !s.jsonSkipDefaults}
  1771  	respBytes, err := marshaler.Marshal(respContent)
  1772  	if err != nil {
  1773  		s.writeError(ctx, resp, wrapInternal(err, "failed to marshal json response"))
  1774  		return
  1775  	}
  1776  
  1777  	ctx = ctxsetters.WithStatusCode(ctx, http.StatusOK)
  1778  	resp.Header().Set("Content-Type", "application/json")
  1779  	resp.Header().Set("Content-Length", strconv.Itoa(len(respBytes)))
  1780  	resp.WriteHeader(http.StatusOK)
  1781  
  1782  	if n, err := resp.Write(respBytes); err != nil {
  1783  		msg := fmt.Sprintf("failed to write response, %d of %d bytes written: %s", n, len(respBytes), err.Error())
  1784  		twerr := twirp.NewError(twirp.Unknown, msg)
  1785  		ctx = callError(ctx, s.hooks, twerr)
  1786  	}
  1787  	callResponseSent(ctx, s.hooks)
  1788  }
  1789  
  1790  func (s *roomServiceServer) serveDeleteRoomProtobuf(ctx context.Context, resp http.ResponseWriter, req *http.Request) {
  1791  	var err error
  1792  	ctx = ctxsetters.WithMethodName(ctx, "DeleteRoom")
  1793  	ctx, err = callRequestRouted(ctx, s.hooks)
  1794  	if err != nil {
  1795  		s.writeError(ctx, resp, err)
  1796  		return
  1797  	}
  1798  
  1799  	buf, err := io.ReadAll(req.Body)
  1800  	if err != nil {
  1801  		s.handleRequestBodyError(ctx, resp, "failed to read request body", err)
  1802  		return
  1803  	}
  1804  	reqContent := new(DeleteRoomRequest)
  1805  	if err = proto.Unmarshal(buf, reqContent); err != nil {
  1806  		s.writeError(ctx, resp, malformedRequestError("the protobuf request could not be decoded"))
  1807  		return
  1808  	}
  1809  
  1810  	handler := s.RoomService.DeleteRoom
  1811  	if s.interceptor != nil {
  1812  		handler = func(ctx context.Context, req *DeleteRoomRequest) (*DeleteRoomResponse, error) {
  1813  			resp, err := s.interceptor(
  1814  				func(ctx context.Context, req interface{}) (interface{}, error) {
  1815  					typedReq, ok := req.(*DeleteRoomRequest)
  1816  					if !ok {
  1817  						return nil, twirp.InternalError("failed type assertion req.(*DeleteRoomRequest) when calling interceptor")
  1818  					}
  1819  					return s.RoomService.DeleteRoom(ctx, typedReq)
  1820  				},
  1821  			)(ctx, req)
  1822  			if resp != nil {
  1823  				typedResp, ok := resp.(*DeleteRoomResponse)
  1824  				if !ok {
  1825  					return nil, twirp.InternalError("failed type assertion resp.(*DeleteRoomResponse) when calling interceptor")
  1826  				}
  1827  				return typedResp, err
  1828  			}
  1829  			return nil, err
  1830  		}
  1831  	}
  1832  
  1833  	// Call service method
  1834  	var respContent *DeleteRoomResponse
  1835  	func() {
  1836  		defer ensurePanicResponses(ctx, resp, s.hooks)
  1837  		respContent, err = handler(ctx, reqContent)
  1838  	}()
  1839  
  1840  	if err != nil {
  1841  		s.writeError(ctx, resp, err)
  1842  		return
  1843  	}
  1844  	if respContent == nil {
  1845  		s.writeError(ctx, resp, twirp.InternalError("received a nil *DeleteRoomResponse and nil error while calling DeleteRoom. nil responses are not supported"))
  1846  		return
  1847  	}
  1848  
  1849  	ctx = callResponsePrepared(ctx, s.hooks)
  1850  
  1851  	respBytes, err := proto.Marshal(respContent)
  1852  	if err != nil {
  1853  		s.writeError(ctx, resp, wrapInternal(err, "failed to marshal proto response"))
  1854  		return
  1855  	}
  1856  
  1857  	ctx = ctxsetters.WithStatusCode(ctx, http.StatusOK)
  1858  	resp.Header().Set("Content-Type", "application/protobuf")
  1859  	resp.Header().Set("Content-Length", strconv.Itoa(len(respBytes)))
  1860  	resp.WriteHeader(http.StatusOK)
  1861  	if n, err := resp.Write(respBytes); err != nil {
  1862  		msg := fmt.Sprintf("failed to write response, %d of %d bytes written: %s", n, len(respBytes), err.Error())
  1863  		twerr := twirp.NewError(twirp.Unknown, msg)
  1864  		ctx = callError(ctx, s.hooks, twerr)
  1865  	}
  1866  	callResponseSent(ctx, s.hooks)
  1867  }
  1868  
  1869  func (s *roomServiceServer) serveListParticipants(ctx context.Context, resp http.ResponseWriter, req *http.Request) {
  1870  	header := req.Header.Get("Content-Type")
  1871  	i := strings.Index(header, ";")
  1872  	if i == -1 {
  1873  		i = len(header)
  1874  	}
  1875  	switch strings.TrimSpace(strings.ToLower(header[:i])) {
  1876  	case "application/json":
  1877  		s.serveListParticipantsJSON(ctx, resp, req)
  1878  	case "application/protobuf":
  1879  		s.serveListParticipantsProtobuf(ctx, resp, req)
  1880  	default:
  1881  		msg := fmt.Sprintf("unexpected Content-Type: %q", req.Header.Get("Content-Type"))
  1882  		twerr := badRouteError(msg, req.Method, req.URL.Path)
  1883  		s.writeError(ctx, resp, twerr)
  1884  	}
  1885  }
  1886  
  1887  func (s *roomServiceServer) serveListParticipantsJSON(ctx context.Context, resp http.ResponseWriter, req *http.Request) {
  1888  	var err error
  1889  	ctx = ctxsetters.WithMethodName(ctx, "ListParticipants")
  1890  	ctx, err = callRequestRouted(ctx, s.hooks)
  1891  	if err != nil {
  1892  		s.writeError(ctx, resp, err)
  1893  		return
  1894  	}
  1895  
  1896  	d := json.NewDecoder(req.Body)
  1897  	rawReqBody := json.RawMessage{}
  1898  	if err := d.Decode(&rawReqBody); err != nil {
  1899  		s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err)
  1900  		return
  1901  	}
  1902  	reqContent := new(ListParticipantsRequest)
  1903  	unmarshaler := protojson.UnmarshalOptions{DiscardUnknown: true}
  1904  	if err = unmarshaler.Unmarshal(rawReqBody, reqContent); err != nil {
  1905  		s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err)
  1906  		return
  1907  	}
  1908  
  1909  	handler := s.RoomService.ListParticipants
  1910  	if s.interceptor != nil {
  1911  		handler = func(ctx context.Context, req *ListParticipantsRequest) (*ListParticipantsResponse, error) {
  1912  			resp, err := s.interceptor(
  1913  				func(ctx context.Context, req interface{}) (interface{}, error) {
  1914  					typedReq, ok := req.(*ListParticipantsRequest)
  1915  					if !ok {
  1916  						return nil, twirp.InternalError("failed type assertion req.(*ListParticipantsRequest) when calling interceptor")
  1917  					}
  1918  					return s.RoomService.ListParticipants(ctx, typedReq)
  1919  				},
  1920  			)(ctx, req)
  1921  			if resp != nil {
  1922  				typedResp, ok := resp.(*ListParticipantsResponse)
  1923  				if !ok {
  1924  					return nil, twirp.InternalError("failed type assertion resp.(*ListParticipantsResponse) when calling interceptor")
  1925  				}
  1926  				return typedResp, err
  1927  			}
  1928  			return nil, err
  1929  		}
  1930  	}
  1931  
  1932  	// Call service method
  1933  	var respContent *ListParticipantsResponse
  1934  	func() {
  1935  		defer ensurePanicResponses(ctx, resp, s.hooks)
  1936  		respContent, err = handler(ctx, reqContent)
  1937  	}()
  1938  
  1939  	if err != nil {
  1940  		s.writeError(ctx, resp, err)
  1941  		return
  1942  	}
  1943  	if respContent == nil {
  1944  		s.writeError(ctx, resp, twirp.InternalError("received a nil *ListParticipantsResponse and nil error while calling ListParticipants. nil responses are not supported"))
  1945  		return
  1946  	}
  1947  
  1948  	ctx = callResponsePrepared(ctx, s.hooks)
  1949  
  1950  	marshaler := &protojson.MarshalOptions{UseProtoNames: !s.jsonCamelCase, EmitUnpopulated: !s.jsonSkipDefaults}
  1951  	respBytes, err := marshaler.Marshal(respContent)
  1952  	if err != nil {
  1953  		s.writeError(ctx, resp, wrapInternal(err, "failed to marshal json response"))
  1954  		return
  1955  	}
  1956  
  1957  	ctx = ctxsetters.WithStatusCode(ctx, http.StatusOK)
  1958  	resp.Header().Set("Content-Type", "application/json")
  1959  	resp.Header().Set("Content-Length", strconv.Itoa(len(respBytes)))
  1960  	resp.WriteHeader(http.StatusOK)
  1961  
  1962  	if n, err := resp.Write(respBytes); err != nil {
  1963  		msg := fmt.Sprintf("failed to write response, %d of %d bytes written: %s", n, len(respBytes), err.Error())
  1964  		twerr := twirp.NewError(twirp.Unknown, msg)
  1965  		ctx = callError(ctx, s.hooks, twerr)
  1966  	}
  1967  	callResponseSent(ctx, s.hooks)
  1968  }
  1969  
  1970  func (s *roomServiceServer) serveListParticipantsProtobuf(ctx context.Context, resp http.ResponseWriter, req *http.Request) {
  1971  	var err error
  1972  	ctx = ctxsetters.WithMethodName(ctx, "ListParticipants")
  1973  	ctx, err = callRequestRouted(ctx, s.hooks)
  1974  	if err != nil {
  1975  		s.writeError(ctx, resp, err)
  1976  		return
  1977  	}
  1978  
  1979  	buf, err := io.ReadAll(req.Body)
  1980  	if err != nil {
  1981  		s.handleRequestBodyError(ctx, resp, "failed to read request body", err)
  1982  		return
  1983  	}
  1984  	reqContent := new(ListParticipantsRequest)
  1985  	if err = proto.Unmarshal(buf, reqContent); err != nil {
  1986  		s.writeError(ctx, resp, malformedRequestError("the protobuf request could not be decoded"))
  1987  		return
  1988  	}
  1989  
  1990  	handler := s.RoomService.ListParticipants
  1991  	if s.interceptor != nil {
  1992  		handler = func(ctx context.Context, req *ListParticipantsRequest) (*ListParticipantsResponse, error) {
  1993  			resp, err := s.interceptor(
  1994  				func(ctx context.Context, req interface{}) (interface{}, error) {
  1995  					typedReq, ok := req.(*ListParticipantsRequest)
  1996  					if !ok {
  1997  						return nil, twirp.InternalError("failed type assertion req.(*ListParticipantsRequest) when calling interceptor")
  1998  					}
  1999  					return s.RoomService.ListParticipants(ctx, typedReq)
  2000  				},
  2001  			)(ctx, req)
  2002  			if resp != nil {
  2003  				typedResp, ok := resp.(*ListParticipantsResponse)
  2004  				if !ok {
  2005  					return nil, twirp.InternalError("failed type assertion resp.(*ListParticipantsResponse) when calling interceptor")
  2006  				}
  2007  				return typedResp, err
  2008  			}
  2009  			return nil, err
  2010  		}
  2011  	}
  2012  
  2013  	// Call service method
  2014  	var respContent *ListParticipantsResponse
  2015  	func() {
  2016  		defer ensurePanicResponses(ctx, resp, s.hooks)
  2017  		respContent, err = handler(ctx, reqContent)
  2018  	}()
  2019  
  2020  	if err != nil {
  2021  		s.writeError(ctx, resp, err)
  2022  		return
  2023  	}
  2024  	if respContent == nil {
  2025  		s.writeError(ctx, resp, twirp.InternalError("received a nil *ListParticipantsResponse and nil error while calling ListParticipants. nil responses are not supported"))
  2026  		return
  2027  	}
  2028  
  2029  	ctx = callResponsePrepared(ctx, s.hooks)
  2030  
  2031  	respBytes, err := proto.Marshal(respContent)
  2032  	if err != nil {
  2033  		s.writeError(ctx, resp, wrapInternal(err, "failed to marshal proto response"))
  2034  		return
  2035  	}
  2036  
  2037  	ctx = ctxsetters.WithStatusCode(ctx, http.StatusOK)
  2038  	resp.Header().Set("Content-Type", "application/protobuf")
  2039  	resp.Header().Set("Content-Length", strconv.Itoa(len(respBytes)))
  2040  	resp.WriteHeader(http.StatusOK)
  2041  	if n, err := resp.Write(respBytes); err != nil {
  2042  		msg := fmt.Sprintf("failed to write response, %d of %d bytes written: %s", n, len(respBytes), err.Error())
  2043  		twerr := twirp.NewError(twirp.Unknown, msg)
  2044  		ctx = callError(ctx, s.hooks, twerr)
  2045  	}
  2046  	callResponseSent(ctx, s.hooks)
  2047  }
  2048  
  2049  func (s *roomServiceServer) serveGetParticipant(ctx context.Context, resp http.ResponseWriter, req *http.Request) {
  2050  	header := req.Header.Get("Content-Type")
  2051  	i := strings.Index(header, ";")
  2052  	if i == -1 {
  2053  		i = len(header)
  2054  	}
  2055  	switch strings.TrimSpace(strings.ToLower(header[:i])) {
  2056  	case "application/json":
  2057  		s.serveGetParticipantJSON(ctx, resp, req)
  2058  	case "application/protobuf":
  2059  		s.serveGetParticipantProtobuf(ctx, resp, req)
  2060  	default:
  2061  		msg := fmt.Sprintf("unexpected Content-Type: %q", req.Header.Get("Content-Type"))
  2062  		twerr := badRouteError(msg, req.Method, req.URL.Path)
  2063  		s.writeError(ctx, resp, twerr)
  2064  	}
  2065  }
  2066  
  2067  func (s *roomServiceServer) serveGetParticipantJSON(ctx context.Context, resp http.ResponseWriter, req *http.Request) {
  2068  	var err error
  2069  	ctx = ctxsetters.WithMethodName(ctx, "GetParticipant")
  2070  	ctx, err = callRequestRouted(ctx, s.hooks)
  2071  	if err != nil {
  2072  		s.writeError(ctx, resp, err)
  2073  		return
  2074  	}
  2075  
  2076  	d := json.NewDecoder(req.Body)
  2077  	rawReqBody := json.RawMessage{}
  2078  	if err := d.Decode(&rawReqBody); err != nil {
  2079  		s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err)
  2080  		return
  2081  	}
  2082  	reqContent := new(RoomParticipantIdentity)
  2083  	unmarshaler := protojson.UnmarshalOptions{DiscardUnknown: true}
  2084  	if err = unmarshaler.Unmarshal(rawReqBody, reqContent); err != nil {
  2085  		s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err)
  2086  		return
  2087  	}
  2088  
  2089  	handler := s.RoomService.GetParticipant
  2090  	if s.interceptor != nil {
  2091  		handler = func(ctx context.Context, req *RoomParticipantIdentity) (*ParticipantInfo, error) {
  2092  			resp, err := s.interceptor(
  2093  				func(ctx context.Context, req interface{}) (interface{}, error) {
  2094  					typedReq, ok := req.(*RoomParticipantIdentity)
  2095  					if !ok {
  2096  						return nil, twirp.InternalError("failed type assertion req.(*RoomParticipantIdentity) when calling interceptor")
  2097  					}
  2098  					return s.RoomService.GetParticipant(ctx, typedReq)
  2099  				},
  2100  			)(ctx, req)
  2101  			if resp != nil {
  2102  				typedResp, ok := resp.(*ParticipantInfo)
  2103  				if !ok {
  2104  					return nil, twirp.InternalError("failed type assertion resp.(*ParticipantInfo) when calling interceptor")
  2105  				}
  2106  				return typedResp, err
  2107  			}
  2108  			return nil, err
  2109  		}
  2110  	}
  2111  
  2112  	// Call service method
  2113  	var respContent *ParticipantInfo
  2114  	func() {
  2115  		defer ensurePanicResponses(ctx, resp, s.hooks)
  2116  		respContent, err = handler(ctx, reqContent)
  2117  	}()
  2118  
  2119  	if err != nil {
  2120  		s.writeError(ctx, resp, err)
  2121  		return
  2122  	}
  2123  	if respContent == nil {
  2124  		s.writeError(ctx, resp, twirp.InternalError("received a nil *ParticipantInfo and nil error while calling GetParticipant. nil responses are not supported"))
  2125  		return
  2126  	}
  2127  
  2128  	ctx = callResponsePrepared(ctx, s.hooks)
  2129  
  2130  	marshaler := &protojson.MarshalOptions{UseProtoNames: !s.jsonCamelCase, EmitUnpopulated: !s.jsonSkipDefaults}
  2131  	respBytes, err := marshaler.Marshal(respContent)
  2132  	if err != nil {
  2133  		s.writeError(ctx, resp, wrapInternal(err, "failed to marshal json response"))
  2134  		return
  2135  	}
  2136  
  2137  	ctx = ctxsetters.WithStatusCode(ctx, http.StatusOK)
  2138  	resp.Header().Set("Content-Type", "application/json")
  2139  	resp.Header().Set("Content-Length", strconv.Itoa(len(respBytes)))
  2140  	resp.WriteHeader(http.StatusOK)
  2141  
  2142  	if n, err := resp.Write(respBytes); err != nil {
  2143  		msg := fmt.Sprintf("failed to write response, %d of %d bytes written: %s", n, len(respBytes), err.Error())
  2144  		twerr := twirp.NewError(twirp.Unknown, msg)
  2145  		ctx = callError(ctx, s.hooks, twerr)
  2146  	}
  2147  	callResponseSent(ctx, s.hooks)
  2148  }
  2149  
  2150  func (s *roomServiceServer) serveGetParticipantProtobuf(ctx context.Context, resp http.ResponseWriter, req *http.Request) {
  2151  	var err error
  2152  	ctx = ctxsetters.WithMethodName(ctx, "GetParticipant")
  2153  	ctx, err = callRequestRouted(ctx, s.hooks)
  2154  	if err != nil {
  2155  		s.writeError(ctx, resp, err)
  2156  		return
  2157  	}
  2158  
  2159  	buf, err := io.ReadAll(req.Body)
  2160  	if err != nil {
  2161  		s.handleRequestBodyError(ctx, resp, "failed to read request body", err)
  2162  		return
  2163  	}
  2164  	reqContent := new(RoomParticipantIdentity)
  2165  	if err = proto.Unmarshal(buf, reqContent); err != nil {
  2166  		s.writeError(ctx, resp, malformedRequestError("the protobuf request could not be decoded"))
  2167  		return
  2168  	}
  2169  
  2170  	handler := s.RoomService.GetParticipant
  2171  	if s.interceptor != nil {
  2172  		handler = func(ctx context.Context, req *RoomParticipantIdentity) (*ParticipantInfo, error) {
  2173  			resp, err := s.interceptor(
  2174  				func(ctx context.Context, req interface{}) (interface{}, error) {
  2175  					typedReq, ok := req.(*RoomParticipantIdentity)
  2176  					if !ok {
  2177  						return nil, twirp.InternalError("failed type assertion req.(*RoomParticipantIdentity) when calling interceptor")
  2178  					}
  2179  					return s.RoomService.GetParticipant(ctx, typedReq)
  2180  				},
  2181  			)(ctx, req)
  2182  			if resp != nil {
  2183  				typedResp, ok := resp.(*ParticipantInfo)
  2184  				if !ok {
  2185  					return nil, twirp.InternalError("failed type assertion resp.(*ParticipantInfo) when calling interceptor")
  2186  				}
  2187  				return typedResp, err
  2188  			}
  2189  			return nil, err
  2190  		}
  2191  	}
  2192  
  2193  	// Call service method
  2194  	var respContent *ParticipantInfo
  2195  	func() {
  2196  		defer ensurePanicResponses(ctx, resp, s.hooks)
  2197  		respContent, err = handler(ctx, reqContent)
  2198  	}()
  2199  
  2200  	if err != nil {
  2201  		s.writeError(ctx, resp, err)
  2202  		return
  2203  	}
  2204  	if respContent == nil {
  2205  		s.writeError(ctx, resp, twirp.InternalError("received a nil *ParticipantInfo and nil error while calling GetParticipant. nil responses are not supported"))
  2206  		return
  2207  	}
  2208  
  2209  	ctx = callResponsePrepared(ctx, s.hooks)
  2210  
  2211  	respBytes, err := proto.Marshal(respContent)
  2212  	if err != nil {
  2213  		s.writeError(ctx, resp, wrapInternal(err, "failed to marshal proto response"))
  2214  		return
  2215  	}
  2216  
  2217  	ctx = ctxsetters.WithStatusCode(ctx, http.StatusOK)
  2218  	resp.Header().Set("Content-Type", "application/protobuf")
  2219  	resp.Header().Set("Content-Length", strconv.Itoa(len(respBytes)))
  2220  	resp.WriteHeader(http.StatusOK)
  2221  	if n, err := resp.Write(respBytes); err != nil {
  2222  		msg := fmt.Sprintf("failed to write response, %d of %d bytes written: %s", n, len(respBytes), err.Error())
  2223  		twerr := twirp.NewError(twirp.Unknown, msg)
  2224  		ctx = callError(ctx, s.hooks, twerr)
  2225  	}
  2226  	callResponseSent(ctx, s.hooks)
  2227  }
  2228  
  2229  func (s *roomServiceServer) serveRemoveParticipant(ctx context.Context, resp http.ResponseWriter, req *http.Request) {
  2230  	header := req.Header.Get("Content-Type")
  2231  	i := strings.Index(header, ";")
  2232  	if i == -1 {
  2233  		i = len(header)
  2234  	}
  2235  	switch strings.TrimSpace(strings.ToLower(header[:i])) {
  2236  	case "application/json":
  2237  		s.serveRemoveParticipantJSON(ctx, resp, req)
  2238  	case "application/protobuf":
  2239  		s.serveRemoveParticipantProtobuf(ctx, resp, req)
  2240  	default:
  2241  		msg := fmt.Sprintf("unexpected Content-Type: %q", req.Header.Get("Content-Type"))
  2242  		twerr := badRouteError(msg, req.Method, req.URL.Path)
  2243  		s.writeError(ctx, resp, twerr)
  2244  	}
  2245  }
  2246  
  2247  func (s *roomServiceServer) serveRemoveParticipantJSON(ctx context.Context, resp http.ResponseWriter, req *http.Request) {
  2248  	var err error
  2249  	ctx = ctxsetters.WithMethodName(ctx, "RemoveParticipant")
  2250  	ctx, err = callRequestRouted(ctx, s.hooks)
  2251  	if err != nil {
  2252  		s.writeError(ctx, resp, err)
  2253  		return
  2254  	}
  2255  
  2256  	d := json.NewDecoder(req.Body)
  2257  	rawReqBody := json.RawMessage{}
  2258  	if err := d.Decode(&rawReqBody); err != nil {
  2259  		s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err)
  2260  		return
  2261  	}
  2262  	reqContent := new(RoomParticipantIdentity)
  2263  	unmarshaler := protojson.UnmarshalOptions{DiscardUnknown: true}
  2264  	if err = unmarshaler.Unmarshal(rawReqBody, reqContent); err != nil {
  2265  		s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err)
  2266  		return
  2267  	}
  2268  
  2269  	handler := s.RoomService.RemoveParticipant
  2270  	if s.interceptor != nil {
  2271  		handler = func(ctx context.Context, req *RoomParticipantIdentity) (*RemoveParticipantResponse, error) {
  2272  			resp, err := s.interceptor(
  2273  				func(ctx context.Context, req interface{}) (interface{}, error) {
  2274  					typedReq, ok := req.(*RoomParticipantIdentity)
  2275  					if !ok {
  2276  						return nil, twirp.InternalError("failed type assertion req.(*RoomParticipantIdentity) when calling interceptor")
  2277  					}
  2278  					return s.RoomService.RemoveParticipant(ctx, typedReq)
  2279  				},
  2280  			)(ctx, req)
  2281  			if resp != nil {
  2282  				typedResp, ok := resp.(*RemoveParticipantResponse)
  2283  				if !ok {
  2284  					return nil, twirp.InternalError("failed type assertion resp.(*RemoveParticipantResponse) when calling interceptor")
  2285  				}
  2286  				return typedResp, err
  2287  			}
  2288  			return nil, err
  2289  		}
  2290  	}
  2291  
  2292  	// Call service method
  2293  	var respContent *RemoveParticipantResponse
  2294  	func() {
  2295  		defer ensurePanicResponses(ctx, resp, s.hooks)
  2296  		respContent, err = handler(ctx, reqContent)
  2297  	}()
  2298  
  2299  	if err != nil {
  2300  		s.writeError(ctx, resp, err)
  2301  		return
  2302  	}
  2303  	if respContent == nil {
  2304  		s.writeError(ctx, resp, twirp.InternalError("received a nil *RemoveParticipantResponse and nil error while calling RemoveParticipant. nil responses are not supported"))
  2305  		return
  2306  	}
  2307  
  2308  	ctx = callResponsePrepared(ctx, s.hooks)
  2309  
  2310  	marshaler := &protojson.MarshalOptions{UseProtoNames: !s.jsonCamelCase, EmitUnpopulated: !s.jsonSkipDefaults}
  2311  	respBytes, err := marshaler.Marshal(respContent)
  2312  	if err != nil {
  2313  		s.writeError(ctx, resp, wrapInternal(err, "failed to marshal json response"))
  2314  		return
  2315  	}
  2316  
  2317  	ctx = ctxsetters.WithStatusCode(ctx, http.StatusOK)
  2318  	resp.Header().Set("Content-Type", "application/json")
  2319  	resp.Header().Set("Content-Length", strconv.Itoa(len(respBytes)))
  2320  	resp.WriteHeader(http.StatusOK)
  2321  
  2322  	if n, err := resp.Write(respBytes); err != nil {
  2323  		msg := fmt.Sprintf("failed to write response, %d of %d bytes written: %s", n, len(respBytes), err.Error())
  2324  		twerr := twirp.NewError(twirp.Unknown, msg)
  2325  		ctx = callError(ctx, s.hooks, twerr)
  2326  	}
  2327  	callResponseSent(ctx, s.hooks)
  2328  }
  2329  
  2330  func (s *roomServiceServer) serveRemoveParticipantProtobuf(ctx context.Context, resp http.ResponseWriter, req *http.Request) {
  2331  	var err error
  2332  	ctx = ctxsetters.WithMethodName(ctx, "RemoveParticipant")
  2333  	ctx, err = callRequestRouted(ctx, s.hooks)
  2334  	if err != nil {
  2335  		s.writeError(ctx, resp, err)
  2336  		return
  2337  	}
  2338  
  2339  	buf, err := io.ReadAll(req.Body)
  2340  	if err != nil {
  2341  		s.handleRequestBodyError(ctx, resp, "failed to read request body", err)
  2342  		return
  2343  	}
  2344  	reqContent := new(RoomParticipantIdentity)
  2345  	if err = proto.Unmarshal(buf, reqContent); err != nil {
  2346  		s.writeError(ctx, resp, malformedRequestError("the protobuf request could not be decoded"))
  2347  		return
  2348  	}
  2349  
  2350  	handler := s.RoomService.RemoveParticipant
  2351  	if s.interceptor != nil {
  2352  		handler = func(ctx context.Context, req *RoomParticipantIdentity) (*RemoveParticipantResponse, error) {
  2353  			resp, err := s.interceptor(
  2354  				func(ctx context.Context, req interface{}) (interface{}, error) {
  2355  					typedReq, ok := req.(*RoomParticipantIdentity)
  2356  					if !ok {
  2357  						return nil, twirp.InternalError("failed type assertion req.(*RoomParticipantIdentity) when calling interceptor")
  2358  					}
  2359  					return s.RoomService.RemoveParticipant(ctx, typedReq)
  2360  				},
  2361  			)(ctx, req)
  2362  			if resp != nil {
  2363  				typedResp, ok := resp.(*RemoveParticipantResponse)
  2364  				if !ok {
  2365  					return nil, twirp.InternalError("failed type assertion resp.(*RemoveParticipantResponse) when calling interceptor")
  2366  				}
  2367  				return typedResp, err
  2368  			}
  2369  			return nil, err
  2370  		}
  2371  	}
  2372  
  2373  	// Call service method
  2374  	var respContent *RemoveParticipantResponse
  2375  	func() {
  2376  		defer ensurePanicResponses(ctx, resp, s.hooks)
  2377  		respContent, err = handler(ctx, reqContent)
  2378  	}()
  2379  
  2380  	if err != nil {
  2381  		s.writeError(ctx, resp, err)
  2382  		return
  2383  	}
  2384  	if respContent == nil {
  2385  		s.writeError(ctx, resp, twirp.InternalError("received a nil *RemoveParticipantResponse and nil error while calling RemoveParticipant. nil responses are not supported"))
  2386  		return
  2387  	}
  2388  
  2389  	ctx = callResponsePrepared(ctx, s.hooks)
  2390  
  2391  	respBytes, err := proto.Marshal(respContent)
  2392  	if err != nil {
  2393  		s.writeError(ctx, resp, wrapInternal(err, "failed to marshal proto response"))
  2394  		return
  2395  	}
  2396  
  2397  	ctx = ctxsetters.WithStatusCode(ctx, http.StatusOK)
  2398  	resp.Header().Set("Content-Type", "application/protobuf")
  2399  	resp.Header().Set("Content-Length", strconv.Itoa(len(respBytes)))
  2400  	resp.WriteHeader(http.StatusOK)
  2401  	if n, err := resp.Write(respBytes); err != nil {
  2402  		msg := fmt.Sprintf("failed to write response, %d of %d bytes written: %s", n, len(respBytes), err.Error())
  2403  		twerr := twirp.NewError(twirp.Unknown, msg)
  2404  		ctx = callError(ctx, s.hooks, twerr)
  2405  	}
  2406  	callResponseSent(ctx, s.hooks)
  2407  }
  2408  
  2409  func (s *roomServiceServer) serveMutePublishedTrack(ctx context.Context, resp http.ResponseWriter, req *http.Request) {
  2410  	header := req.Header.Get("Content-Type")
  2411  	i := strings.Index(header, ";")
  2412  	if i == -1 {
  2413  		i = len(header)
  2414  	}
  2415  	switch strings.TrimSpace(strings.ToLower(header[:i])) {
  2416  	case "application/json":
  2417  		s.serveMutePublishedTrackJSON(ctx, resp, req)
  2418  	case "application/protobuf":
  2419  		s.serveMutePublishedTrackProtobuf(ctx, resp, req)
  2420  	default:
  2421  		msg := fmt.Sprintf("unexpected Content-Type: %q", req.Header.Get("Content-Type"))
  2422  		twerr := badRouteError(msg, req.Method, req.URL.Path)
  2423  		s.writeError(ctx, resp, twerr)
  2424  	}
  2425  }
  2426  
  2427  func (s *roomServiceServer) serveMutePublishedTrackJSON(ctx context.Context, resp http.ResponseWriter, req *http.Request) {
  2428  	var err error
  2429  	ctx = ctxsetters.WithMethodName(ctx, "MutePublishedTrack")
  2430  	ctx, err = callRequestRouted(ctx, s.hooks)
  2431  	if err != nil {
  2432  		s.writeError(ctx, resp, err)
  2433  		return
  2434  	}
  2435  
  2436  	d := json.NewDecoder(req.Body)
  2437  	rawReqBody := json.RawMessage{}
  2438  	if err := d.Decode(&rawReqBody); err != nil {
  2439  		s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err)
  2440  		return
  2441  	}
  2442  	reqContent := new(MuteRoomTrackRequest)
  2443  	unmarshaler := protojson.UnmarshalOptions{DiscardUnknown: true}
  2444  	if err = unmarshaler.Unmarshal(rawReqBody, reqContent); err != nil {
  2445  		s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err)
  2446  		return
  2447  	}
  2448  
  2449  	handler := s.RoomService.MutePublishedTrack
  2450  	if s.interceptor != nil {
  2451  		handler = func(ctx context.Context, req *MuteRoomTrackRequest) (*MuteRoomTrackResponse, error) {
  2452  			resp, err := s.interceptor(
  2453  				func(ctx context.Context, req interface{}) (interface{}, error) {
  2454  					typedReq, ok := req.(*MuteRoomTrackRequest)
  2455  					if !ok {
  2456  						return nil, twirp.InternalError("failed type assertion req.(*MuteRoomTrackRequest) when calling interceptor")
  2457  					}
  2458  					return s.RoomService.MutePublishedTrack(ctx, typedReq)
  2459  				},
  2460  			)(ctx, req)
  2461  			if resp != nil {
  2462  				typedResp, ok := resp.(*MuteRoomTrackResponse)
  2463  				if !ok {
  2464  					return nil, twirp.InternalError("failed type assertion resp.(*MuteRoomTrackResponse) when calling interceptor")
  2465  				}
  2466  				return typedResp, err
  2467  			}
  2468  			return nil, err
  2469  		}
  2470  	}
  2471  
  2472  	// Call service method
  2473  	var respContent *MuteRoomTrackResponse
  2474  	func() {
  2475  		defer ensurePanicResponses(ctx, resp, s.hooks)
  2476  		respContent, err = handler(ctx, reqContent)
  2477  	}()
  2478  
  2479  	if err != nil {
  2480  		s.writeError(ctx, resp, err)
  2481  		return
  2482  	}
  2483  	if respContent == nil {
  2484  		s.writeError(ctx, resp, twirp.InternalError("received a nil *MuteRoomTrackResponse and nil error while calling MutePublishedTrack. nil responses are not supported"))
  2485  		return
  2486  	}
  2487  
  2488  	ctx = callResponsePrepared(ctx, s.hooks)
  2489  
  2490  	marshaler := &protojson.MarshalOptions{UseProtoNames: !s.jsonCamelCase, EmitUnpopulated: !s.jsonSkipDefaults}
  2491  	respBytes, err := marshaler.Marshal(respContent)
  2492  	if err != nil {
  2493  		s.writeError(ctx, resp, wrapInternal(err, "failed to marshal json response"))
  2494  		return
  2495  	}
  2496  
  2497  	ctx = ctxsetters.WithStatusCode(ctx, http.StatusOK)
  2498  	resp.Header().Set("Content-Type", "application/json")
  2499  	resp.Header().Set("Content-Length", strconv.Itoa(len(respBytes)))
  2500  	resp.WriteHeader(http.StatusOK)
  2501  
  2502  	if n, err := resp.Write(respBytes); err != nil {
  2503  		msg := fmt.Sprintf("failed to write response, %d of %d bytes written: %s", n, len(respBytes), err.Error())
  2504  		twerr := twirp.NewError(twirp.Unknown, msg)
  2505  		ctx = callError(ctx, s.hooks, twerr)
  2506  	}
  2507  	callResponseSent(ctx, s.hooks)
  2508  }
  2509  
  2510  func (s *roomServiceServer) serveMutePublishedTrackProtobuf(ctx context.Context, resp http.ResponseWriter, req *http.Request) {
  2511  	var err error
  2512  	ctx = ctxsetters.WithMethodName(ctx, "MutePublishedTrack")
  2513  	ctx, err = callRequestRouted(ctx, s.hooks)
  2514  	if err != nil {
  2515  		s.writeError(ctx, resp, err)
  2516  		return
  2517  	}
  2518  
  2519  	buf, err := io.ReadAll(req.Body)
  2520  	if err != nil {
  2521  		s.handleRequestBodyError(ctx, resp, "failed to read request body", err)
  2522  		return
  2523  	}
  2524  	reqContent := new(MuteRoomTrackRequest)
  2525  	if err = proto.Unmarshal(buf, reqContent); err != nil {
  2526  		s.writeError(ctx, resp, malformedRequestError("the protobuf request could not be decoded"))
  2527  		return
  2528  	}
  2529  
  2530  	handler := s.RoomService.MutePublishedTrack
  2531  	if s.interceptor != nil {
  2532  		handler = func(ctx context.Context, req *MuteRoomTrackRequest) (*MuteRoomTrackResponse, error) {
  2533  			resp, err := s.interceptor(
  2534  				func(ctx context.Context, req interface{}) (interface{}, error) {
  2535  					typedReq, ok := req.(*MuteRoomTrackRequest)
  2536  					if !ok {
  2537  						return nil, twirp.InternalError("failed type assertion req.(*MuteRoomTrackRequest) when calling interceptor")
  2538  					}
  2539  					return s.RoomService.MutePublishedTrack(ctx, typedReq)
  2540  				},
  2541  			)(ctx, req)
  2542  			if resp != nil {
  2543  				typedResp, ok := resp.(*MuteRoomTrackResponse)
  2544  				if !ok {
  2545  					return nil, twirp.InternalError("failed type assertion resp.(*MuteRoomTrackResponse) when calling interceptor")
  2546  				}
  2547  				return typedResp, err
  2548  			}
  2549  			return nil, err
  2550  		}
  2551  	}
  2552  
  2553  	// Call service method
  2554  	var respContent *MuteRoomTrackResponse
  2555  	func() {
  2556  		defer ensurePanicResponses(ctx, resp, s.hooks)
  2557  		respContent, err = handler(ctx, reqContent)
  2558  	}()
  2559  
  2560  	if err != nil {
  2561  		s.writeError(ctx, resp, err)
  2562  		return
  2563  	}
  2564  	if respContent == nil {
  2565  		s.writeError(ctx, resp, twirp.InternalError("received a nil *MuteRoomTrackResponse and nil error while calling MutePublishedTrack. nil responses are not supported"))
  2566  		return
  2567  	}
  2568  
  2569  	ctx = callResponsePrepared(ctx, s.hooks)
  2570  
  2571  	respBytes, err := proto.Marshal(respContent)
  2572  	if err != nil {
  2573  		s.writeError(ctx, resp, wrapInternal(err, "failed to marshal proto response"))
  2574  		return
  2575  	}
  2576  
  2577  	ctx = ctxsetters.WithStatusCode(ctx, http.StatusOK)
  2578  	resp.Header().Set("Content-Type", "application/protobuf")
  2579  	resp.Header().Set("Content-Length", strconv.Itoa(len(respBytes)))
  2580  	resp.WriteHeader(http.StatusOK)
  2581  	if n, err := resp.Write(respBytes); err != nil {
  2582  		msg := fmt.Sprintf("failed to write response, %d of %d bytes written: %s", n, len(respBytes), err.Error())
  2583  		twerr := twirp.NewError(twirp.Unknown, msg)
  2584  		ctx = callError(ctx, s.hooks, twerr)
  2585  	}
  2586  	callResponseSent(ctx, s.hooks)
  2587  }
  2588  
  2589  func (s *roomServiceServer) serveUpdateParticipant(ctx context.Context, resp http.ResponseWriter, req *http.Request) {
  2590  	header := req.Header.Get("Content-Type")
  2591  	i := strings.Index(header, ";")
  2592  	if i == -1 {
  2593  		i = len(header)
  2594  	}
  2595  	switch strings.TrimSpace(strings.ToLower(header[:i])) {
  2596  	case "application/json":
  2597  		s.serveUpdateParticipantJSON(ctx, resp, req)
  2598  	case "application/protobuf":
  2599  		s.serveUpdateParticipantProtobuf(ctx, resp, req)
  2600  	default:
  2601  		msg := fmt.Sprintf("unexpected Content-Type: %q", req.Header.Get("Content-Type"))
  2602  		twerr := badRouteError(msg, req.Method, req.URL.Path)
  2603  		s.writeError(ctx, resp, twerr)
  2604  	}
  2605  }
  2606  
  2607  func (s *roomServiceServer) serveUpdateParticipantJSON(ctx context.Context, resp http.ResponseWriter, req *http.Request) {
  2608  	var err error
  2609  	ctx = ctxsetters.WithMethodName(ctx, "UpdateParticipant")
  2610  	ctx, err = callRequestRouted(ctx, s.hooks)
  2611  	if err != nil {
  2612  		s.writeError(ctx, resp, err)
  2613  		return
  2614  	}
  2615  
  2616  	d := json.NewDecoder(req.Body)
  2617  	rawReqBody := json.RawMessage{}
  2618  	if err := d.Decode(&rawReqBody); err != nil {
  2619  		s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err)
  2620  		return
  2621  	}
  2622  	reqContent := new(UpdateParticipantRequest)
  2623  	unmarshaler := protojson.UnmarshalOptions{DiscardUnknown: true}
  2624  	if err = unmarshaler.Unmarshal(rawReqBody, reqContent); err != nil {
  2625  		s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err)
  2626  		return
  2627  	}
  2628  
  2629  	handler := s.RoomService.UpdateParticipant
  2630  	if s.interceptor != nil {
  2631  		handler = func(ctx context.Context, req *UpdateParticipantRequest) (*ParticipantInfo, error) {
  2632  			resp, err := s.interceptor(
  2633  				func(ctx context.Context, req interface{}) (interface{}, error) {
  2634  					typedReq, ok := req.(*UpdateParticipantRequest)
  2635  					if !ok {
  2636  						return nil, twirp.InternalError("failed type assertion req.(*UpdateParticipantRequest) when calling interceptor")
  2637  					}
  2638  					return s.RoomService.UpdateParticipant(ctx, typedReq)
  2639  				},
  2640  			)(ctx, req)
  2641  			if resp != nil {
  2642  				typedResp, ok := resp.(*ParticipantInfo)
  2643  				if !ok {
  2644  					return nil, twirp.InternalError("failed type assertion resp.(*ParticipantInfo) when calling interceptor")
  2645  				}
  2646  				return typedResp, err
  2647  			}
  2648  			return nil, err
  2649  		}
  2650  	}
  2651  
  2652  	// Call service method
  2653  	var respContent *ParticipantInfo
  2654  	func() {
  2655  		defer ensurePanicResponses(ctx, resp, s.hooks)
  2656  		respContent, err = handler(ctx, reqContent)
  2657  	}()
  2658  
  2659  	if err != nil {
  2660  		s.writeError(ctx, resp, err)
  2661  		return
  2662  	}
  2663  	if respContent == nil {
  2664  		s.writeError(ctx, resp, twirp.InternalError("received a nil *ParticipantInfo and nil error while calling UpdateParticipant. nil responses are not supported"))
  2665  		return
  2666  	}
  2667  
  2668  	ctx = callResponsePrepared(ctx, s.hooks)
  2669  
  2670  	marshaler := &protojson.MarshalOptions{UseProtoNames: !s.jsonCamelCase, EmitUnpopulated: !s.jsonSkipDefaults}
  2671  	respBytes, err := marshaler.Marshal(respContent)
  2672  	if err != nil {
  2673  		s.writeError(ctx, resp, wrapInternal(err, "failed to marshal json response"))
  2674  		return
  2675  	}
  2676  
  2677  	ctx = ctxsetters.WithStatusCode(ctx, http.StatusOK)
  2678  	resp.Header().Set("Content-Type", "application/json")
  2679  	resp.Header().Set("Content-Length", strconv.Itoa(len(respBytes)))
  2680  	resp.WriteHeader(http.StatusOK)
  2681  
  2682  	if n, err := resp.Write(respBytes); err != nil {
  2683  		msg := fmt.Sprintf("failed to write response, %d of %d bytes written: %s", n, len(respBytes), err.Error())
  2684  		twerr := twirp.NewError(twirp.Unknown, msg)
  2685  		ctx = callError(ctx, s.hooks, twerr)
  2686  	}
  2687  	callResponseSent(ctx, s.hooks)
  2688  }
  2689  
  2690  func (s *roomServiceServer) serveUpdateParticipantProtobuf(ctx context.Context, resp http.ResponseWriter, req *http.Request) {
  2691  	var err error
  2692  	ctx = ctxsetters.WithMethodName(ctx, "UpdateParticipant")
  2693  	ctx, err = callRequestRouted(ctx, s.hooks)
  2694  	if err != nil {
  2695  		s.writeError(ctx, resp, err)
  2696  		return
  2697  	}
  2698  
  2699  	buf, err := io.ReadAll(req.Body)
  2700  	if err != nil {
  2701  		s.handleRequestBodyError(ctx, resp, "failed to read request body", err)
  2702  		return
  2703  	}
  2704  	reqContent := new(UpdateParticipantRequest)
  2705  	if err = proto.Unmarshal(buf, reqContent); err != nil {
  2706  		s.writeError(ctx, resp, malformedRequestError("the protobuf request could not be decoded"))
  2707  		return
  2708  	}
  2709  
  2710  	handler := s.RoomService.UpdateParticipant
  2711  	if s.interceptor != nil {
  2712  		handler = func(ctx context.Context, req *UpdateParticipantRequest) (*ParticipantInfo, error) {
  2713  			resp, err := s.interceptor(
  2714  				func(ctx context.Context, req interface{}) (interface{}, error) {
  2715  					typedReq, ok := req.(*UpdateParticipantRequest)
  2716  					if !ok {
  2717  						return nil, twirp.InternalError("failed type assertion req.(*UpdateParticipantRequest) when calling interceptor")
  2718  					}
  2719  					return s.RoomService.UpdateParticipant(ctx, typedReq)
  2720  				},
  2721  			)(ctx, req)
  2722  			if resp != nil {
  2723  				typedResp, ok := resp.(*ParticipantInfo)
  2724  				if !ok {
  2725  					return nil, twirp.InternalError("failed type assertion resp.(*ParticipantInfo) when calling interceptor")
  2726  				}
  2727  				return typedResp, err
  2728  			}
  2729  			return nil, err
  2730  		}
  2731  	}
  2732  
  2733  	// Call service method
  2734  	var respContent *ParticipantInfo
  2735  	func() {
  2736  		defer ensurePanicResponses(ctx, resp, s.hooks)
  2737  		respContent, err = handler(ctx, reqContent)
  2738  	}()
  2739  
  2740  	if err != nil {
  2741  		s.writeError(ctx, resp, err)
  2742  		return
  2743  	}
  2744  	if respContent == nil {
  2745  		s.writeError(ctx, resp, twirp.InternalError("received a nil *ParticipantInfo and nil error while calling UpdateParticipant. nil responses are not supported"))
  2746  		return
  2747  	}
  2748  
  2749  	ctx = callResponsePrepared(ctx, s.hooks)
  2750  
  2751  	respBytes, err := proto.Marshal(respContent)
  2752  	if err != nil {
  2753  		s.writeError(ctx, resp, wrapInternal(err, "failed to marshal proto response"))
  2754  		return
  2755  	}
  2756  
  2757  	ctx = ctxsetters.WithStatusCode(ctx, http.StatusOK)
  2758  	resp.Header().Set("Content-Type", "application/protobuf")
  2759  	resp.Header().Set("Content-Length", strconv.Itoa(len(respBytes)))
  2760  	resp.WriteHeader(http.StatusOK)
  2761  	if n, err := resp.Write(respBytes); err != nil {
  2762  		msg := fmt.Sprintf("failed to write response, %d of %d bytes written: %s", n, len(respBytes), err.Error())
  2763  		twerr := twirp.NewError(twirp.Unknown, msg)
  2764  		ctx = callError(ctx, s.hooks, twerr)
  2765  	}
  2766  	callResponseSent(ctx, s.hooks)
  2767  }
  2768  
  2769  func (s *roomServiceServer) serveUpdateSubscriptions(ctx context.Context, resp http.ResponseWriter, req *http.Request) {
  2770  	header := req.Header.Get("Content-Type")
  2771  	i := strings.Index(header, ";")
  2772  	if i == -1 {
  2773  		i = len(header)
  2774  	}
  2775  	switch strings.TrimSpace(strings.ToLower(header[:i])) {
  2776  	case "application/json":
  2777  		s.serveUpdateSubscriptionsJSON(ctx, resp, req)
  2778  	case "application/protobuf":
  2779  		s.serveUpdateSubscriptionsProtobuf(ctx, resp, req)
  2780  	default:
  2781  		msg := fmt.Sprintf("unexpected Content-Type: %q", req.Header.Get("Content-Type"))
  2782  		twerr := badRouteError(msg, req.Method, req.URL.Path)
  2783  		s.writeError(ctx, resp, twerr)
  2784  	}
  2785  }
  2786  
  2787  func (s *roomServiceServer) serveUpdateSubscriptionsJSON(ctx context.Context, resp http.ResponseWriter, req *http.Request) {
  2788  	var err error
  2789  	ctx = ctxsetters.WithMethodName(ctx, "UpdateSubscriptions")
  2790  	ctx, err = callRequestRouted(ctx, s.hooks)
  2791  	if err != nil {
  2792  		s.writeError(ctx, resp, err)
  2793  		return
  2794  	}
  2795  
  2796  	d := json.NewDecoder(req.Body)
  2797  	rawReqBody := json.RawMessage{}
  2798  	if err := d.Decode(&rawReqBody); err != nil {
  2799  		s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err)
  2800  		return
  2801  	}
  2802  	reqContent := new(UpdateSubscriptionsRequest)
  2803  	unmarshaler := protojson.UnmarshalOptions{DiscardUnknown: true}
  2804  	if err = unmarshaler.Unmarshal(rawReqBody, reqContent); err != nil {
  2805  		s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err)
  2806  		return
  2807  	}
  2808  
  2809  	handler := s.RoomService.UpdateSubscriptions
  2810  	if s.interceptor != nil {
  2811  		handler = func(ctx context.Context, req *UpdateSubscriptionsRequest) (*UpdateSubscriptionsResponse, error) {
  2812  			resp, err := s.interceptor(
  2813  				func(ctx context.Context, req interface{}) (interface{}, error) {
  2814  					typedReq, ok := req.(*UpdateSubscriptionsRequest)
  2815  					if !ok {
  2816  						return nil, twirp.InternalError("failed type assertion req.(*UpdateSubscriptionsRequest) when calling interceptor")
  2817  					}
  2818  					return s.RoomService.UpdateSubscriptions(ctx, typedReq)
  2819  				},
  2820  			)(ctx, req)
  2821  			if resp != nil {
  2822  				typedResp, ok := resp.(*UpdateSubscriptionsResponse)
  2823  				if !ok {
  2824  					return nil, twirp.InternalError("failed type assertion resp.(*UpdateSubscriptionsResponse) when calling interceptor")
  2825  				}
  2826  				return typedResp, err
  2827  			}
  2828  			return nil, err
  2829  		}
  2830  	}
  2831  
  2832  	// Call service method
  2833  	var respContent *UpdateSubscriptionsResponse
  2834  	func() {
  2835  		defer ensurePanicResponses(ctx, resp, s.hooks)
  2836  		respContent, err = handler(ctx, reqContent)
  2837  	}()
  2838  
  2839  	if err != nil {
  2840  		s.writeError(ctx, resp, err)
  2841  		return
  2842  	}
  2843  	if respContent == nil {
  2844  		s.writeError(ctx, resp, twirp.InternalError("received a nil *UpdateSubscriptionsResponse and nil error while calling UpdateSubscriptions. nil responses are not supported"))
  2845  		return
  2846  	}
  2847  
  2848  	ctx = callResponsePrepared(ctx, s.hooks)
  2849  
  2850  	marshaler := &protojson.MarshalOptions{UseProtoNames: !s.jsonCamelCase, EmitUnpopulated: !s.jsonSkipDefaults}
  2851  	respBytes, err := marshaler.Marshal(respContent)
  2852  	if err != nil {
  2853  		s.writeError(ctx, resp, wrapInternal(err, "failed to marshal json response"))
  2854  		return
  2855  	}
  2856  
  2857  	ctx = ctxsetters.WithStatusCode(ctx, http.StatusOK)
  2858  	resp.Header().Set("Content-Type", "application/json")
  2859  	resp.Header().Set("Content-Length", strconv.Itoa(len(respBytes)))
  2860  	resp.WriteHeader(http.StatusOK)
  2861  
  2862  	if n, err := resp.Write(respBytes); err != nil {
  2863  		msg := fmt.Sprintf("failed to write response, %d of %d bytes written: %s", n, len(respBytes), err.Error())
  2864  		twerr := twirp.NewError(twirp.Unknown, msg)
  2865  		ctx = callError(ctx, s.hooks, twerr)
  2866  	}
  2867  	callResponseSent(ctx, s.hooks)
  2868  }
  2869  
  2870  func (s *roomServiceServer) serveUpdateSubscriptionsProtobuf(ctx context.Context, resp http.ResponseWriter, req *http.Request) {
  2871  	var err error
  2872  	ctx = ctxsetters.WithMethodName(ctx, "UpdateSubscriptions")
  2873  	ctx, err = callRequestRouted(ctx, s.hooks)
  2874  	if err != nil {
  2875  		s.writeError(ctx, resp, err)
  2876  		return
  2877  	}
  2878  
  2879  	buf, err := io.ReadAll(req.Body)
  2880  	if err != nil {
  2881  		s.handleRequestBodyError(ctx, resp, "failed to read request body", err)
  2882  		return
  2883  	}
  2884  	reqContent := new(UpdateSubscriptionsRequest)
  2885  	if err = proto.Unmarshal(buf, reqContent); err != nil {
  2886  		s.writeError(ctx, resp, malformedRequestError("the protobuf request could not be decoded"))
  2887  		return
  2888  	}
  2889  
  2890  	handler := s.RoomService.UpdateSubscriptions
  2891  	if s.interceptor != nil {
  2892  		handler = func(ctx context.Context, req *UpdateSubscriptionsRequest) (*UpdateSubscriptionsResponse, error) {
  2893  			resp, err := s.interceptor(
  2894  				func(ctx context.Context, req interface{}) (interface{}, error) {
  2895  					typedReq, ok := req.(*UpdateSubscriptionsRequest)
  2896  					if !ok {
  2897  						return nil, twirp.InternalError("failed type assertion req.(*UpdateSubscriptionsRequest) when calling interceptor")
  2898  					}
  2899  					return s.RoomService.UpdateSubscriptions(ctx, typedReq)
  2900  				},
  2901  			)(ctx, req)
  2902  			if resp != nil {
  2903  				typedResp, ok := resp.(*UpdateSubscriptionsResponse)
  2904  				if !ok {
  2905  					return nil, twirp.InternalError("failed type assertion resp.(*UpdateSubscriptionsResponse) when calling interceptor")
  2906  				}
  2907  				return typedResp, err
  2908  			}
  2909  			return nil, err
  2910  		}
  2911  	}
  2912  
  2913  	// Call service method
  2914  	var respContent *UpdateSubscriptionsResponse
  2915  	func() {
  2916  		defer ensurePanicResponses(ctx, resp, s.hooks)
  2917  		respContent, err = handler(ctx, reqContent)
  2918  	}()
  2919  
  2920  	if err != nil {
  2921  		s.writeError(ctx, resp, err)
  2922  		return
  2923  	}
  2924  	if respContent == nil {
  2925  		s.writeError(ctx, resp, twirp.InternalError("received a nil *UpdateSubscriptionsResponse and nil error while calling UpdateSubscriptions. nil responses are not supported"))
  2926  		return
  2927  	}
  2928  
  2929  	ctx = callResponsePrepared(ctx, s.hooks)
  2930  
  2931  	respBytes, err := proto.Marshal(respContent)
  2932  	if err != nil {
  2933  		s.writeError(ctx, resp, wrapInternal(err, "failed to marshal proto response"))
  2934  		return
  2935  	}
  2936  
  2937  	ctx = ctxsetters.WithStatusCode(ctx, http.StatusOK)
  2938  	resp.Header().Set("Content-Type", "application/protobuf")
  2939  	resp.Header().Set("Content-Length", strconv.Itoa(len(respBytes)))
  2940  	resp.WriteHeader(http.StatusOK)
  2941  	if n, err := resp.Write(respBytes); err != nil {
  2942  		msg := fmt.Sprintf("failed to write response, %d of %d bytes written: %s", n, len(respBytes), err.Error())
  2943  		twerr := twirp.NewError(twirp.Unknown, msg)
  2944  		ctx = callError(ctx, s.hooks, twerr)
  2945  	}
  2946  	callResponseSent(ctx, s.hooks)
  2947  }
  2948  
  2949  func (s *roomServiceServer) serveSendData(ctx context.Context, resp http.ResponseWriter, req *http.Request) {
  2950  	header := req.Header.Get("Content-Type")
  2951  	i := strings.Index(header, ";")
  2952  	if i == -1 {
  2953  		i = len(header)
  2954  	}
  2955  	switch strings.TrimSpace(strings.ToLower(header[:i])) {
  2956  	case "application/json":
  2957  		s.serveSendDataJSON(ctx, resp, req)
  2958  	case "application/protobuf":
  2959  		s.serveSendDataProtobuf(ctx, resp, req)
  2960  	default:
  2961  		msg := fmt.Sprintf("unexpected Content-Type: %q", req.Header.Get("Content-Type"))
  2962  		twerr := badRouteError(msg, req.Method, req.URL.Path)
  2963  		s.writeError(ctx, resp, twerr)
  2964  	}
  2965  }
  2966  
  2967  func (s *roomServiceServer) serveSendDataJSON(ctx context.Context, resp http.ResponseWriter, req *http.Request) {
  2968  	var err error
  2969  	ctx = ctxsetters.WithMethodName(ctx, "SendData")
  2970  	ctx, err = callRequestRouted(ctx, s.hooks)
  2971  	if err != nil {
  2972  		s.writeError(ctx, resp, err)
  2973  		return
  2974  	}
  2975  
  2976  	d := json.NewDecoder(req.Body)
  2977  	rawReqBody := json.RawMessage{}
  2978  	if err := d.Decode(&rawReqBody); err != nil {
  2979  		s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err)
  2980  		return
  2981  	}
  2982  	reqContent := new(SendDataRequest)
  2983  	unmarshaler := protojson.UnmarshalOptions{DiscardUnknown: true}
  2984  	if err = unmarshaler.Unmarshal(rawReqBody, reqContent); err != nil {
  2985  		s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err)
  2986  		return
  2987  	}
  2988  
  2989  	handler := s.RoomService.SendData
  2990  	if s.interceptor != nil {
  2991  		handler = func(ctx context.Context, req *SendDataRequest) (*SendDataResponse, error) {
  2992  			resp, err := s.interceptor(
  2993  				func(ctx context.Context, req interface{}) (interface{}, error) {
  2994  					typedReq, ok := req.(*SendDataRequest)
  2995  					if !ok {
  2996  						return nil, twirp.InternalError("failed type assertion req.(*SendDataRequest) when calling interceptor")
  2997  					}
  2998  					return s.RoomService.SendData(ctx, typedReq)
  2999  				},
  3000  			)(ctx, req)
  3001  			if resp != nil {
  3002  				typedResp, ok := resp.(*SendDataResponse)
  3003  				if !ok {
  3004  					return nil, twirp.InternalError("failed type assertion resp.(*SendDataResponse) when calling interceptor")
  3005  				}
  3006  				return typedResp, err
  3007  			}
  3008  			return nil, err
  3009  		}
  3010  	}
  3011  
  3012  	// Call service method
  3013  	var respContent *SendDataResponse
  3014  	func() {
  3015  		defer ensurePanicResponses(ctx, resp, s.hooks)
  3016  		respContent, err = handler(ctx, reqContent)
  3017  	}()
  3018  
  3019  	if err != nil {
  3020  		s.writeError(ctx, resp, err)
  3021  		return
  3022  	}
  3023  	if respContent == nil {
  3024  		s.writeError(ctx, resp, twirp.InternalError("received a nil *SendDataResponse and nil error while calling SendData. nil responses are not supported"))
  3025  		return
  3026  	}
  3027  
  3028  	ctx = callResponsePrepared(ctx, s.hooks)
  3029  
  3030  	marshaler := &protojson.MarshalOptions{UseProtoNames: !s.jsonCamelCase, EmitUnpopulated: !s.jsonSkipDefaults}
  3031  	respBytes, err := marshaler.Marshal(respContent)
  3032  	if err != nil {
  3033  		s.writeError(ctx, resp, wrapInternal(err, "failed to marshal json response"))
  3034  		return
  3035  	}
  3036  
  3037  	ctx = ctxsetters.WithStatusCode(ctx, http.StatusOK)
  3038  	resp.Header().Set("Content-Type", "application/json")
  3039  	resp.Header().Set("Content-Length", strconv.Itoa(len(respBytes)))
  3040  	resp.WriteHeader(http.StatusOK)
  3041  
  3042  	if n, err := resp.Write(respBytes); err != nil {
  3043  		msg := fmt.Sprintf("failed to write response, %d of %d bytes written: %s", n, len(respBytes), err.Error())
  3044  		twerr := twirp.NewError(twirp.Unknown, msg)
  3045  		ctx = callError(ctx, s.hooks, twerr)
  3046  	}
  3047  	callResponseSent(ctx, s.hooks)
  3048  }
  3049  
  3050  func (s *roomServiceServer) serveSendDataProtobuf(ctx context.Context, resp http.ResponseWriter, req *http.Request) {
  3051  	var err error
  3052  	ctx = ctxsetters.WithMethodName(ctx, "SendData")
  3053  	ctx, err = callRequestRouted(ctx, s.hooks)
  3054  	if err != nil {
  3055  		s.writeError(ctx, resp, err)
  3056  		return
  3057  	}
  3058  
  3059  	buf, err := io.ReadAll(req.Body)
  3060  	if err != nil {
  3061  		s.handleRequestBodyError(ctx, resp, "failed to read request body", err)
  3062  		return
  3063  	}
  3064  	reqContent := new(SendDataRequest)
  3065  	if err = proto.Unmarshal(buf, reqContent); err != nil {
  3066  		s.writeError(ctx, resp, malformedRequestError("the protobuf request could not be decoded"))
  3067  		return
  3068  	}
  3069  
  3070  	handler := s.RoomService.SendData
  3071  	if s.interceptor != nil {
  3072  		handler = func(ctx context.Context, req *SendDataRequest) (*SendDataResponse, error) {
  3073  			resp, err := s.interceptor(
  3074  				func(ctx context.Context, req interface{}) (interface{}, error) {
  3075  					typedReq, ok := req.(*SendDataRequest)
  3076  					if !ok {
  3077  						return nil, twirp.InternalError("failed type assertion req.(*SendDataRequest) when calling interceptor")
  3078  					}
  3079  					return s.RoomService.SendData(ctx, typedReq)
  3080  				},
  3081  			)(ctx, req)
  3082  			if resp != nil {
  3083  				typedResp, ok := resp.(*SendDataResponse)
  3084  				if !ok {
  3085  					return nil, twirp.InternalError("failed type assertion resp.(*SendDataResponse) when calling interceptor")
  3086  				}
  3087  				return typedResp, err
  3088  			}
  3089  			return nil, err
  3090  		}
  3091  	}
  3092  
  3093  	// Call service method
  3094  	var respContent *SendDataResponse
  3095  	func() {
  3096  		defer ensurePanicResponses(ctx, resp, s.hooks)
  3097  		respContent, err = handler(ctx, reqContent)
  3098  	}()
  3099  
  3100  	if err != nil {
  3101  		s.writeError(ctx, resp, err)
  3102  		return
  3103  	}
  3104  	if respContent == nil {
  3105  		s.writeError(ctx, resp, twirp.InternalError("received a nil *SendDataResponse and nil error while calling SendData. nil responses are not supported"))
  3106  		return
  3107  	}
  3108  
  3109  	ctx = callResponsePrepared(ctx, s.hooks)
  3110  
  3111  	respBytes, err := proto.Marshal(respContent)
  3112  	if err != nil {
  3113  		s.writeError(ctx, resp, wrapInternal(err, "failed to marshal proto response"))
  3114  		return
  3115  	}
  3116  
  3117  	ctx = ctxsetters.WithStatusCode(ctx, http.StatusOK)
  3118  	resp.Header().Set("Content-Type", "application/protobuf")
  3119  	resp.Header().Set("Content-Length", strconv.Itoa(len(respBytes)))
  3120  	resp.WriteHeader(http.StatusOK)
  3121  	if n, err := resp.Write(respBytes); err != nil {
  3122  		msg := fmt.Sprintf("failed to write response, %d of %d bytes written: %s", n, len(respBytes), err.Error())
  3123  		twerr := twirp.NewError(twirp.Unknown, msg)
  3124  		ctx = callError(ctx, s.hooks, twerr)
  3125  	}
  3126  	callResponseSent(ctx, s.hooks)
  3127  }
  3128  
  3129  func (s *roomServiceServer) serveUpdateRoomMetadata(ctx context.Context, resp http.ResponseWriter, req *http.Request) {
  3130  	header := req.Header.Get("Content-Type")
  3131  	i := strings.Index(header, ";")
  3132  	if i == -1 {
  3133  		i = len(header)
  3134  	}
  3135  	switch strings.TrimSpace(strings.ToLower(header[:i])) {
  3136  	case "application/json":
  3137  		s.serveUpdateRoomMetadataJSON(ctx, resp, req)
  3138  	case "application/protobuf":
  3139  		s.serveUpdateRoomMetadataProtobuf(ctx, resp, req)
  3140  	default:
  3141  		msg := fmt.Sprintf("unexpected Content-Type: %q", req.Header.Get("Content-Type"))
  3142  		twerr := badRouteError(msg, req.Method, req.URL.Path)
  3143  		s.writeError(ctx, resp, twerr)
  3144  	}
  3145  }
  3146  
  3147  func (s *roomServiceServer) serveUpdateRoomMetadataJSON(ctx context.Context, resp http.ResponseWriter, req *http.Request) {
  3148  	var err error
  3149  	ctx = ctxsetters.WithMethodName(ctx, "UpdateRoomMetadata")
  3150  	ctx, err = callRequestRouted(ctx, s.hooks)
  3151  	if err != nil {
  3152  		s.writeError(ctx, resp, err)
  3153  		return
  3154  	}
  3155  
  3156  	d := json.NewDecoder(req.Body)
  3157  	rawReqBody := json.RawMessage{}
  3158  	if err := d.Decode(&rawReqBody); err != nil {
  3159  		s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err)
  3160  		return
  3161  	}
  3162  	reqContent := new(UpdateRoomMetadataRequest)
  3163  	unmarshaler := protojson.UnmarshalOptions{DiscardUnknown: true}
  3164  	if err = unmarshaler.Unmarshal(rawReqBody, reqContent); err != nil {
  3165  		s.handleRequestBodyError(ctx, resp, "the json request could not be decoded", err)
  3166  		return
  3167  	}
  3168  
  3169  	handler := s.RoomService.UpdateRoomMetadata
  3170  	if s.interceptor != nil {
  3171  		handler = func(ctx context.Context, req *UpdateRoomMetadataRequest) (*Room, error) {
  3172  			resp, err := s.interceptor(
  3173  				func(ctx context.Context, req interface{}) (interface{}, error) {
  3174  					typedReq, ok := req.(*UpdateRoomMetadataRequest)
  3175  					if !ok {
  3176  						return nil, twirp.InternalError("failed type assertion req.(*UpdateRoomMetadataRequest) when calling interceptor")
  3177  					}
  3178  					return s.RoomService.UpdateRoomMetadata(ctx, typedReq)
  3179  				},
  3180  			)(ctx, req)
  3181  			if resp != nil {
  3182  				typedResp, ok := resp.(*Room)
  3183  				if !ok {
  3184  					return nil, twirp.InternalError("failed type assertion resp.(*Room) when calling interceptor")
  3185  				}
  3186  				return typedResp, err
  3187  			}
  3188  			return nil, err
  3189  		}
  3190  	}
  3191  
  3192  	// Call service method
  3193  	var respContent *Room
  3194  	func() {
  3195  		defer ensurePanicResponses(ctx, resp, s.hooks)
  3196  		respContent, err = handler(ctx, reqContent)
  3197  	}()
  3198  
  3199  	if err != nil {
  3200  		s.writeError(ctx, resp, err)
  3201  		return
  3202  	}
  3203  	if respContent == nil {
  3204  		s.writeError(ctx, resp, twirp.InternalError("received a nil *Room and nil error while calling UpdateRoomMetadata. nil responses are not supported"))
  3205  		return
  3206  	}
  3207  
  3208  	ctx = callResponsePrepared(ctx, s.hooks)
  3209  
  3210  	marshaler := &protojson.MarshalOptions{UseProtoNames: !s.jsonCamelCase, EmitUnpopulated: !s.jsonSkipDefaults}
  3211  	respBytes, err := marshaler.Marshal(respContent)
  3212  	if err != nil {
  3213  		s.writeError(ctx, resp, wrapInternal(err, "failed to marshal json response"))
  3214  		return
  3215  	}
  3216  
  3217  	ctx = ctxsetters.WithStatusCode(ctx, http.StatusOK)
  3218  	resp.Header().Set("Content-Type", "application/json")
  3219  	resp.Header().Set("Content-Length", strconv.Itoa(len(respBytes)))
  3220  	resp.WriteHeader(http.StatusOK)
  3221  
  3222  	if n, err := resp.Write(respBytes); err != nil {
  3223  		msg := fmt.Sprintf("failed to write response, %d of %d bytes written: %s", n, len(respBytes), err.Error())
  3224  		twerr := twirp.NewError(twirp.Unknown, msg)
  3225  		ctx = callError(ctx, s.hooks, twerr)
  3226  	}
  3227  	callResponseSent(ctx, s.hooks)
  3228  }
  3229  
  3230  func (s *roomServiceServer) serveUpdateRoomMetadataProtobuf(ctx context.Context, resp http.ResponseWriter, req *http.Request) {
  3231  	var err error
  3232  	ctx = ctxsetters.WithMethodName(ctx, "UpdateRoomMetadata")
  3233  	ctx, err = callRequestRouted(ctx, s.hooks)
  3234  	if err != nil {
  3235  		s.writeError(ctx, resp, err)
  3236  		return
  3237  	}
  3238  
  3239  	buf, err := io.ReadAll(req.Body)
  3240  	if err != nil {
  3241  		s.handleRequestBodyError(ctx, resp, "failed to read request body", err)
  3242  		return
  3243  	}
  3244  	reqContent := new(UpdateRoomMetadataRequest)
  3245  	if err = proto.Unmarshal(buf, reqContent); err != nil {
  3246  		s.writeError(ctx, resp, malformedRequestError("the protobuf request could not be decoded"))
  3247  		return
  3248  	}
  3249  
  3250  	handler := s.RoomService.UpdateRoomMetadata
  3251  	if s.interceptor != nil {
  3252  		handler = func(ctx context.Context, req *UpdateRoomMetadataRequest) (*Room, error) {
  3253  			resp, err := s.interceptor(
  3254  				func(ctx context.Context, req interface{}) (interface{}, error) {
  3255  					typedReq, ok := req.(*UpdateRoomMetadataRequest)
  3256  					if !ok {
  3257  						return nil, twirp.InternalError("failed type assertion req.(*UpdateRoomMetadataRequest) when calling interceptor")
  3258  					}
  3259  					return s.RoomService.UpdateRoomMetadata(ctx, typedReq)
  3260  				},
  3261  			)(ctx, req)
  3262  			if resp != nil {
  3263  				typedResp, ok := resp.(*Room)
  3264  				if !ok {
  3265  					return nil, twirp.InternalError("failed type assertion resp.(*Room) when calling interceptor")
  3266  				}
  3267  				return typedResp, err
  3268  			}
  3269  			return nil, err
  3270  		}
  3271  	}
  3272  
  3273  	// Call service method
  3274  	var respContent *Room
  3275  	func() {
  3276  		defer ensurePanicResponses(ctx, resp, s.hooks)
  3277  		respContent, err = handler(ctx, reqContent)
  3278  	}()
  3279  
  3280  	if err != nil {
  3281  		s.writeError(ctx, resp, err)
  3282  		return
  3283  	}
  3284  	if respContent == nil {
  3285  		s.writeError(ctx, resp, twirp.InternalError("received a nil *Room and nil error while calling UpdateRoomMetadata. nil responses are not supported"))
  3286  		return
  3287  	}
  3288  
  3289  	ctx = callResponsePrepared(ctx, s.hooks)
  3290  
  3291  	respBytes, err := proto.Marshal(respContent)
  3292  	if err != nil {
  3293  		s.writeError(ctx, resp, wrapInternal(err, "failed to marshal proto response"))
  3294  		return
  3295  	}
  3296  
  3297  	ctx = ctxsetters.WithStatusCode(ctx, http.StatusOK)
  3298  	resp.Header().Set("Content-Type", "application/protobuf")
  3299  	resp.Header().Set("Content-Length", strconv.Itoa(len(respBytes)))
  3300  	resp.WriteHeader(http.StatusOK)
  3301  	if n, err := resp.Write(respBytes); err != nil {
  3302  		msg := fmt.Sprintf("failed to write response, %d of %d bytes written: %s", n, len(respBytes), err.Error())
  3303  		twerr := twirp.NewError(twirp.Unknown, msg)
  3304  		ctx = callError(ctx, s.hooks, twerr)
  3305  	}
  3306  	callResponseSent(ctx, s.hooks)
  3307  }
  3308  
  3309  func (s *roomServiceServer) ServiceDescriptor() ([]byte, int) {
  3310  	return twirpFileDescriptor2, 0
  3311  }
  3312  
  3313  func (s *roomServiceServer) ProtocGenTwirpVersion() string {
  3314  	return "v8.1.3"
  3315  }
  3316  
  3317  // PathPrefix returns the base service path, in the form: "/<prefix>/<package>.<Service>/"
  3318  // that is everything in a Twirp route except for the <Method>. This can be used for routing,
  3319  // for example to identify the requests that are targeted to this service in a mux.
  3320  func (s *roomServiceServer) PathPrefix() string {
  3321  	return baseServicePath(s.pathPrefix, "livekit", "RoomService")
  3322  }
  3323  
  3324  var twirpFileDescriptor2 = []byte{
  3325  	// 966 bytes of a gzipped FileDescriptorProto
  3326  	0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x56, 0xdd, 0x6e, 0x1b, 0x45,
  3327  	0x14, 0x66, 0x13, 0xdb, 0x8d, 0x8f, 0xf3, 0xe7, 0xd3, 0xa0, 0xac, 0x37, 0xa4, 0x32, 0x1b, 0x24,
  3328  	0x8c, 0x00, 0x17, 0x99, 0x8b, 0xa2, 0x0a, 0x81, 0x9a, 0xb6, 0x94, 0x28, 0xa9, 0x64, 0x8d, 0x8b,
  3329  	0xf8, 0xb9, 0x31, 0x6b, 0xef, 0xd0, 0x8e, 0xe2, 0xdd, 0x59, 0x76, 0xc6, 0xa1, 0x79, 0x03, 0x9e,
  3330  	0x85, 0x17, 0x40, 0xe2, 0x39, 0xb8, 0xe1, 0x05, 0xb8, 0xe0, 0x29, 0xd0, 0xfc, 0x78, 0x7f, 0xec,
  3331  	0xb5, 0x41, 0xbd, 0xf3, 0x9c, 0xff, 0x73, 0xbe, 0x73, 0xbe, 0x35, 0xe0, 0x8c, 0xdd, 0xd0, 0x6b,
  3332  	0x26, 0xc7, 0x29, 0xe7, 0x51, 0x3f, 0x49, 0xb9, 0xe4, 0x78, 0xc7, 0xca, 0xbc, 0xa3, 0x85, 0x32,
  3333  	0xe2, 0x21, 0x9d, 0x09, 0xa3, 0xce, 0xa5, 0xf4, 0x65, 0x4a, 0x85, 0x95, 0xfa, 0x7f, 0x39, 0xd0,
  3334  	0x7e, 0x9c, 0xd2, 0x40, 0x52, 0xc2, 0x79, 0x44, 0xe8, 0xcf, 0x73, 0x2a, 0x24, 0x22, 0xd4, 0xe2,
  3335  	0x20, 0xa2, 0xae, 0xd3, 0x75, 0x7a, 0x4d, 0xa2, 0x7f, 0xe3, 0x19, 0xec, 0xd1, 0x28, 0x91, 0xb7,
  3336  	0x63, 0xc9, 0x22, 0xca, 0xe7, 0xd2, 0xdd, 0xea, 0x3a, 0xbd, 0x3d, 0xb2, 0xab, 0x85, 0x2f, 0x8c,
  3337  	0x0c, 0x3f, 0x80, 0xc3, 0x28, 0x78, 0x3d, 0x4e, 0x82, 0x54, 0xb2, 0x29, 0x4b, 0x82, 0x58, 0x0a,
  3338  	0x77, 0x5b, 0xdb, 0x1d, 0x44, 0xc1, 0xeb, 0x61, 0x41, 0x8c, 0xc7, 0x70, 0x27, 0xe6, 0x21, 0x1d,
  3339  	0xb3, 0xd0, 0xad, 0xe9, 0x34, 0x0d, 0xf5, 0xbc, 0x08, 0xd1, 0x83, 0x9d, 0x88, 0xca, 0x20, 0x0c,
  3340  	0x64, 0xe0, 0xd6, 0xb5, 0x26, 0x7b, 0xe3, 0x87, 0xd0, 0x30, 0xe5, 0xbb, 0x8d, 0xae, 0xd3, 0x6b,
  3341  	0x0d, 0xee, 0xf6, 0x6d, 0x57, 0x7d, 0x55, 0xfe, 0x53, 0xad, 0x22, 0xd6, 0xc4, 0xff, 0x05, 0x20,
  3342  	0x97, 0xe2, 0x03, 0xa8, 0xa9, 0x61, 0xe9, 0x9e, 0x5a, 0x83, 0xb3, 0x92, 0xe3, 0x63, 0x1e, 0x25,
  3343  	0x5c, 0x30, 0x49, 0x6d, 0x04, 0x33, 0x06, 0xa2, 0x1d, 0xf0, 0x13, 0x68, 0xc8, 0x34, 0x98, 0x5e,
  3344  	0x0b, 0xdd, 0x71, 0x6b, 0xe0, 0x66, 0xae, 0x8f, 0xe6, 0x92, 0xbf, 0x50, 0xaa, 0x45, 0x62, 0x63,
  3345  	0xe7, 0xf7, 0xe0, 0xf0, 0x8a, 0x09, 0xa9, 0x22, 0x2f, 0x62, 0xe1, 0x11, 0xd4, 0xd5, 0x18, 0x85,
  3346  	0xeb, 0x74, 0xb7, 0x7b, 0x4d, 0x62, 0x1e, 0xfe, 0x67, 0xd0, 0x2e, 0x58, 0x8a, 0x84, 0xc7, 0x42,
  3347  	0x4d, 0xba, 0xae, 0x12, 0x1b, 0xd3, 0xd6, 0x60, 0xaf, 0x54, 0x2a, 0x31, 0x3a, 0xff, 0x7d, 0x68,
  3348  	0x3f, 0xa1, 0x33, 0xba, 0x82, 0x5b, 0xd6, 0x63, 0xd3, 0x94, 0xef, 0x1f, 0x01, 0x16, 0x0d, 0x4d,
  3349  	0x0e, 0xff, 0x63, 0x38, 0x56, 0x89, 0x8b, 0x88, 0x6c, 0x0a, 0xf2, 0x1d, 0xb8, 0xab, 0xe6, 0xb6,
  3350  	0xdc, 0xcf, 0x61, 0xb7, 0x84, 0xb7, 0xa9, 0x3a, 0x9f, 0x52, 0xc1, 0xe9, 0x22, 0xfe, 0x89, 0x93,
  3351  	0x92, 0xb5, 0x7f, 0x01, 0xc7, 0xaa, 0xb0, 0xa2, 0x51, 0x48, 0x63, 0xc9, 0xe4, 0x6d, 0x55, 0x21,
  3352  	0x6a, 0x39, 0x98, 0xd5, 0x6b, 0x38, 0x9a, 0x24, 0x7b, 0xfb, 0x27, 0xd0, 0x21, 0x34, 0xe2, 0x37,
  3353  	0xb4, 0x10, 0x2c, 0x6b, 0xf8, 0x16, 0x8e, 0x9e, 0xcf, 0xcd, 0x10, 0x34, 0x64, 0x1b, 0xba, 0xdd,
  3354  	0x94, 0x04, 0x4f, 0xa0, 0xa9, 0x51, 0x1e, 0x0b, 0x16, 0xea, 0xd5, 0x6e, 0x92, 0x1d, 0x2d, 0x18,
  3355  	0xb1, 0x50, 0x81, 0x1c, 0xcd, 0x25, 0x35, 0x1b, 0xbd, 0x43, 0xcc, 0xc3, 0x7f, 0x04, 0x6f, 0x2f,
  3356  	0xa5, 0xb6, 0x93, 0xeb, 0x41, 0x5d, 0xbb, 0xda, 0x9d, 0xc4, 0x6c, 0x64, 0xda, 0x4c, 0x0f, 0xcb,
  3357  	0x18, 0xf8, 0x7f, 0x38, 0xe0, 0x7e, 0x93, 0x84, 0x81, 0x2c, 0xf7, 0xf6, 0x66, 0x2d, 0x14, 0x0f,
  3358  	0x6c, 0x7b, 0xe9, 0xc0, 0xbe, 0x00, 0x48, 0x68, 0x1a, 0x31, 0x21, 0x18, 0x8f, 0x75, 0x1b, 0xad,
  3359  	0xc1, 0xbd, 0x2a, 0x28, 0x87, 0x99, 0x15, 0x29, 0x78, 0x64, 0xcc, 0x51, 0xcf, 0x99, 0xc3, 0xff,
  3360  	0xd3, 0x01, 0xcf, 0x14, 0x3f, 0x9a, 0x4f, 0xc4, 0x34, 0x65, 0x89, 0x64, 0x3c, 0x16, 0x6f, 0x5a,
  3361  	0xfe, 0x29, 0x40, 0x86, 0x80, 0x62, 0x17, 0x75, 0x4e, 0xcd, 0x05, 0x04, 0x02, 0xdf, 0x81, 0xa6,
  3362  	0x30, 0x69, 0x26, 0xd4, 0xe2, 0x90, 0x0b, 0xf0, 0x02, 0xb0, 0xb0, 0x7e, 0x63, 0x7b, 0xd8, 0x75,
  3363  	0xbd, 0xb2, 0x5e, 0x55, 0x9f, 0x1a, 0x0a, 0x41, 0xda, 0xc9, 0xb2, 0xc8, 0x3f, 0x85, 0x93, 0xca,
  3364  	0xae, 0xec, 0xc2, 0xfd, 0xee, 0xc0, 0xc1, 0x88, 0xc6, 0xe1, 0x93, 0x40, 0x06, 0x9b, 0x5a, 0x45,
  3365  	0xa8, 0x69, 0x24, 0x54, 0x9b, 0xbb, 0x44, 0xff, 0xc6, 0x8f, 0xa0, 0x76, 0xcd, 0x62, 0xb3, 0x5f,
  3366  	0xfb, 0x85, 0x53, 0x52, 0xb1, 0x86, 0xc1, 0xf4, 0x9a, 0xca, 0xfe, 0x25, 0x8b, 0x43, 0xa2, 0xad,
  3367  	0x14, 0xe9, 0x86, 0x54, 0x48, 0x16, 0x07, 0xaa, 0x02, 0x33, 0x96, 0x9a, 0x1e, 0xcb, 0x41, 0x41,
  3368  	0xae, 0x87, 0xd3, 0x81, 0xba, 0xe4, 0x09, 0x9b, 0x1a, 0x7c, 0xbe, 0x7e, 0x8b, 0x98, 0xe7, 0xaf,
  3369  	0x8e, 0x73, 0xbe, 0x03, 0x8d, 0xb1, 0x7e, 0xf8, 0x08, 0x87, 0x79, 0xe1, 0xb6, 0x9b, 0x4b, 0xe8,
  3370  	0x98, 0x66, 0xd5, 0x16, 0x3f, 0xb7, 0xdb, 0xf2, 0x1f, 0x08, 0x66, 0x4b, 0xb6, 0x55, 0x5e, 0xb2,
  3371  	0xc1, 0xdf, 0x0d, 0x68, 0xa9, 0x38, 0x23, 0x9a, 0xde, 0xb0, 0x29, 0xc5, 0x07, 0x00, 0xf9, 0x37,
  3372  	0x08, 0x73, 0x18, 0x56, 0x3e, 0x4c, 0x5e, 0x99, 0x0b, 0xf1, 0x1c, 0x9a, 0x19, 0x7d, 0x62, 0x27,
  3373  	0xd3, 0x2d, 0x93, 0xaf, 0xe7, 0x55, 0xa9, 0xec, 0x11, 0x3e, 0x05, 0xc8, 0xf9, 0xb1, 0x90, 0x7c,
  3374  	0x85, 0x5d, 0xbd, 0x93, 0x4a, 0x9d, 0x0d, 0xf3, 0xad, 0xe1, 0xfc, 0xd2, 0x27, 0xae, 0x5b, 0x4a,
  3375  	0x5b, 0xc1, 0xb5, 0xde, 0xbb, 0x1b, 0x2c, 0x6c, 0xe0, 0x2b, 0xd8, 0x7f, 0x46, 0x8b, 0xaa, 0x42,
  3376  	0xd8, 0x35, 0xcc, 0xe9, 0xad, 0x25, 0x5f, 0xfc, 0x1e, 0xda, 0x2b, 0x1c, 0xf9, 0x3f, 0x02, 0xfa,
  3377  	0xb9, 0xc5, 0x3a, 0x86, 0xc5, 0x11, 0xa0, 0xa2, 0xb9, 0xe1, 0x7c, 0x32, 0x63, 0xe2, 0x15, 0x0d,
  3378  	0xf5, 0x99, 0xe0, 0x69, 0xe6, 0x59, 0x45, 0xbf, 0xde, 0xbd, 0x75, 0x6a, 0x1b, 0x74, 0x08, 0xed,
  3379  	0x15, 0xde, 0xc3, 0x7c, 0x6a, 0xeb, 0x38, 0x71, 0xc3, 0x04, 0x7e, 0x84, 0xbb, 0x15, 0x67, 0x8b,
  3380  	0x67, 0x4b, 0x31, 0xab, 0xa8, 0xca, 0x7b, 0x6f, 0xb3, 0x91, 0xad, 0xf9, 0x4b, 0xd8, 0x59, 0xdc,
  3381  	0x0f, 0xe6, 0x75, 0x2c, 0x71, 0x81, 0xd7, 0xa9, 0xd0, 0xd8, 0x00, 0xcf, 0x00, 0x57, 0x8f, 0x0d,
  3382  	0xfd, 0xa5, 0xe4, 0x15, 0x97, 0xb8, 0x74, 0x1f, 0xe7, 0x5f, 0xfd, 0x70, 0xf6, 0x92, 0xc9, 0x57,
  3383  	0xf3, 0x49, 0x7f, 0xca, 0xa3, 0xfb, 0x56, 0x75, 0x5f, 0xff, 0xf3, 0x9b, 0xf2, 0xd9, 0x42, 0xf0,
  3384  	0xdb, 0xd6, 0xde, 0x15, 0xbb, 0xa1, 0x97, 0x6a, 0x58, 0x4a, 0xf5, 0xcf, 0xd6, 0xbe, 0x7d, 0x3f,
  3385  	0x7c, 0xa8, 0x05, 0x93, 0x86, 0x76, 0xf9, 0xf4, 0xdf, 0x00, 0x00, 0x00, 0xff, 0xff, 0x11, 0xf7,
  3386  	0xe4, 0x7c, 0x77, 0x0a, 0x00, 0x00,
  3387  }