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