github.com/twilio/twilio-go@v1.20.1/rest/video/v1/rooms.go (about) 1 /* 2 * This code was generated by 3 * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ 4 * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ 5 * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ 6 * 7 * Twilio - Video 8 * This is the public Twilio REST API. 9 * 10 * NOTE: This class is auto generated by OpenAPI Generator. 11 * https://openapi-generator.tech 12 * Do not edit the class manually. 13 */ 14 15 package openapi 16 17 import ( 18 "encoding/json" 19 "fmt" 20 "net/url" 21 "strings" 22 "time" 23 24 "github.com/twilio/twilio-go/client" 25 ) 26 27 // Optional parameters for the method 'CreateRoom' 28 type CreateRoomParams struct { 29 // Deprecated, now always considered to be true. 30 EnableTurn *bool `json:"EnableTurn,omitempty"` 31 // 32 Type *string `json:"Type,omitempty"` 33 // An application-defined string that uniquely identifies the resource. It can be used as a `room_sid` in place of the resource's `sid` in the URL to address the resource, assuming it does not contain any [reserved characters](https://tools.ietf.org/html/rfc3986#section-2.2) that would need to be URL encoded. This value is unique for `in-progress` rooms. SDK clients can use this name to connect to the room. REST API clients can use this name in place of the Room SID to interact with the room as long as the room is `in-progress`. 34 UniqueName *string `json:"UniqueName,omitempty"` 35 // The URL we should call using the `status_callback_method` to send status information to your application on every room event. See [Status Callbacks](https://www.twilio.com/docs/video/api/status-callbacks) for more info. 36 StatusCallback *string `json:"StatusCallback,omitempty"` 37 // The HTTP method we should use to call `status_callback`. Can be `POST` or `GET`. 38 StatusCallbackMethod *string `json:"StatusCallbackMethod,omitempty"` 39 // The maximum number of concurrent Participants allowed in the room. Peer-to-peer rooms can have up to 10 Participants. Small Group rooms can have up to 4 Participants. Group rooms can have up to 50 Participants. 40 MaxParticipants *int `json:"MaxParticipants,omitempty"` 41 // Whether to start recording when Participants connect. ***This feature is not available in `peer-to-peer` rooms.*** 42 RecordParticipantsOnConnect *bool `json:"RecordParticipantsOnConnect,omitempty"` 43 // An array of the video codecs that are supported when publishing a track in the room. Can be: `VP8` and `H264`. ***This feature is not available in `peer-to-peer` rooms*** 44 VideoCodecs *[]string `json:"VideoCodecs,omitempty"` 45 // The region for the media server in Group Rooms. Can be: one of the [available Media Regions](https://www.twilio.com/docs/video/ip-addresses#group-rooms-media-servers). ***This feature is not available in `peer-to-peer` rooms.*** 46 MediaRegion *string `json:"MediaRegion,omitempty"` 47 // A collection of Recording Rules that describe how to include or exclude matching tracks for recording 48 RecordingRules *interface{} `json:"RecordingRules,omitempty"` 49 // When set to true, indicates that the participants in the room will only publish audio. No video tracks will be allowed. Group rooms only. 50 AudioOnly *bool `json:"AudioOnly,omitempty"` 51 // The maximum number of seconds a Participant can be connected to the room. The maximum possible value is 86400 seconds (24 hours). The default is 14400 seconds (4 hours). 52 MaxParticipantDuration *int `json:"MaxParticipantDuration,omitempty"` 53 // Configures how long (in minutes) a room will remain active after last participant leaves. Valid values range from 1 to 60 minutes (no fractions). 54 EmptyRoomTimeout *int `json:"EmptyRoomTimeout,omitempty"` 55 // Configures how long (in minutes) a room will remain active if no one joins. Valid values range from 1 to 60 minutes (no fractions). 56 UnusedRoomTimeout *int `json:"UnusedRoomTimeout,omitempty"` 57 // When set to true, indicated that this is the large room. 58 LargeRoom *bool `json:"LargeRoom,omitempty"` 59 } 60 61 func (params *CreateRoomParams) SetEnableTurn(EnableTurn bool) *CreateRoomParams { 62 params.EnableTurn = &EnableTurn 63 return params 64 } 65 func (params *CreateRoomParams) SetType(Type string) *CreateRoomParams { 66 params.Type = &Type 67 return params 68 } 69 func (params *CreateRoomParams) SetUniqueName(UniqueName string) *CreateRoomParams { 70 params.UniqueName = &UniqueName 71 return params 72 } 73 func (params *CreateRoomParams) SetStatusCallback(StatusCallback string) *CreateRoomParams { 74 params.StatusCallback = &StatusCallback 75 return params 76 } 77 func (params *CreateRoomParams) SetStatusCallbackMethod(StatusCallbackMethod string) *CreateRoomParams { 78 params.StatusCallbackMethod = &StatusCallbackMethod 79 return params 80 } 81 func (params *CreateRoomParams) SetMaxParticipants(MaxParticipants int) *CreateRoomParams { 82 params.MaxParticipants = &MaxParticipants 83 return params 84 } 85 func (params *CreateRoomParams) SetRecordParticipantsOnConnect(RecordParticipantsOnConnect bool) *CreateRoomParams { 86 params.RecordParticipantsOnConnect = &RecordParticipantsOnConnect 87 return params 88 } 89 func (params *CreateRoomParams) SetVideoCodecs(VideoCodecs []string) *CreateRoomParams { 90 params.VideoCodecs = &VideoCodecs 91 return params 92 } 93 func (params *CreateRoomParams) SetMediaRegion(MediaRegion string) *CreateRoomParams { 94 params.MediaRegion = &MediaRegion 95 return params 96 } 97 func (params *CreateRoomParams) SetRecordingRules(RecordingRules interface{}) *CreateRoomParams { 98 params.RecordingRules = &RecordingRules 99 return params 100 } 101 func (params *CreateRoomParams) SetAudioOnly(AudioOnly bool) *CreateRoomParams { 102 params.AudioOnly = &AudioOnly 103 return params 104 } 105 func (params *CreateRoomParams) SetMaxParticipantDuration(MaxParticipantDuration int) *CreateRoomParams { 106 params.MaxParticipantDuration = &MaxParticipantDuration 107 return params 108 } 109 func (params *CreateRoomParams) SetEmptyRoomTimeout(EmptyRoomTimeout int) *CreateRoomParams { 110 params.EmptyRoomTimeout = &EmptyRoomTimeout 111 return params 112 } 113 func (params *CreateRoomParams) SetUnusedRoomTimeout(UnusedRoomTimeout int) *CreateRoomParams { 114 params.UnusedRoomTimeout = &UnusedRoomTimeout 115 return params 116 } 117 func (params *CreateRoomParams) SetLargeRoom(LargeRoom bool) *CreateRoomParams { 118 params.LargeRoom = &LargeRoom 119 return params 120 } 121 122 // 123 func (c *ApiService) CreateRoom(params *CreateRoomParams) (*VideoV1Room, error) { 124 path := "/v1/Rooms" 125 126 data := url.Values{} 127 headers := make(map[string]interface{}) 128 129 if params != nil && params.EnableTurn != nil { 130 data.Set("EnableTurn", fmt.Sprint(*params.EnableTurn)) 131 } 132 if params != nil && params.Type != nil { 133 data.Set("Type", *params.Type) 134 } 135 if params != nil && params.UniqueName != nil { 136 data.Set("UniqueName", *params.UniqueName) 137 } 138 if params != nil && params.StatusCallback != nil { 139 data.Set("StatusCallback", *params.StatusCallback) 140 } 141 if params != nil && params.StatusCallbackMethod != nil { 142 data.Set("StatusCallbackMethod", *params.StatusCallbackMethod) 143 } 144 if params != nil && params.MaxParticipants != nil { 145 data.Set("MaxParticipants", fmt.Sprint(*params.MaxParticipants)) 146 } 147 if params != nil && params.RecordParticipantsOnConnect != nil { 148 data.Set("RecordParticipantsOnConnect", fmt.Sprint(*params.RecordParticipantsOnConnect)) 149 } 150 if params != nil && params.VideoCodecs != nil { 151 for _, item := range *params.VideoCodecs { 152 data.Add("VideoCodecs", item) 153 } 154 } 155 if params != nil && params.MediaRegion != nil { 156 data.Set("MediaRegion", *params.MediaRegion) 157 } 158 if params != nil && params.RecordingRules != nil { 159 v, err := json.Marshal(params.RecordingRules) 160 161 if err != nil { 162 return nil, err 163 } 164 165 data.Set("RecordingRules", string(v)) 166 } 167 if params != nil && params.AudioOnly != nil { 168 data.Set("AudioOnly", fmt.Sprint(*params.AudioOnly)) 169 } 170 if params != nil && params.MaxParticipantDuration != nil { 171 data.Set("MaxParticipantDuration", fmt.Sprint(*params.MaxParticipantDuration)) 172 } 173 if params != nil && params.EmptyRoomTimeout != nil { 174 data.Set("EmptyRoomTimeout", fmt.Sprint(*params.EmptyRoomTimeout)) 175 } 176 if params != nil && params.UnusedRoomTimeout != nil { 177 data.Set("UnusedRoomTimeout", fmt.Sprint(*params.UnusedRoomTimeout)) 178 } 179 if params != nil && params.LargeRoom != nil { 180 data.Set("LargeRoom", fmt.Sprint(*params.LargeRoom)) 181 } 182 183 resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) 184 if err != nil { 185 return nil, err 186 } 187 188 defer resp.Body.Close() 189 190 ps := &VideoV1Room{} 191 if err := json.NewDecoder(resp.Body).Decode(ps); err != nil { 192 return nil, err 193 } 194 195 return ps, err 196 } 197 198 // 199 func (c *ApiService) FetchRoom(Sid string) (*VideoV1Room, error) { 200 path := "/v1/Rooms/{Sid}" 201 path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) 202 203 data := url.Values{} 204 headers := make(map[string]interface{}) 205 206 resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) 207 if err != nil { 208 return nil, err 209 } 210 211 defer resp.Body.Close() 212 213 ps := &VideoV1Room{} 214 if err := json.NewDecoder(resp.Body).Decode(ps); err != nil { 215 return nil, err 216 } 217 218 return ps, err 219 } 220 221 // Optional parameters for the method 'ListRoom' 222 type ListRoomParams struct { 223 // Read only the rooms with this status. Can be: `in-progress` (default) or `completed` 224 Status *string `json:"Status,omitempty"` 225 // Read only rooms with the this `unique_name`. 226 UniqueName *string `json:"UniqueName,omitempty"` 227 // Read only rooms that started on or after this date, given as `YYYY-MM-DD`. 228 DateCreatedAfter *time.Time `json:"DateCreatedAfter,omitempty"` 229 // Read only rooms that started before this date, given as `YYYY-MM-DD`. 230 DateCreatedBefore *time.Time `json:"DateCreatedBefore,omitempty"` 231 // How many resources to return in each list page. The default is 50, and the maximum is 1000. 232 PageSize *int `json:"PageSize,omitempty"` 233 // Max number of records to return. 234 Limit *int `json:"limit,omitempty"` 235 } 236 237 func (params *ListRoomParams) SetStatus(Status string) *ListRoomParams { 238 params.Status = &Status 239 return params 240 } 241 func (params *ListRoomParams) SetUniqueName(UniqueName string) *ListRoomParams { 242 params.UniqueName = &UniqueName 243 return params 244 } 245 func (params *ListRoomParams) SetDateCreatedAfter(DateCreatedAfter time.Time) *ListRoomParams { 246 params.DateCreatedAfter = &DateCreatedAfter 247 return params 248 } 249 func (params *ListRoomParams) SetDateCreatedBefore(DateCreatedBefore time.Time) *ListRoomParams { 250 params.DateCreatedBefore = &DateCreatedBefore 251 return params 252 } 253 func (params *ListRoomParams) SetPageSize(PageSize int) *ListRoomParams { 254 params.PageSize = &PageSize 255 return params 256 } 257 func (params *ListRoomParams) SetLimit(Limit int) *ListRoomParams { 258 params.Limit = &Limit 259 return params 260 } 261 262 // Retrieve a single page of Room records from the API. Request is executed immediately. 263 func (c *ApiService) PageRoom(params *ListRoomParams, pageToken, pageNumber string) (*ListRoomResponse, error) { 264 path := "/v1/Rooms" 265 266 data := url.Values{} 267 headers := make(map[string]interface{}) 268 269 if params != nil && params.Status != nil { 270 data.Set("Status", *params.Status) 271 } 272 if params != nil && params.UniqueName != nil { 273 data.Set("UniqueName", *params.UniqueName) 274 } 275 if params != nil && params.DateCreatedAfter != nil { 276 data.Set("DateCreatedAfter", fmt.Sprint((*params.DateCreatedAfter).Format(time.RFC3339))) 277 } 278 if params != nil && params.DateCreatedBefore != nil { 279 data.Set("DateCreatedBefore", fmt.Sprint((*params.DateCreatedBefore).Format(time.RFC3339))) 280 } 281 if params != nil && params.PageSize != nil { 282 data.Set("PageSize", fmt.Sprint(*params.PageSize)) 283 } 284 285 if pageToken != "" { 286 data.Set("PageToken", pageToken) 287 } 288 if pageNumber != "" { 289 data.Set("Page", pageNumber) 290 } 291 292 resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) 293 if err != nil { 294 return nil, err 295 } 296 297 defer resp.Body.Close() 298 299 ps := &ListRoomResponse{} 300 if err := json.NewDecoder(resp.Body).Decode(ps); err != nil { 301 return nil, err 302 } 303 304 return ps, err 305 } 306 307 // Lists Room records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. 308 func (c *ApiService) ListRoom(params *ListRoomParams) ([]VideoV1Room, error) { 309 response, errors := c.StreamRoom(params) 310 311 records := make([]VideoV1Room, 0) 312 for record := range response { 313 records = append(records, record) 314 } 315 316 if err := <-errors; err != nil { 317 return nil, err 318 } 319 320 return records, nil 321 } 322 323 // Streams Room records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. 324 func (c *ApiService) StreamRoom(params *ListRoomParams) (chan VideoV1Room, chan error) { 325 if params == nil { 326 params = &ListRoomParams{} 327 } 328 params.SetPageSize(client.ReadLimits(params.PageSize, params.Limit)) 329 330 recordChannel := make(chan VideoV1Room, 1) 331 errorChannel := make(chan error, 1) 332 333 response, err := c.PageRoom(params, "", "") 334 if err != nil { 335 errorChannel <- err 336 close(recordChannel) 337 close(errorChannel) 338 } else { 339 go c.streamRoom(response, params, recordChannel, errorChannel) 340 } 341 342 return recordChannel, errorChannel 343 } 344 345 func (c *ApiService) streamRoom(response *ListRoomResponse, params *ListRoomParams, recordChannel chan VideoV1Room, errorChannel chan error) { 346 curRecord := 1 347 348 for response != nil { 349 responseRecords := response.Rooms 350 for item := range responseRecords { 351 recordChannel <- responseRecords[item] 352 curRecord += 1 353 if params.Limit != nil && *params.Limit < curRecord { 354 close(recordChannel) 355 close(errorChannel) 356 return 357 } 358 } 359 360 record, err := client.GetNext(c.baseURL, response, c.getNextListRoomResponse) 361 if err != nil { 362 errorChannel <- err 363 break 364 } else if record == nil { 365 break 366 } 367 368 response = record.(*ListRoomResponse) 369 } 370 371 close(recordChannel) 372 close(errorChannel) 373 } 374 375 func (c *ApiService) getNextListRoomResponse(nextPageUrl string) (interface{}, error) { 376 if nextPageUrl == "" { 377 return nil, nil 378 } 379 resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) 380 if err != nil { 381 return nil, err 382 } 383 384 defer resp.Body.Close() 385 386 ps := &ListRoomResponse{} 387 if err := json.NewDecoder(resp.Body).Decode(ps); err != nil { 388 return nil, err 389 } 390 return ps, nil 391 } 392 393 // Optional parameters for the method 'UpdateRoom' 394 type UpdateRoomParams struct { 395 // 396 Status *string `json:"Status,omitempty"` 397 } 398 399 func (params *UpdateRoomParams) SetStatus(Status string) *UpdateRoomParams { 400 params.Status = &Status 401 return params 402 } 403 404 // 405 func (c *ApiService) UpdateRoom(Sid string, params *UpdateRoomParams) (*VideoV1Room, error) { 406 path := "/v1/Rooms/{Sid}" 407 path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) 408 409 data := url.Values{} 410 headers := make(map[string]interface{}) 411 412 if params != nil && params.Status != nil { 413 data.Set("Status", *params.Status) 414 } 415 416 resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) 417 if err != nil { 418 return nil, err 419 } 420 421 defer resp.Body.Close() 422 423 ps := &VideoV1Room{} 424 if err := json.NewDecoder(resp.Body).Decode(ps); err != nil { 425 return nil, err 426 } 427 428 return ps, err 429 }