001/* 002 * Copyright (c) 2011-2017 Nexmo Inc 003 * 004 * Permission is hereby granted, free of charge, to any person obtaining a copy 005 * of this software and associated documentation files (the "Software"), to deal 006 * in the Software without restriction, including without limitation the rights 007 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 008 * copies of the Software, and to permit persons to whom the Software is 009 * furnished to do so, subject to the following conditions: 010 * 011 * The above copyright notice and this permission notice shall be included in 012 * all copies or substantial portions of the Software. 013 * 014 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 015 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 016 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 017 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 018 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 019 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 020 * THE SOFTWARE. 021 */ 022package com.nexmo.client.voice.ncco; 023 024import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 025import com.fasterxml.jackson.annotation.JsonInclude; 026 027import java.util.Arrays; 028import java.util.Collection; 029 030/** 031 * An NCCO stream action which allows for media to be streamed to a call. 032 */ 033@JsonInclude(value = JsonInclude.Include.NON_NULL) 034@JsonIgnoreProperties(ignoreUnknown = true) 035public class StreamAction implements Action { 036 private static final String ACTION = "stream"; 037 038 private Collection<String> streamUrl; 039 private Float level; 040 private Boolean bargeIn; 041 private Integer loop; 042 043 private StreamAction(Builder builder) { 044 this.streamUrl = builder.streamUrl; 045 this.level = builder.level; 046 this.bargeIn = builder.bargeIn; 047 this.loop = builder.loop; 048 } 049 050 @Override 051 public String getAction() { 052 return ACTION; 053 } 054 055 public Collection<String> getStreamUrl() { 056 return streamUrl; 057 } 058 059 public Float getLevel() { 060 return level; 061 } 062 063 public Boolean getBargeIn() { 064 return bargeIn; 065 } 066 067 public Integer getLoop() { 068 return loop; 069 } 070 071 public static Builder builder(Collection<String> streamUrl) { 072 return new Builder(streamUrl); 073 } 074 075 public static Builder builder(String... streamUrl) { 076 return new Builder(streamUrl); 077 } 078 079 public static class Builder { 080 private Collection<String> streamUrl; 081 private Float level = null; 082 private Boolean bargeIn = null; 083 private Integer loop = null; 084 085 /** 086 * @param streamUrl An array containing a single URL to an mp3 or wav (16-bit) audio file to stream to the 087 * Call or Conversation. 088 */ 089 public Builder(Collection<String> streamUrl) { 090 this.streamUrl = streamUrl; 091 } 092 093 /** 094 * @param streamUrl An array containing a single URL to an mp3 or wav (16-bit) audio file to stream to the 095 * Call or Conversation. 096 */ 097 public Builder(String... streamUrl) { 098 this(Arrays.asList(streamUrl)); 099 } 100 101 /** 102 * @param streamUrl An array containing a single URL to an mp3 or wav (16-bit) audio file to stream to the 103 * Call or Conversation. 104 * 105 * @return The {@link Builder} to keep building. 106 */ 107 public Builder streamUrl(Collection<String> streamUrl) { 108 this.streamUrl = streamUrl; 109 return this; 110 } 111 112 /** 113 * @param streamUrl An array containing a single URL to an mp3 or wav (16-bit) audio file to stream to the 114 * Call or Conversation. 115 * 116 * @return The {@link Builder} to keep building. 117 */ 118 public Builder streamUrl(String... streamUrl) { 119 return streamUrl(Arrays.asList(streamUrl)); 120 } 121 122 /** 123 * @param level Set the audio level of the stream in the range between -1 and 1 inclusively with a precision 124 * of 0.1. The default value is 0. 125 * 126 * @return The {@link Builder} to keep building. 127 */ 128 public Builder level(Float level) { 129 this.level = level; 130 return this; 131 } 132 133 /** 134 * @param bargeIn Set to true so this action is terminated when the user presses a button on the keypad. 135 * Use this feature to enable users to choose an option without having to listen to the whole 136 * message in your Interactive Voice Response (IVR ). If you set bargeIn to true on one more 137 * Stream actions then the next action in the NCCO stack must be an input action. 138 * <p> 139 * The default value is false. 140 * 141 * @return The {@link Builder} to keep building. 142 */ 143 public Builder bargeIn(Boolean bargeIn) { 144 this.bargeIn = bargeIn; 145 return this; 146 } 147 148 /** 149 * @param loop The number of times audio is repeated before the Call is closed. 150 * The default value is 1. Set to 0 to loop infinitely. 151 * 152 * @return The {@link Builder} to keep building. 153 */ 154 public Builder loop(Integer loop) { 155 this.loop = loop; 156 return this; 157 } 158 159 /** 160 * @return A new {@link StreamAction} object from the stored builder options. 161 */ 162 public StreamAction build() { 163 return new StreamAction(this); 164 } 165 } 166}