Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added interruptAudioAndAnnounce api #43357

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
"AssetsRepo": "Azure/azure-sdk-assets",
"AssetsRepoPrefixPath": "java",
"TagPrefix": "java/communication/azure-communication-callautomation",
"Tag": "java/communication/azure-communication-callautomation_768622e9b4"
"Tag": "java/communication/azure-communication-callautomation_8eed475b32"
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,16 @@
import com.azure.communication.callautomation.models.events.DialogSensitivityUpdate;
import com.azure.communication.callautomation.models.events.DialogStarted;
import com.azure.communication.callautomation.models.events.DialogTransfer;
import com.azure.communication.callautomation.models.events.HoldAudioCompleted;
import com.azure.communication.callautomation.models.events.HoldAudioPaused;
import com.azure.communication.callautomation.models.events.HoldAudioResumed;
import com.azure.communication.callautomation.models.events.HoldAudioStarted;
import com.azure.communication.callautomation.models.events.HoldFailed;
import com.azure.communication.callautomation.models.events.ParticipantsUpdated;
import com.azure.communication.callautomation.models.events.PlayCanceled;
import com.azure.communication.callautomation.models.events.PlayCompleted;
import com.azure.communication.callautomation.models.events.PlayPaused;
import com.azure.communication.callautomation.models.events.PlayResumed;
import com.azure.communication.callautomation.models.events.PlayFailed;
import com.azure.communication.callautomation.models.events.PlayStarted;
import com.azure.communication.callautomation.models.events.RecognizeCanceled;
Expand Down Expand Up @@ -135,6 +141,10 @@ private static CallAutomationEventBase parseSingleCloudEvent(String data, String
ret = PlayStarted.fromJson(jsonReader);
} else if (Objects.equals(eventType, "Microsoft.Communication.PlayCanceled")) {
ret = PlayCanceled.fromJson(jsonReader);
} else if (Objects.equals(eventType, "Microsoft.Communication.PlayPaused")) {
ret = PlayPaused.fromJson(jsonReader);
} else if (Objects.equals(eventType, "Microsoft.Communication.PlayResumed")) {
ret = PlayResumed.fromJson(jsonReader);
} else if (Objects.equals(eventType, "Microsoft.Communication.RecognizeCompleted")) {
ret = RecognizeCompleted.fromJson(jsonReader);
} else if (Objects.equals(eventType, "Microsoft.Communication.RecognizeFailed")) {
Expand Down Expand Up @@ -189,6 +199,14 @@ private static CallAutomationEventBase parseSingleCloudEvent(String data, String
ret = AnswerFailed.fromJson(jsonReader);
} else if (Objects.equals(eventType, "Microsoft.Communication.CreateCallFailed")) {
ret = CreateCallFailed.fromJson(jsonReader);
} else if (Objects.equals(eventType, "Microsoft.Communication.HoldAudioCompleted")) {
ret = HoldAudioCompleted.fromJson(jsonReader);
} else if (Objects.equals(eventType, "Microsoft.Communication.HoldAudioStarted")) {
ret = HoldAudioStarted.fromJson(jsonReader);
} else if (Objects.equals(eventType, "Microsoft.Communication.HoldAudioPaused")) {
ret = HoldAudioPaused.fromJson(jsonReader);
} else if (Objects.equals(eventType, "Microsoft.Communication.HoldAudioResumed")) {
ret = HoldAudioResumed.fromJson(jsonReader);
} else if (Objects.equals(eventType, "Microsoft.Communication.HoldFailed")) {
ret = HoldFailed.fromJson(jsonReader);
} else if (Objects.equals(eventType, "Microsoft.Communication.ConnectFailed")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.azure.communication.callautomation.models.ContinuousDtmfRecognitionOptions;
import com.azure.communication.callautomation.models.DtmfTone;
import com.azure.communication.callautomation.models.HoldOptions;
import com.azure.communication.callautomation.models.InterruptAudioAndAnnounceOptions;
import com.azure.communication.callautomation.models.UnholdOptions;
import com.azure.communication.callautomation.models.PlayOptions;
import com.azure.communication.callautomation.models.PlayToAllOptions;
Expand Down Expand Up @@ -386,4 +387,26 @@ public void stopMediaStreaming() {
public Response<Void> stopMediaStreamingWithResponse(StopMediaStreamingOptions options, Context context) {
return callMediaAsync.stopMediaStreamingWithResponseInternal(options, context).block();
}

/**
* Interrupt audio and play announment to the participant in call.
* @param playSource A {@link PlaySource} representing the source to play.
* @param playTo the target.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public void interruptAudioAndAnnounce(PlaySource playSource, CommunicationIdentifier playTo) {
callMediaAsync.interruptAudioAndAnnounce(playSource, playTo).block();
}

/**
* Interrupt audio and play announment to the participant in call.
* @param options - Different options to pass to the request.
* @param context Context
* @return Response for successful operation.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Response<Void> interruptAudioAndAnnounceWithResponse(InterruptAudioAndAnnounceOptions options,
Context context) {
return callMediaAsync.interruptAudioAndAnnounceWithResponseInternal(options, context).block();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.azure.communication.callautomation.implementation.models.DtmfToneInternal;
import com.azure.communication.callautomation.implementation.models.FileSourceInternal;
import com.azure.communication.callautomation.implementation.models.HoldRequest;
import com.azure.communication.callautomation.implementation.models.InterruptAudioAndAnnounceRequest;
import com.azure.communication.callautomation.implementation.models.PlayOptionsInternal;
import com.azure.communication.callautomation.implementation.models.PlayRequest;
import com.azure.communication.callautomation.implementation.models.PlaySourceInternal;
Expand Down Expand Up @@ -39,6 +40,7 @@
import com.azure.communication.callautomation.models.DtmfTone;
import com.azure.communication.callautomation.models.FileSource;
import com.azure.communication.callautomation.models.HoldOptions;
import com.azure.communication.callautomation.models.InterruptAudioAndAnnounceOptions;
import com.azure.communication.callautomation.models.PlayOptions;
import com.azure.communication.callautomation.models.PlaySource;
import com.azure.communication.callautomation.models.PlayToAllOptions;
Expand Down Expand Up @@ -1009,4 +1011,50 @@ Mono<Response<Void>> stopMediaStreamingWithResponseInternal(StopMediaStreamingOp
return monoError(logger, ex);
}
}

/**
* Interrupt audio and play announment to the participant in call.
* @param playTo the target.
* @param playSource the play source.
* @return Response for successful operation.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Mono<Void> interruptAudioAndAnnounce(PlaySource playSource, CommunicationIdentifier playTo) {
return interruptAudioAndAnnounceWithResponse(new InterruptAudioAndAnnounceOptions(playSource, playTo))
.flatMap(FluxUtil::toMono);
}

/**
* Interrupt audio and play announment to the participant in call.
* @param options - Different options to pass to the request.
* @return Response for successful operation.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Mono<Response<Void>> interruptAudioAndAnnounceWithResponse(InterruptAudioAndAnnounceOptions options) {
return withContext(context -> interruptAudioAndAnnounceWithResponseInternal(options, context));
}

Mono<Response<Void>> interruptAudioAndAnnounceWithResponseInternal(InterruptAudioAndAnnounceOptions options,
Context context) {
try {
context = context == null ? Context.NONE : context;
List<PlaySourceInternal> playSourcesInternal = new ArrayList<>();
InterruptAudioAndAnnounceRequest request = new InterruptAudioAndAnnounceRequest()
.setPlayTo(CommunicationIdentifierConverter.convert(options.getPlayTo()))
.setOperationContext(options.getOperationContext());

if (options.getPlaySources() != null) {
for (PlaySource playSource : options.getPlaySources()) {
if (playSource != null) {
playSourcesInternal.add(convertPlaySourceToPlaySourceInternal(playSource));
}
}
}
request.setPlaySources(playSourcesInternal);

return contentsInternal.interruptAudioAndAnnounceWithResponseAsync(callConnectionId, request, context);
} catch (RuntimeException ex) {
return monoError(logger, ex);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

package com.azure.communication.callautomation.models;

import com.azure.communication.common.CommunicationIdentifier;
import com.azure.core.annotation.Fluent;

import java.util.ArrayList;
import java.util.List;

/** The InterruptAudioAndAnnounceOptions model. */
@Fluent
public final class InterruptAudioAndAnnounceOptions {
/*
* A List of {@link PlaySource} representing the sources to play.
* Currently only single play source per request is supported.
*/
private final List<PlaySource> playSources;

/*
* The targets to play to
*/
private final CommunicationIdentifier playTo;

/*
* The operation context
*/
private String operationContext;

/**
* Constructor
* @param playSources A List of {@link PlaySource} representing the sources to play.
* @param playTo The target to play to.
*/
public InterruptAudioAndAnnounceOptions(List<PlaySource> playSources, CommunicationIdentifier playTo) {
this.playSources = playSources;
this.playTo = playTo;
}

/**
* Constructor
* @param playSource A {@link PlaySource} representing the source to play.
* @param playTo The target to play to.
*/
public InterruptAudioAndAnnounceOptions(PlaySource playSource, CommunicationIdentifier playTo) {
this.playSources = new ArrayList<>();
this.playSources.add(playSource);
this.playTo = playTo;
}

/**
* Get the play sources.
*
* @return the playSources value.
*/
public List<PlaySource> getPlaySources() {
return this.playSources;
}

/**
* Get the target to play to.
*
* @return the playTo value.
*/
public CommunicationIdentifier getPlayTo() {
return this.playTo;
}

/**
* Get the operationContext property.
*
* @return the operationContext value.
*/
public String getOperationContext() {
return this.operationContext;
}

/**
* Set the operationContext property.
*
* @param operationContext the operationContext value to set.
* @return the InterruptAudioAndAnnounceOptions object itself.
*/
public InterruptAudioAndAnnounceOptions setOperationContext(String operationContext) {
this.operationContext = operationContext;
return this;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

package com.azure.communication.callautomation.models.events;

import java.io.IOException;

import com.azure.core.annotation.Immutable;
import com.azure.json.JsonReader;
import com.azure.json.JsonToken;
import com.azure.json.JsonWriter;

/** The HoldAudioCompleted model. */
@Immutable
public final class HoldAudioCompleted extends CallAutomationEventBase {

private HoldAudioCompleted() {
}

/**
* {@inheritDoc}
*/
@Override
public JsonWriter toJson(JsonWriter jsonWriter) throws IOException {
jsonWriter.writeStartObject();
super.writeFields(jsonWriter);
return jsonWriter.writeEndObject();
}

/**
* Reads an instance of HoldAudioCompleted from the JsonReader.
*
* @param jsonReader The JsonReader being read.
* @return An instance of HoldAudioCompleted if the JsonReader was pointing to an instance of it, or null
* if it was pointing to JSON null.
* @throws IOException If an error occurs while reading the HoldAudioCompleted.
*/
public static HoldAudioCompleted fromJson(JsonReader jsonReader) throws IOException {
return jsonReader.readObject(reader -> {
final HoldAudioCompleted event = new HoldAudioCompleted();
while (jsonReader.nextToken() != JsonToken.END_OBJECT) {
String fieldName = reader.getFieldName();
reader.nextToken();
if (!event.readField(fieldName, reader)) {
reader.skipChildren();
}
}
return event;
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

package com.azure.communication.callautomation.models.events;

import java.io.IOException;

import com.azure.core.annotation.Immutable;
import com.azure.json.JsonReader;
import com.azure.json.JsonToken;
import com.azure.json.JsonWriter;

/** The HoldAudioPaused model. */
@Immutable
public final class HoldAudioPaused extends CallAutomationEventBase {

private HoldAudioPaused() {
}

/**
* {@inheritDoc}
*/
@Override
public JsonWriter toJson(JsonWriter jsonWriter) throws IOException {
jsonWriter.writeStartObject();
super.writeFields(jsonWriter);
return jsonWriter.writeEndObject();
}

/**
* Reads an instance of HoldAudioPaused from the JsonReader.
*
* @param jsonReader The JsonReader being read.
* @return An instance of HoldAudioPaused if the JsonReader was pointing to an instance of it, or null
* if it was pointing to JSON null.
* @throws IOException If an error occurs while reading the HoldAudioPaused.
*/
public static HoldAudioPaused fromJson(JsonReader jsonReader) throws IOException {
return jsonReader.readObject(reader -> {
final HoldAudioPaused event = new HoldAudioPaused();
while (jsonReader.nextToken() != JsonToken.END_OBJECT) {
String fieldName = reader.getFieldName();
reader.nextToken();
if (!event.readField(fieldName, reader)) {
reader.skipChildren();
}
}
return event;
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

package com.azure.communication.callautomation.models.events;

import java.io.IOException;

import com.azure.core.annotation.Immutable;
import com.azure.json.JsonReader;
import com.azure.json.JsonToken;
import com.azure.json.JsonWriter;

/** The HoldAudioResumed model. */
@Immutable
public final class HoldAudioResumed extends CallAutomationEventBase {

private HoldAudioResumed() {
}

/**
* {@inheritDoc}
*/
@Override
public JsonWriter toJson(JsonWriter jsonWriter) throws IOException {
jsonWriter.writeStartObject();
super.writeFields(jsonWriter);
return jsonWriter.writeEndObject();
}

/**
* Reads an instance of HoldAudioResumed from the JsonReader.
*
* @param jsonReader The JsonReader being read.
* @return An instance of HoldAudioResumed if the JsonReader was pointing to an instance of it, or null
* if it was pointing to JSON null.
* @throws IOException If an error occurs while reading the HoldAudioResumed.
*/
public static HoldAudioResumed fromJson(JsonReader jsonReader) throws IOException {
return jsonReader.readObject(reader -> {
final HoldAudioResumed event = new HoldAudioResumed();
while (jsonReader.nextToken() != JsonToken.END_OBJECT) {
String fieldName = reader.getFieldName();
reader.nextToken();
if (!event.readField(fieldName, reader)) {
reader.skipChildren();
}
}
return event;
});
}
}
Loading
Loading