com.twilio.rest.video.v1.RoomCreator Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of common-thirdparty.twilio
Show all versions of common-thirdparty.twilio
The parent for all OSGi wrapped third party libraries
/**
* This code was generated by
* \ / _ _ _| _ _
* | (_)\/(_)(_|\/| |(/_ v1.0.0
* / /
*/
package com.twilio.rest.video.v1;
import com.twilio.base.Creator;
import com.twilio.converter.Promoter;
import com.twilio.exception.ApiConnectionException;
import com.twilio.exception.ApiException;
import com.twilio.exception.RestException;
import com.twilio.http.HttpMethod;
import com.twilio.http.Request;
import com.twilio.http.Response;
import com.twilio.http.TwilioRestClient;
import com.twilio.rest.Domains;
import java.net.URI;
import java.util.List;
public class RoomCreator extends Creator {
private Boolean enableTurn;
private Room.RoomType type;
private String uniqueName;
private URI statusCallback;
private HttpMethod statusCallbackMethod;
private Integer maxParticipants;
private Boolean recordParticipantsOnConnect;
private List videoCodecs;
private String mediaRegion;
/**
* Use Twilio Network Traversal for TURN service. Defaults to true. Only
* applicable to Rooms with type `peer-to-peer`..
*
* @param enableTurn Use Twilio Network Traversal for TURN service.
* @return this
*/
public RoomCreator setEnableTurn(final Boolean enableTurn) {
this.enableTurn = enableTurn;
return this;
}
/**
* Type of room, either `peer-to-peer`, `group-small` or `group`. Will be
* `group` by default..
*
* @param type Type of room, either peer-to-peer, group-small or group.
* @return this
*/
public RoomCreator setType(final Room.RoomType type) {
this.type = type;
return this;
}
/**
* Name of the Room. This is unique for `in-progress` rooms. If not provided,
* Room name will be set to the Room Sid..
*
* @param uniqueName Name of the Room.
* @return this
*/
public RoomCreator setUniqueName(final String uniqueName) {
this.uniqueName = uniqueName;
return this;
}
/**
* A URL that Twilio sends asynchronous webhook requests to on every room event.
* If not provided, status callback events will not be dispatched..
*
* @param statusCallback A URL that Twilio sends asynchronous webhook requests
* to on every room event.
* @return this
*/
public RoomCreator setStatusCallback(final URI statusCallback) {
this.statusCallback = statusCallback;
return this;
}
/**
* A URL that Twilio sends asynchronous webhook requests to on every room event.
* If not provided, status callback events will not be dispatched..
*
* @param statusCallback A URL that Twilio sends asynchronous webhook requests
* to on every room event.
* @return this
*/
public RoomCreator setStatusCallback(final String statusCallback) {
return setStatusCallback(Promoter.uriFromString(statusCallback));
}
/**
* HTTP method Twilio should use when requesting the above URL. Defaults to
* `POST`..
*
* @param statusCallbackMethod HTTP method Twilio should use when requesting
* the above URL.
* @return this
*/
public RoomCreator setStatusCallbackMethod(final HttpMethod statusCallbackMethod) {
this.statusCallbackMethod = statusCallbackMethod;
return this;
}
/**
* Maximum number of Participants in the Room. Peer-to-peer rooms can have a
* maximum of 10 Participants. Small Group rooms can have a max of 4
* Participants. Group rooms can have a max of 50 Participants.
*
* @param maxParticipants Maximum number of Participants in the Room.
* @return this
*/
public RoomCreator setMaxParticipants(final Integer maxParticipants) {
this.maxParticipants = maxParticipants;
return this;
}
/**
* Start Participant recording when connected. ***This feature is not available
* in `peer-to-peer` rooms.***.
*
* @param recordParticipantsOnConnect Start Participant recording when
* connected.
* @return this
*/
public RoomCreator setRecordParticipantsOnConnect(final Boolean recordParticipantsOnConnect) {
this.recordParticipantsOnConnect = recordParticipantsOnConnect;
return this;
}
/**
* An array of video codecs supported when publishing a Track in the Room.
* `VP8` and `H264` codecs are supported. ***This feature is not available in
* `peer-to-peer` rooms***.
*
* @param videoCodecs An array of video codecs supported when publishing a
* Track in the Room.
* @return this
*/
public RoomCreator setVideoCodecs(final List videoCodecs) {
this.videoCodecs = videoCodecs;
return this;
}
/**
* An array of video codecs supported when publishing a Track in the Room.
* `VP8` and `H264` codecs are supported. ***This feature is not available in
* `peer-to-peer` rooms***.
*
* @param videoCodecs An array of video codecs supported when publishing a
* Track in the Room.
* @return this
*/
public RoomCreator setVideoCodecs(final Room.VideoCodec videoCodecs) {
return setVideoCodecs(Promoter.listOfOne(videoCodecs));
}
/**
* Region for the media server in Group Rooms. Default region is `us1`. See
* the list of [available Media
* Regions.](https://www.twilio.com/docs/api/video/ip-address-whitelisting#group-rooms-media-servers)***This feature is not available in `peer-to-peer` rooms.***.
*
* @param mediaRegion Region for the media server in Group Rooms.
* @return this
*/
public RoomCreator setMediaRegion(final String mediaRegion) {
this.mediaRegion = mediaRegion;
return this;
}
/**
* Make the request to the Twilio API to perform the create.
*
* @param client TwilioRestClient with which to make the request
* @return Created Room
*/
@Override
@SuppressWarnings("checkstyle:linelength")
public Room create(final TwilioRestClient client) {
Request request = new Request(
HttpMethod.POST,
Domains.VIDEO.toString(),
"/v1/Rooms",
client.getRegion()
);
addPostParams(request);
Response response = client.request(request);
if (response == null) {
throw new ApiConnectionException("Room creation failed: Unable to connect to server");
} else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) {
RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper());
if (restException == null) {
throw new ApiException("Server Error, no content");
}
throw new ApiException(
restException.getMessage(),
restException.getCode(),
restException.getMoreInfo(),
restException.getStatus(),
null
);
}
return Room.fromJson(response.getStream(), client.getObjectMapper());
}
/**
* Add the requested post parameters to the Request.
*
* @param request Request to add post params to
*/
private void addPostParams(final Request request) {
if (enableTurn != null) {
request.addPostParam("EnableTurn", enableTurn.toString());
}
if (type != null) {
request.addPostParam("Type", type.toString());
}
if (uniqueName != null) {
request.addPostParam("UniqueName", uniqueName);
}
if (statusCallback != null) {
request.addPostParam("StatusCallback", statusCallback.toString());
}
if (statusCallbackMethod != null) {
request.addPostParam("StatusCallbackMethod", statusCallbackMethod.toString());
}
if (maxParticipants != null) {
request.addPostParam("MaxParticipants", maxParticipants.toString());
}
if (recordParticipantsOnConnect != null) {
request.addPostParam("RecordParticipantsOnConnect", recordParticipantsOnConnect.toString());
}
if (videoCodecs != null) {
for (Room.VideoCodec prop : videoCodecs) {
request.addPostParam("VideoCodecs", prop.toString());
}
}
if (mediaRegion != null) {
request.addPostParam("MediaRegion", mediaRegion);
}
}
}