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.voice.ncco; 017 018import com.fasterxml.jackson.annotation.JsonProperty; 019import com.vonage.client.JsonableBaseObject; 020import java.util.Arrays; 021import java.util.Collection; 022 023/** 024 * An NCCO stream action which allows for media to be streamed to a call. 025 */ 026public class StreamAction extends JsonableBaseObject implements Action { 027 private static final String ACTION = "stream"; 028 029 private Collection<String> streamUrl; 030 private Float level; 031 private Boolean bargeIn; 032 private Integer loop; 033 034 StreamAction() {} 035 036 private StreamAction(Builder builder) { 037 streamUrl = builder.streamUrl; 038 level = builder.level; 039 bargeIn = builder.bargeIn; 040 loop = builder.loop; 041 } 042 043 @Override 044 public String getAction() { 045 return ACTION; 046 } 047 048 @JsonProperty("streamUrl") 049 public Collection<String> getStreamUrl() { 050 return streamUrl; 051 } 052 053 @JsonProperty("level") 054 public Float getLevel() { 055 return level; 056 } 057 058 @JsonProperty("bargeIn") 059 public Boolean getBargeIn() { 060 return bargeIn; 061 } 062 063 @JsonProperty("loop") 064 public Integer getLoop() { 065 return loop; 066 } 067 068 /** 069 * @param streamUrl An array containing a single URL to an mp3 or wav (16-bit) audio file to stream to the 070 * Call or Conversation. 071 * @return A {@link Builder}. 072 */ 073 public static Builder builder(Collection<String> streamUrl) { 074 return new Builder(streamUrl); 075 } 076 077 /** 078 * @param streamUrl An array containing a single URL to an mp3 or wav (16-bit) audio file to stream to the 079 * Call or Conversation. 080 * @return A {@link Builder}. 081 */ 082 public static Builder builder(String... streamUrl) { 083 return builder(Arrays.asList(streamUrl)); 084 } 085 086 public static class Builder { 087 private Collection<String> streamUrl; 088 private Float level; 089 private Boolean bargeIn; 090 private Integer loop; 091 092 Builder(Collection<String> streamUrl) { 093 this.streamUrl = streamUrl; 094 } 095 096 /** 097 * @param streamUrl An array containing a single URL to an mp3 or wav (16-bit) audio file to stream to the 098 * Call or Conversation. 099 * 100 * @return This builder. 101 */ 102 public Builder streamUrl(Collection<String> streamUrl) { 103 this.streamUrl = streamUrl; 104 return this; 105 } 106 107 /** 108 * @param streamUrl An array containing a single URL to an mp3 or wav (16-bit) audio file to stream to the 109 * Call or Conversation. 110 * 111 * @return This builder. 112 */ 113 public Builder streamUrl(String... streamUrl) { 114 return streamUrl(Arrays.asList(streamUrl)); 115 } 116 117 /** 118 * @param level Set the audio level of the stream in the range between -1 and 1 inclusively with a precision 119 * of 0.1. The default value is 0. 120 * 121 * @return This builder. 122 */ 123 public Builder level(Float level) { 124 this.level = level; 125 return this; 126 } 127 128 /** 129 * @param bargeIn Set to true so this action is terminated when the user presses a button on the keypad. 130 * Use this feature to enable users to choose an option without having to listen to the whole 131 * message in your Interactive Voice Response (IVR ). If you set bargeIn to true on one more 132 * Stream actions then the next action in the NCCO stack must be an input action. 133 * <p> 134 * The default value is false. 135 * 136 * @return This builder. 137 */ 138 public Builder bargeIn(Boolean bargeIn) { 139 this.bargeIn = bargeIn; 140 return this; 141 } 142 143 /** 144 * @param loop The number of times audio is repeated before the Call is closed. 145 * The default value is 1. Set to 0 to loop infinitely. 146 * 147 * @return This builder. 148 */ 149 public Builder loop(Integer loop) { 150 this.loop = loop; 151 return this; 152 } 153 154 /** 155 * @return A new {@link StreamAction} object from the stored builder options. 156 */ 157 public StreamAction build() { 158 return new StreamAction(this); 159 } 160 } 161}