001/* 002 * Copyright 2024 Vonage 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package com.vonage.client.video; 017 018import com.fasterxml.jackson.annotation.JsonProperty; 019import com.vonage.client.JsonableBaseObject; 020import java.net.URI; 021import java.util.Objects; 022 023/** 024 * Defines the parameters for starting an Experience Composer session. 025 * 026 * @since 8.6.0 027 */ 028public final class RenderRequest extends AbstractSessionTokenRequest { 029 private URI url; 030 private Integer maxDuration; 031 private Resolution resolution; 032 private Properties properties; 033 034 private RenderRequest() {} 035 036 private RenderRequest(Builder builder) { 037 super(builder); 038 int urlLength = Objects.requireNonNull(builder.url, "URL is required.").length(); 039 if (urlLength < 15 || urlLength > 2048) { 040 throw new IllegalArgumentException("URL must be between 15 and 2048 characters long."); 041 } 042 url = URI.create(builder.url); 043 properties = new Properties(builder.name); 044 if ((maxDuration = builder.maxDuration) != null && (maxDuration < 60 || maxDuration > 36000)) { 045 throw new IllegalArgumentException("Max duration must be between 60 and 36000 seconds."); 046 } 047 resolution = builder.resolution; 048 } 049 050 /** 051 * Publisher initial configuration properties for the composed output stream. 052 */ 053 public static final class Properties extends JsonableBaseObject { 054 private String name; 055 056 private Properties() {} 057 058 private Properties(String name) { 059 if ((this.name = name) == null || name.trim().isEmpty()) { 060 throw new IllegalArgumentException("Name is required."); 061 } 062 if (name.length() > 200) { 063 throw new IllegalArgumentException("Name cannot exceed 200 characters."); 064 } 065 } 066 067 /** 068 * Name of the composed output stream which is published to the session. 069 * 070 * @return The stream name. 071 */ 072 @JsonProperty("name") 073 public String getName() { 074 return name; 075 } 076 } 077 078 /** 079 * A publicly reachable URL controlled by the customer and capable of generating the content 080 * to be rendered without user intervention. 081 * 082 * @return The URL, or {@code null} if unspecified. 083 */ 084 @JsonProperty("url") 085 public URI getUrl() { 086 return url; 087 } 088 089 /** 090 * Maximum time allowed for the Experience Composer, in seconds. After this time, it is stopped automatically, 091 * if it is still running. The maximum value is 36000 (10 hours), the minimum value is 60 (1 minute), and the 092 * default value is 7200 (2 hours). When the Experience Composer ends, its stream is unpublished and an event 093 * is posted to the callback URL, if configured in the Application Config. 094 * 095 * @return The maximum duration in seconds as an Integer, or {@code null} if unspecified. 096 */ 097 @JsonProperty("maxDuration") 098 public Integer getMaxDuration() { 099 return maxDuration; 100 } 101 102 /** 103 * Render resolution of the Experience Composer. 104 * 105 * @return The render resolution as an enum, or {@code null} if unspecified. 106 */ 107 @JsonProperty("resolution") 108 public Resolution getResolution() { 109 return resolution; 110 } 111 112 /** 113 * The initial configuration of Publisher properties for the composed output stream. 114 * 115 * @return The publisher properties object. 116 */ 117 @JsonProperty("properties") 118 public Properties getProperties() { 119 return properties; 120 } 121 122 /** 123 * Entry point for constructing an instance of this class. 124 * 125 * @return A new Builder instance. 126 */ 127 public static Builder builder() { 128 return new Builder(); 129 } 130 131 /** 132 * Builder for defining the parameters of {@link RenderRequest}. 133 */ 134 public static class Builder extends AbstractSessionTokenRequest.Builder<RenderRequest, Builder> { 135 private String name, url; 136 private Integer maxDuration; 137 private Resolution resolution; 138 139 /** 140 * (REQUIRED) 141 * Name of the composed output stream which is published to the session. 142 * 143 * @param name The stream name. 144 * @return This builder. 145 */ 146 public Builder name(String name) { 147 this.name = name; 148 return this; 149 } 150 151 /** 152 * (REQUIRED) 153 * URL of the customer service where the callbacks will be received. 154 * This must be between 15 and 2048 characters in length. 155 * 156 * @param url The URL as a string. 157 * @return This builder. 158 */ 159 public Builder url(String url) { 160 this.url = url; 161 return this; 162 } 163 164 /** 165 * (OPTIONAL) 166 * Maximum time allowed for the Experience Composer, in seconds. After this time, it is 167 * stopped automatically, if it is still running. The maximum value is 36000 (10 hours), 168 * the minimum value is 60 (1 minute), and the default value is 7200 (2 hours). When the 169 * Experience Composer ends, its stream is unpublished and an event is posted to the 170 * callback URL, if configured in the Application Config. 171 * 172 * @param maxDuration The maximum duration in seconds as an int. 173 * @return This builder. 174 */ 175 public Builder maxDuration(int maxDuration) { 176 this.maxDuration = maxDuration; 177 return this; 178 } 179 180 /** 181 * (OPTIONAL) 182 * Resolution of the display area for the composition. 1280x720 is the default. 183 * 184 * @param resolution The resolution as an enum. 185 * @return This builder. 186 */ 187 public Builder resolution(Resolution resolution) { 188 this.resolution = resolution; 189 return this; 190 } 191 192 /** 193 * Builds the RenderRequest with this builder's properties. 194 * 195 * @return A new RenderRequest instance. 196 */ 197 public RenderRequest build() { 198 return new RenderRequest(this); 199 } 200 } 201}