com.twilio.rest.video.v1.CompositionHookUpdater Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of twilio Show documentation
Show all versions of twilio Show documentation
Twilio Java Helper Library
/**
* This code was generated by
* \ / _ _ _| _ _
* | (_)\/(_)(_|\/| |(/_ v1.0.0
* / /
*/
package com.twilio.rest.video.v1;
import com.twilio.base.Updater;
import com.twilio.converter.Converter;
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;
import java.util.Map;
/**
* PLEASE NOTE that this class contains preview products that are subject to
* change. Use them with caution. If you currently do not have developer preview
* access, please contact [email protected].
*/
public class CompositionHookUpdater extends Updater {
private final String pathSid;
private final String friendlyName;
private Boolean enabled;
private Map videoLayout;
private List audioSources;
private List audioSourcesExcluded;
private Boolean trim;
private CompositionHook.Format format;
private String resolution;
private URI statusCallback;
private HttpMethod statusCallbackMethod;
/**
* Construct a new CompositionHookUpdater.
*
* @param pathSid The SID that identifies the resource to update
* @param friendlyName A unique string to describe the resource
*/
public CompositionHookUpdater(final String pathSid,
final String friendlyName) {
this.pathSid = pathSid;
this.friendlyName = friendlyName;
}
/**
* Whether the composition hook is active. When `true`, the composition hook
* will be triggered for every completed Group Room in the account. When
* `false`, the composition hook never triggers..
*
* @param enabled Whether the composition hook is active
* @return this
*/
public CompositionHookUpdater setEnabled(final Boolean enabled) {
this.enabled = enabled;
return this;
}
/**
* A JSON object that describes the video layout of the composition hook in
* terms of regions. See Specifying
* Video Layouts for more info..
*
* @param videoLayout A JSON object that describes the video layout of the
* composition hook
* @return this
*/
public CompositionHookUpdater setVideoLayout(final Map videoLayout) {
this.videoLayout = videoLayout;
return this;
}
/**
* An array of track names from the same group room to merge into the
* compositions created by the composition hook. Can include zero or more track
* names. A composition triggered by the composition hook includes all audio
* sources specified in `audio_sources` except those specified in
* `audio_sources_excluded`. The track names in this parameter can include an
* asterisk as a wild card character, which matches zero or more characters in a
* track name. For example, `student*` includes tracks named `student` as well
* as `studentTeam`..
*
* @param audioSources An array of track names from the same group room to merge
* @return this
*/
public CompositionHookUpdater setAudioSources(final List audioSources) {
this.audioSources = audioSources;
return this;
}
/**
* An array of track names from the same group room to merge into the
* compositions created by the composition hook. Can include zero or more track
* names. A composition triggered by the composition hook includes all audio
* sources specified in `audio_sources` except those specified in
* `audio_sources_excluded`. The track names in this parameter can include an
* asterisk as a wild card character, which matches zero or more characters in a
* track name. For example, `student*` includes tracks named `student` as well
* as `studentTeam`..
*
* @param audioSources An array of track names from the same group room to merge
* @return this
*/
public CompositionHookUpdater setAudioSources(final String audioSources) {
return setAudioSources(Promoter.listOfOne(audioSources));
}
/**
* An array of track names to exclude. A composition triggered by the
* composition hook includes all audio sources specified in `audio_sources`
* except for those specified in `audio_sources_excluded`. The track names in
* this parameter can include an asterisk as a wild card character, which
* matches zero or more characters in a track name. For example, `student*`
* excludes `student` as well as `studentTeam`. This parameter can also be
* empty..
*
* @param audioSourcesExcluded An array of track names to exclude
* @return this
*/
public CompositionHookUpdater setAudioSourcesExcluded(final List audioSourcesExcluded) {
this.audioSourcesExcluded = audioSourcesExcluded;
return this;
}
/**
* An array of track names to exclude. A composition triggered by the
* composition hook includes all audio sources specified in `audio_sources`
* except for those specified in `audio_sources_excluded`. The track names in
* this parameter can include an asterisk as a wild card character, which
* matches zero or more characters in a track name. For example, `student*`
* excludes `student` as well as `studentTeam`. This parameter can also be
* empty..
*
* @param audioSourcesExcluded An array of track names to exclude
* @return this
*/
public CompositionHookUpdater setAudioSourcesExcluded(final String audioSourcesExcluded) {
return setAudioSourcesExcluded(Promoter.listOfOne(audioSourcesExcluded));
}
/**
* Whether to clip the intervals where there is no active media in the
* compositions triggered by the composition hook. The default is `true`.
* Compositions with `trim` enabled are shorter when the Room is created and no
* Participant joins for a while as well as if all the Participants leave the
* room and join later, because those gaps will be removed. See Specifying
* Video Layouts for more info..
*
* @param trim Whether to clip the intervals where there is no active media in
* the Compositions triggered by the composition hook
* @return this
*/
public CompositionHookUpdater setTrim(final Boolean trim) {
this.trim = trim;
return this;
}
/**
* The container format of the media files used by the compositions created by
* the composition hook. Can be: `mp4` or `webm` and the default is `webm`. If
* `mp4` or `webm`, `audio_sources` must have one or more tracks and/or a
* `video_layout` element must contain a valid `video_sources` list, otherwise
* an error occurs..
*
* @param format The container format of the media files used by the
* compositions created by the composition hook
* @return this
*/
public CompositionHookUpdater setFormat(final CompositionHook.Format format) {
this.format = format;
return this;
}
/**
* A string that describes the columns (width) and rows (height) of the
* generated composed video in pixels. Defaults to `640x480`.
* The string's format is `{width}x{height}` where:
*
* * 16 <= `{width}` <= 1280
* * 16 <= `{height}` <= 1280
* * `{width}` * `{height}` <= 921,600
*
* Typical values are:
*
* * HD = `1280x720`
* * PAL = `1024x576`
* * VGA = `640x480`
* * CIF = `320x240`
*
* Note that the `resolution` imposes an aspect ratio to the resulting
* composition. When the original video tracks are constrained by the aspect
* ratio, they are scaled to fit. See Specifying
* Video Layouts for more info..
*
* @param resolution A string that describes the columns (width) and rows
* (height) of the generated composed video in pixels
* @return this
*/
public CompositionHookUpdater setResolution(final String resolution) {
this.resolution = resolution;
return this;
}
/**
* The URL we should call using the `status_callback_method` to send status
* information to your application on every composition event. If not provided,
* status callback events will not be dispatched..
*
* @param statusCallback The URL we should call to send status information to
* your application
* @return this
*/
public CompositionHookUpdater setStatusCallback(final URI statusCallback) {
this.statusCallback = statusCallback;
return this;
}
/**
* The URL we should call using the `status_callback_method` to send status
* information to your application on every composition event. If not provided,
* status callback events will not be dispatched..
*
* @param statusCallback The URL we should call to send status information to
* your application
* @return this
*/
public CompositionHookUpdater setStatusCallback(final String statusCallback) {
return setStatusCallback(Promoter.uriFromString(statusCallback));
}
/**
* The HTTP method we should use to call `status_callback`. Can be: `POST` or
* `GET` and the default is `POST`..
*
* @param statusCallbackMethod The HTTP method we should use to call
* status_callback
* @return this
*/
public CompositionHookUpdater setStatusCallbackMethod(final HttpMethod statusCallbackMethod) {
this.statusCallbackMethod = statusCallbackMethod;
return this;
}
/**
* Make the request to the Twilio API to perform the update.
*
* @param client TwilioRestClient with which to make the request
* @return Updated CompositionHook
*/
@Override
@SuppressWarnings("checkstyle:linelength")
public CompositionHook update(final TwilioRestClient client) {
Request request = new Request(
HttpMethod.POST,
Domains.VIDEO.toString(),
"/v1/CompositionHooks/" + this.pathSid + ""
);
addPostParams(request);
Response response = client.request(request);
if (response == null) {
throw new ApiConnectionException("CompositionHook update failed: Unable to connect to server");
} else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) {
RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper());
if (restException == null) {
throw new ApiException("Server Error, no content");
}
throw new ApiException(restException);
}
return CompositionHook.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 (friendlyName != null) {
request.addPostParam("FriendlyName", friendlyName);
}
if (enabled != null) {
request.addPostParam("Enabled", enabled.toString());
}
if (videoLayout != null) {
request.addPostParam("VideoLayout", Converter.mapToJson(videoLayout));
}
if (audioSources != null) {
for (String prop : audioSources) {
request.addPostParam("AudioSources", prop);
}
}
if (audioSourcesExcluded != null) {
for (String prop : audioSourcesExcluded) {
request.addPostParam("AudioSourcesExcluded", prop);
}
}
if (trim != null) {
request.addPostParam("Trim", trim.toString());
}
if (format != null) {
request.addPostParam("Format", format.toString());
}
if (resolution != null) {
request.addPostParam("Resolution", resolution);
}
if (statusCallback != null) {
request.addPostParam("StatusCallback", statusCallback.toString());
}
if (statusCallbackMethod != null) {
request.addPostParam("StatusCallbackMethod", statusCallbackMethod.toString());
}
}
}