From 81a54de73fe5cf58f87a1e4a42a1770cf7d6785e Mon Sep 17 00:00:00 2001 From: Paresh Arvind Patil Date: Wed, 26 May 2021 16:40:27 -0700 Subject: [PATCH 1/5] Added playAudio and cancelMedia api for out-call --- .../src/ConversationClient.cs | 100 +++++++ .../src/Generated/ConversationRestClient.cs | 168 +++++++++++ ...ncelMediaOperationRequest.Serialization.cs | 28 ++ .../Models/CancelMediaOperationRequest.cs | 33 +++ .../Models/PlayAudioRequest.Serialization.cs | 5 + .../src/Generated/Models/PlayAudioRequest.cs | 2 + .../src/swagger/Sample-Swagger.json | 153 ++++++++++ .../ConversationClientsTests.cs | 262 ++++++++++++++++++ 8 files changed, 751 insertions(+) create mode 100644 sdk/communication/Azure.Communication.Calling.Server/src/Generated/Models/CancelMediaOperationRequest.Serialization.cs create mode 100644 sdk/communication/Azure.Communication.Calling.Server/src/Generated/Models/CancelMediaOperationRequest.cs create mode 100644 sdk/communication/Azure.Communication.Calling.Server/tests/ConversationClients/ConversationClientsTests.cs diff --git a/sdk/communication/Azure.Communication.Calling.Server/src/ConversationClient.cs b/sdk/communication/Azure.Communication.Calling.Server/src/ConversationClient.cs index d9736c2d20cca..ab736cd75ba3d 100644 --- a/sdk/communication/Azure.Communication.Calling.Server/src/ConversationClient.cs +++ b/sdk/communication/Azure.Communication.Calling.Server/src/ConversationClient.cs @@ -410,6 +410,106 @@ public virtual Response GetRecordingState(string } } + /// + /// PlayAudio + /// + /// The conversation id. + /// Play audio request. + /// The cancellation token. + /// + public virtual async Task> PlayAudioAsync(string conversationId, PlayAudioRequest request, CancellationToken cancellationToken = default) + { + using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(ConversationClient)}.{nameof(PlayAudioAsync)}"); + scope.Start(); + try + { + Argument.AssertNotNullOrEmpty(conversationId, nameof(conversationId)); + Argument.AssertNotNull(request, nameof(request)); + + return await RestClient.PlayAudioAsync(conversationId, request, cancellationToken).ConfigureAwait(false); + } + catch (Exception ex) + { + scope.Failed(ex); + throw; + } + } + + /// + /// PlayAudio + /// + /// The conversation id. + /// Play audio request. + /// The cancellation token. + /// + public virtual Response PlayAudio(string conversationId, PlayAudioRequest request, CancellationToken cancellationToken = default) + { + using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(ConversationClient)}.{nameof(PlayAudio)}"); + scope.Start(); + try + { + Argument.AssertNotNullOrEmpty(conversationId, nameof(conversationId)); + Argument.AssertNotNull(request, nameof(request)); + + return RestClient.PlayAudio(conversationId, request, cancellationToken); + } + catch (Exception ex) + { + scope.Failed(ex); + throw; + } + } + + /// + /// Cancel Media Processing. + /// + /// The conversation id. + /// Cancel media request. + /// The cancellation token. + /// + public virtual async Task> CancelMediaOperationAsync(string conversationId, CancelMediaOperationRequest request, CancellationToken cancellationToken = default) + { + using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(ConversationClient)}.{nameof(CancelMediaOperationAsync)}"); + scope.Start(); + try + { + Argument.AssertNotNullOrEmpty(conversationId, nameof(conversationId)); + Argument.AssertNotNull(request, nameof(request)); + + return await RestClient.CancelMediaOperationAsync(conversationId, request, cancellationToken).ConfigureAwait(false); + } + catch (Exception ex) + { + scope.Failed(ex); + throw; + } + } + + /// + /// Cancel Media Processing. + /// + /// The conversation id. + /// Cancel media request. + /// The cancellation token. + /// + public virtual Response CancelMediaOperation(string conversationId, CancelMediaOperationRequest request, CancellationToken cancellationToken = default) + { + using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(ConversationClient)}.{nameof(CancelMediaOperation)}"); + scope.Start(); + try + { + Argument.AssertNotNullOrEmpty(conversationId, nameof(conversationId)); + Argument.AssertNotNull(request, nameof(request)); + + return RestClient.CancelMediaOperation(conversationId, request, cancellationToken); + } + catch (Exception ex) + { + scope.Failed(ex); + throw; + } + } + /// /// Add participant /// diff --git a/sdk/communication/Azure.Communication.Calling.Server/src/Generated/ConversationRestClient.cs b/sdk/communication/Azure.Communication.Calling.Server/src/Generated/ConversationRestClient.cs index 62732abd6037f..a0affa23c5ad8 100644 --- a/sdk/communication/Azure.Communication.Calling.Server/src/Generated/ConversationRestClient.cs +++ b/sdk/communication/Azure.Communication.Calling.Server/src/Generated/ConversationRestClient.cs @@ -129,6 +129,174 @@ public Response JoinCall(string conversationId, JoinCallReques } } + internal HttpMessage CreatePlayAudioRequest(string conversationId, PlayAudioRequest request) + { + var message = _pipeline.CreateMessage(); + var request0 = message.Request; + request0.Method = RequestMethod.Post; + var uri = new RawRequestUriBuilder(); + uri.AppendRaw(endpoint, false); + uri.AppendPath("/calling/conversations/", false); + uri.AppendPath(conversationId, true); + uri.AppendPath("/PlayAudio", false); + uri.AppendQuery("api-version", apiVersion, true); + request0.Uri = uri; + request0.Headers.Add("Accept", "application/json"); + request0.Headers.Add("Content-Type", "application/json"); + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(request); + request0.Content = content; + return message; + } + + /// Play audio in a call. + /// The conversation id which can be guid or encoded cs url. + /// Play audio request. + /// The cancellation token to use. + /// or is null. + public async Task> PlayAudioAsync(string conversationId, PlayAudioRequest request, CancellationToken cancellationToken = default) + { + if (conversationId == null) + { + throw new ArgumentNullException(nameof(conversationId)); + } + if (request == null) + { + throw new ArgumentNullException(nameof(request)); + } + + using var message = CreatePlayAudioRequest(conversationId, request); + await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); + switch (message.Response.Status) + { + case 202: + { + PlayAudioResponse value = default; + using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, cancellationToken).ConfigureAwait(false); + value = PlayAudioResponse.DeserializePlayAudioResponse(document.RootElement); + return Response.FromValue(value, message.Response); + } + default: + throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false); + } + } + + /// Play audio in a call. + /// The conversation id which can be guid or encoded cs url. + /// Play audio request. + /// The cancellation token to use. + /// or is null. + public Response PlayAudio(string conversationId, PlayAudioRequest request, CancellationToken cancellationToken = default) + { + if (conversationId == null) + { + throw new ArgumentNullException(nameof(conversationId)); + } + if (request == null) + { + throw new ArgumentNullException(nameof(request)); + } + + using var message = CreatePlayAudioRequest(conversationId, request); + _pipeline.Send(message, cancellationToken); + switch (message.Response.Status) + { + case 202: + { + PlayAudioResponse value = default; + using var document = JsonDocument.Parse(message.Response.ContentStream); + value = PlayAudioResponse.DeserializePlayAudioResponse(document.RootElement); + return Response.FromValue(value, message.Response); + } + default: + throw _clientDiagnostics.CreateRequestFailedException(message.Response); + } + } + + internal HttpMessage CreateCancelMediaOperationRequest(string conversationId, CancelMediaOperationRequest request) + { + var message = _pipeline.CreateMessage(); + var request0 = message.Request; + request0.Method = RequestMethod.Post; + var uri = new RawRequestUriBuilder(); + uri.AppendRaw(endpoint, false); + uri.AppendPath("/calling/conversations/", false); + uri.AppendPath(conversationId, true); + uri.AppendPath("/CancelMediaOperation", false); + uri.AppendQuery("api-version", apiVersion, true); + request0.Uri = uri; + request0.Headers.Add("Accept", "application/json"); + request0.Headers.Add("Content-Type", "application/json"); + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(request); + request0.Content = content; + return message; + } + + /// Cancel Media Processing. + /// The conversation id which can be guid or encoded cs url. + /// The cancel media processing request. + /// The cancellation token to use. + /// or is null. + public async Task> CancelMediaOperationAsync(string conversationId, CancelMediaOperationRequest request, CancellationToken cancellationToken = default) + { + if (conversationId == null) + { + throw new ArgumentNullException(nameof(conversationId)); + } + if (request == null) + { + throw new ArgumentNullException(nameof(request)); + } + + using var message = CreateCancelMediaOperationRequest(conversationId, request); + await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); + switch (message.Response.Status) + { + case 200: + { + CancelMediaProcessingResponse value = default; + using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, cancellationToken).ConfigureAwait(false); + value = CancelMediaProcessingResponse.DeserializeCancelMediaProcessingResponse(document.RootElement); + return Response.FromValue(value, message.Response); + } + default: + throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false); + } + } + + /// Cancel Media Processing. + /// The conversation id which can be guid or encoded cs url. + /// The cancel media processing request. + /// The cancellation token to use. + /// or is null. + public Response CancelMediaOperation(string conversationId, CancelMediaOperationRequest request, CancellationToken cancellationToken = default) + { + if (conversationId == null) + { + throw new ArgumentNullException(nameof(conversationId)); + } + if (request == null) + { + throw new ArgumentNullException(nameof(request)); + } + + using var message = CreateCancelMediaOperationRequest(conversationId, request); + _pipeline.Send(message, cancellationToken); + switch (message.Response.Status) + { + case 200: + { + CancelMediaProcessingResponse value = default; + using var document = JsonDocument.Parse(message.Response.ContentStream); + value = CancelMediaProcessingResponse.DeserializeCancelMediaProcessingResponse(document.RootElement); + return Response.FromValue(value, message.Response); + } + default: + throw _clientDiagnostics.CreateRequestFailedException(message.Response); + } + } + internal HttpMessage CreateInviteParticipantsRequest(string conversationId, InviteParticipantsRequestInternal inviteParticipantsRequest) { var message = _pipeline.CreateMessage(); diff --git a/sdk/communication/Azure.Communication.Calling.Server/src/Generated/Models/CancelMediaOperationRequest.Serialization.cs b/sdk/communication/Azure.Communication.Calling.Server/src/Generated/Models/CancelMediaOperationRequest.Serialization.cs new file mode 100644 index 0000000000000..5cf88eef6a9ce --- /dev/null +++ b/sdk/communication/Azure.Communication.Calling.Server/src/Generated/Models/CancelMediaOperationRequest.Serialization.cs @@ -0,0 +1,28 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System.Text.Json; +using Azure.Core; + +namespace Azure.Communication.Calling.Server +{ + public partial class CancelMediaOperationRequest : IUtf8JsonSerializable + { + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) + { + writer.WriteStartObject(); + if (Optional.IsDefined(OperationContext)) + { + writer.WritePropertyName("operationContext"); + writer.WriteStringValue(OperationContext); + } + writer.WritePropertyName("operationId"); + writer.WriteStringValue(OperationId); + writer.WriteEndObject(); + } + } +} diff --git a/sdk/communication/Azure.Communication.Calling.Server/src/Generated/Models/CancelMediaOperationRequest.cs b/sdk/communication/Azure.Communication.Calling.Server/src/Generated/Models/CancelMediaOperationRequest.cs new file mode 100644 index 0000000000000..34b3586c59d73 --- /dev/null +++ b/sdk/communication/Azure.Communication.Calling.Server/src/Generated/Models/CancelMediaOperationRequest.cs @@ -0,0 +1,33 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; + +namespace Azure.Communication.Calling.Server +{ + /// The request payload for out call cancel media operation. + public partial class CancelMediaOperationRequest + { + /// Initializes a new instance of CancelMediaOperationRequest. + /// The operation Id of out-call. + /// is null. + public CancelMediaOperationRequest(string operationId) + { + if (operationId == null) + { + throw new ArgumentNullException(nameof(operationId)); + } + + OperationId = operationId; + } + + /// The context for this operation. + public string OperationContext { get; set; } + /// The operation Id of out-call. + public string OperationId { get; } + } +} diff --git a/sdk/communication/Azure.Communication.Calling.Server/src/Generated/Models/PlayAudioRequest.Serialization.cs b/sdk/communication/Azure.Communication.Calling.Server/src/Generated/Models/PlayAudioRequest.Serialization.cs index a3aea81532143..bbb2f26b9d1f9 100644 --- a/sdk/communication/Azure.Communication.Calling.Server/src/Generated/Models/PlayAudioRequest.Serialization.cs +++ b/sdk/communication/Azure.Communication.Calling.Server/src/Generated/Models/PlayAudioRequest.Serialization.cs @@ -35,6 +35,11 @@ void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) writer.WritePropertyName("audioFileId"); writer.WriteStringValue(AudioFileId); } + if (Optional.IsDefined(CallbackUri)) + { + writer.WritePropertyName("callbackUri"); + writer.WriteStringValue(CallbackUri); + } writer.WriteEndObject(); } } diff --git a/sdk/communication/Azure.Communication.Calling.Server/src/Generated/Models/PlayAudioRequest.cs b/sdk/communication/Azure.Communication.Calling.Server/src/Generated/Models/PlayAudioRequest.cs index 02b56fad69d3e..b06d0b2e311eb 100644 --- a/sdk/communication/Azure.Communication.Calling.Server/src/Generated/Models/PlayAudioRequest.cs +++ b/sdk/communication/Azure.Communication.Calling.Server/src/Generated/Models/PlayAudioRequest.cs @@ -31,5 +31,7 @@ public PlayAudioRequest() public string OperationContext { get; set; } /// An id for the media in the AudioFileUri, using which we cache the media resource. public string AudioFileId { get; set; } + /// The callback URI. + public string CallbackUri { get; set; } } } diff --git a/sdk/communication/Azure.Communication.Calling.Server/src/swagger/Sample-Swagger.json b/sdk/communication/Azure.Communication.Calling.Server/src/swagger/Sample-Swagger.json index 40f7a8e4a565f..3757ebef522e2 100644 --- a/sdk/communication/Azure.Communication.Calling.Server/src/swagger/Sample-Swagger.json +++ b/sdk/communication/Azure.Communication.Calling.Server/src/swagger/Sample-Swagger.json @@ -379,6 +379,138 @@ } } }, + "/calling/conversations/{conversationId}/PlayAudio": { + "post": { + "tags": [ + "Call" + ], + "summary": "Play audio in a call.", + "description": "Play audio in a call.", + "operationId": "Conversation_PlayAudio", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "parameters": [ + { + "name": "conversationId", + "in": "path", + "description": "The conversation id which can be guid or encoded cs url", + "required": true, + "type": "string" + }, + { + "name": "request", + "in": "body", + "description": "Play audio request.", + "required": true, + "schema": { + "$ref": "#/definitions/PlayAudioRequest" + } + }, + { + "$ref": "#/parameters/ApiVersionParameter" + } + ], + "responses": { + "202": { + "description": "Returns the play audio response.", + "schema": { + "$ref": "#/definitions/PlayAudioResponse" + } + }, + "401": { + "description": "Unauthorized", + "schema": { + "$ref": "#/definitions/CommunicationError" + }, + "x-ms-error-response": true + }, + "400": { + "description": "Bad request", + "schema": { + "$ref": "#/definitions/CommunicationError" + }, + "x-ms-error-response": true + }, + "500": { + "description": "Internal server error.", + "schema": { + "$ref": "#/definitions/CommunicationError" + }, + "x-ms-error-response": true + } + } + } + }, + "/calling/conversations/{conversationId}/CancelMediaOperation": { + "post": { + "tags": [ + "Call" + ], + "summary": "Cancel Media Processing.", + "description": "Cancel Media Processing.", + "operationId": "Conversation_CancelMediaOperation", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "parameters": [ + { + "name": "conversationId", + "in": "path", + "description": "The conversation id which can be guid or encoded cs url", + "required": true, + "type": "string" + }, + { + "name": "request", + "in": "body", + "description": "The cancel media processing request.", + "required": true, + "schema": { + "$ref": "#/definitions/CancelMediaOperationRequest" + } + }, + { + "$ref": "#/parameters/ApiVersionParameter" + } + ], + "responses": { + "200": { + "description": "Returns the cancel media processing response.", + "schema": { + "$ref": "#/definitions/CancelMediaProcessingResponse" + } + }, + "401": { + "description": "Unauthorized", + "schema": { + "$ref": "#/definitions/CommunicationError" + }, + "x-ms-error-response": true + }, + "400": { + "description": "Bad request", + "schema": { + "$ref": "#/definitions/CommunicationError" + }, + "x-ms-error-response": true + }, + "500": { + "description": "Internal server error.", + "schema": { + "$ref": "#/definitions/CommunicationError" + }, + "x-ms-error-response": true + } + } + } + }, "/calling/conversations/{conversationId}/participants": { "post": { "tags": [ @@ -1033,6 +1165,10 @@ "audioFileId": { "description": "An id for the media in the AudioFileUri, using which we cache the media resource.", "type": "string" + }, + "callbackUri": { + "description": "The callback URI.", + "type": "string" } } }, @@ -1170,6 +1306,23 @@ } } }, + "CancelMediaOperationRequest": { + "description": "The request payload for out call cancel media operation", + "required": [ + "operationId" + ], + "type": "object", + "properties": { + "operationContext": { + "description": "The context for this operation.", + "type": "string" + }, + "operationId": { + "description": "The operation Id of out-call.", + "type": "string" + } + } + }, "InviteParticipantsRequest": { "description": "The invite participants request.", "required": [ diff --git a/sdk/communication/Azure.Communication.Calling.Server/tests/ConversationClients/ConversationClientsTests.cs b/sdk/communication/Azure.Communication.Calling.Server/tests/ConversationClients/ConversationClientsTests.cs new file mode 100644 index 0000000000000..6264baeb95315 --- /dev/null +++ b/sdk/communication/Azure.Communication.Calling.Server/tests/ConversationClients/ConversationClientsTests.cs @@ -0,0 +1,262 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using System.Collections.Generic; +using System.Linq.Expressions; +using System.Threading; +using System.Threading.Tasks; +using Moq; +using NUnit.Framework; + +namespace Azure.Communication.Calling.Server.Tests +{ + public class ConversationClientsTests + { + [TestCaseSource(nameof(TestData_StartRecording))] + public async Task StartRecording_Passes(string expectedConversationId, Uri expectedCallbackUri) + { + Mock mockConversationClient = new Mock(); + Response? expectedResponse = default; + CancellationToken cancellationToken = new CancellationTokenSource().Token; + var callExpression = BuildExpression(x => x.StartRecordingAsync(It.IsAny(), It.IsAny(), It.IsAny())); + + mockConversationClient + .Setup(callExpression) + .ReturnsAsync((string conversationId, Uri callBackUri, CancellationToken token) => + { + Assert.AreEqual(expectedConversationId, conversationId); + Assert.AreEqual(expectedCallbackUri, callBackUri); + Assert.AreEqual(cancellationToken, token); + return expectedResponse = new Mock>().Object; + }); + + Response actualResponse = await mockConversationClient.Object.StartRecordingAsync(expectedConversationId, expectedCallbackUri, cancellationToken); + + mockConversationClient.Verify(callExpression, Times.Once()); + Assert.AreEqual(expectedResponse, actualResponse); + } + + [TestCaseSource(nameof(TestData_StopRecording))] + public async Task StopRecording_Passes(string expectedConversationId, string expectedRecordingId) + { + Mock mockConversationClient = new Mock(); + Response? expectedResponse = default; + CancellationToken cancellationToken = new CancellationTokenSource().Token; + var callExpression = BuildExpression(x => x.StopRecordingAsync(It.IsAny(), It.IsAny(), It.IsAny())); + + mockConversationClient + .Setup(callExpression) + .ReturnsAsync((string conversationId, string recordingId, CancellationToken token) => + { + Assert.AreEqual(expectedConversationId, conversationId); + Assert.AreEqual(expectedRecordingId, recordingId); + return expectedResponse = new Mock().Object; + }); + + Response actualResponse = await mockConversationClient.Object.StopRecordingAsync(expectedConversationId, expectedRecordingId, cancellationToken); + + mockConversationClient.Verify(callExpression, Times.Once()); + Assert.AreEqual(expectedResponse, actualResponse); + } + + [TestCaseSource(nameof(TestData_PauseRecording))] + public async Task PauseRecording_Passes(string expectedConversationId, string expectedRecordingId) + { + Mock mockConversationClient = new Mock(); + Response? expectedResponse = default; + CancellationToken cancellationToken = new CancellationTokenSource().Token; + var callExpression = BuildExpression(x => x.PauseRecordingAsync(It.IsAny(), It.IsAny(), It.IsAny())); + + mockConversationClient + .Setup(callExpression) + .ReturnsAsync((string conversationId, string recordingId, CancellationToken token) => + { + Assert.AreEqual(expectedConversationId, conversationId); + Assert.AreEqual(expectedRecordingId, recordingId); + return expectedResponse = new Mock().Object; + }); + + Response actualResponse = await mockConversationClient.Object.PauseRecordingAsync(expectedConversationId, expectedRecordingId, cancellationToken); + + mockConversationClient.Verify(callExpression, Times.Once()); + Assert.AreEqual(expectedResponse, actualResponse); + } + + [TestCaseSource(nameof(TestData_ResumeRecording))] + public async Task ResumeRecording_Passes(string expectedConversationId, string expectedRecordingId) + { + Mock mockConversationClient = new Mock(); + Response? expectedResponse = default; + CancellationToken cancellationToken = new CancellationTokenSource().Token; + var callExpression = BuildExpression(x => x.ResumeRecordingAsync(It.IsAny(), It.IsAny(), It.IsAny())); + + mockConversationClient + .Setup(callExpression) + .ReturnsAsync((string conversationId, string recordingId, CancellationToken token) => + { + Assert.AreEqual(expectedConversationId, conversationId); + Assert.AreEqual(expectedRecordingId, recordingId); + return expectedResponse = new Mock().Object; + }); + + Response actualResponse = await mockConversationClient.Object.ResumeRecordingAsync(expectedConversationId, expectedRecordingId, cancellationToken); + + mockConversationClient.Verify(callExpression, Times.Once()); + Assert.AreEqual(expectedResponse, actualResponse); + } + + [TestCaseSource(nameof(TestData_GetRecordingState))] + public async Task GetRecordingState_Passes(string expectedConversationId, string expectedRecordingId) + { + Mock mockConversationClient = new Mock(); + Response? expectedResponse = default; + CancellationToken cancellationToken = new CancellationTokenSource().Token; + var callExpression = BuildExpression(x => x.GetRecordingStateAsync(It.IsAny(), It.IsAny(), It.IsAny())); + + mockConversationClient + .Setup(callExpression) + .ReturnsAsync((string conversationId, string recordingId, CancellationToken token) => + { + Assert.AreEqual(expectedConversationId, conversationId); + Assert.AreEqual(expectedRecordingId, recordingId); + return expectedResponse = new Mock>().Object; + }); + + Response actualResponse = await mockConversationClient.Object.GetRecordingStateAsync(expectedConversationId, expectedRecordingId, cancellationToken); + + mockConversationClient.Verify(callExpression, Times.Once()); + Assert.AreEqual(expectedResponse, actualResponse); + } + + [TestCaseSource(nameof(TestData_PlayAudioWithRequest))] + public async Task PlayAudioAsyncOverload_Passes(string expectedConversationId, PlayAudioRequest expectedRequest) + { + Mock mockConversationClient = new Mock(); + Response? expectedResponse = default; + CancellationToken cancellationToken = new CancellationTokenSource().Token; + var callExpression = BuildExpression(x => x.PlayAudioAsync(It.IsAny(), It.IsAny(), It.IsAny())); + + mockConversationClient + .Setup(callExpression) + .ReturnsAsync((string conversationId, PlayAudioRequest request, CancellationToken token) => + { + Assert.AreEqual(expectedConversationId, conversationId); + Assert.AreEqual(expectedRequest, request); + Assert.AreEqual(cancellationToken, token); + return expectedResponse = new Mock>().Object; + }); + + Response actualResponse = await mockConversationClient.Object.PlayAudioAsync(expectedConversationId, expectedRequest, cancellationToken); + + mockConversationClient.Verify(callExpression, Times.Once()); + Assert.AreEqual(expectedResponse, actualResponse); + } + + [TestCaseSource(nameof(TestData_CancelMediaOperation))] + public async Task CancelMediaOperationAsync_Passes(string expectedConversationId, CancelMediaOperationRequest expectedRequest) + { + Mock mockConversationClient = new Mock() { CallBase = true }; + Response? expectedResponse = default; + CancellationToken cancellationToken = new CancellationTokenSource().Token; + var callExpression = BuildExpression(x => x.CancelMediaOperationAsync(It.IsAny(), It.IsAny(), It.IsAny())); + + mockConversationClient + .Setup(callExpression) + .ReturnsAsync((string conversationId, CancelMediaOperationRequest request, CancellationToken token) => + { + Assert.AreEqual(expectedConversationId, conversationId); + Assert.AreEqual(expectedRequest, request); + Assert.AreEqual(cancellationToken, token); + return expectedResponse = new Mock>().Object; + }); + + Response actualResponse = await mockConversationClient.Object.CancelMediaOperationAsync(expectedConversationId, expectedRequest, cancellationToken); + + mockConversationClient.Verify(callExpression, Times.Once()); + Assert.AreEqual(expectedResponse, actualResponse); + } + + private static IEnumerable TestData_StartRecording() + { + return new List(){ + new object?[] { + "sampleConversationId", + new Uri("https://somecallbackurl"), + }, + }; + } + + private static IEnumerable TestData_StopRecording() + { + return new List(){ + new object?[] { + "sampleConversationId", + "sampleRecordingId", + }, + }; + } + + private static IEnumerable TestData_PauseRecording() + { + return new List(){ + new object?[] { + "sampleConversationId", + "sampleRecordingId", + }, + }; + } + + private static IEnumerable TestData_ResumeRecording() + { + return new List(){ + new object?[] { + "sampleConversationId", + "sampleRecordingId", + }, + }; + } + + private static IEnumerable TestData_GetRecordingState() + { + return new List(){ + new object?[] { + "sampleConversationId", + "sampleRecordingId", + }, + }; + } + + private static IEnumerable TestData_PlayAudioWithRequest() + { + return new List(){ + new object?[] { + "sampleConversationId", + new PlayAudioRequest() + { + AudioFileUri = "https://av.ngrok.io/audio/sample-message.wav", + OperationContext = Guid.NewGuid().ToString(), + Loop = true, + AudioFileId = Guid.NewGuid().ToString() + } + } + }; + } + + private static IEnumerable TestData_CancelMediaOperation() + { + return new List(){ + new object?[] { + "sampleConversationId", + new CancelMediaOperationRequest(operationId: "sampleOperationId") + { + OperationContext = "sampleOperationContext" + } + }, + }; + } + + private static Expression> BuildExpression(Expression> expression) + => expression; + } +} From ee76c482fd8e42e1636c88495ea0934ffc487394 Mon Sep 17 00:00:00 2001 From: Paresh Arvind Patil Date: Thu, 27 May 2021 15:16:33 -0700 Subject: [PATCH 2/5] Added PlayAudio api on ConversationClient --- .../src/ConversationClient.cs | 96 ++++++------------- .../src/Generated/ConversationRestClient.cs | 84 ---------------- ...ncelMediaOperationRequest.Serialization.cs | 28 ------ .../Models/CancelMediaOperationRequest.cs | 33 ------- .../src/swagger/Sample-Swagger.json | 83 ---------------- .../ConversationClientsTests.cs | 61 ++---------- 6 files changed, 38 insertions(+), 347 deletions(-) delete mode 100644 sdk/communication/Azure.Communication.Calling.Server/src/Generated/Models/CancelMediaOperationRequest.Serialization.cs delete mode 100644 sdk/communication/Azure.Communication.Calling.Server/src/Generated/Models/CancelMediaOperationRequest.cs diff --git a/sdk/communication/Azure.Communication.Calling.Server/src/ConversationClient.cs b/sdk/communication/Azure.Communication.Calling.Server/src/ConversationClient.cs index ab736cd75ba3d..60c0e1c4108f8 100644 --- a/sdk/communication/Azure.Communication.Calling.Server/src/ConversationClient.cs +++ b/sdk/communication/Azure.Communication.Calling.Server/src/ConversationClient.cs @@ -410,21 +410,26 @@ public virtual Response GetRecordingState(string } } - /// - /// PlayAudio - /// - /// The conversation id. - /// Play audio request. - /// The cancellation token. - /// - public virtual async Task> PlayAudioAsync(string conversationId, PlayAudioRequest request, CancellationToken cancellationToken = default) + /// Play Audio. + /// The conversation id. + /// The uri of the audio file. + /// The operation context. + /// The cancellation token to use. + public virtual async Task> PlayAudioAsync(string conversationId, Uri audioFileUri, string operationContext, CancellationToken cancellationToken = default) { using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(ConversationClient)}.{nameof(PlayAudioAsync)}"); scope.Start(); try { Argument.AssertNotNullOrEmpty(conversationId, nameof(conversationId)); - Argument.AssertNotNull(request, nameof(request)); + Argument.AssertNotNull(audioFileUri, nameof(audioFileUri)); + + PlayAudioRequest request = new PlayAudioRequest() + { + AudioFileUri = audioFileUri.AbsoluteUri, + Loop = false, + OperationContext = operationContext + }; return await RestClient.PlayAudioAsync(conversationId, request, cancellationToken).ConfigureAwait(false); } @@ -435,73 +440,28 @@ public virtual async Task> PlayAudioAsync(string con } } - /// - /// PlayAudio - /// - /// The conversation id. - /// Play audio request. - /// The cancellation token. - /// - public virtual Response PlayAudio(string conversationId, PlayAudioRequest request, CancellationToken cancellationToken = default) + /// Play Audio. + /// The conversation id. + /// The uri of the audio file. + /// The operation context. + /// The cancellation token to use. + public virtual Response PlayAudio(string conversationId, Uri audioFileUri, string operationContext, CancellationToken cancellationToken = default) { using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(ConversationClient)}.{nameof(PlayAudio)}"); scope.Start(); try { Argument.AssertNotNullOrEmpty(conversationId, nameof(conversationId)); - Argument.AssertNotNull(request, nameof(request)); - - return RestClient.PlayAudio(conversationId, request, cancellationToken); - } - catch (Exception ex) - { - scope.Failed(ex); - throw; - } - } - - /// - /// Cancel Media Processing. - /// - /// The conversation id. - /// Cancel media request. - /// The cancellation token. - /// - public virtual async Task> CancelMediaOperationAsync(string conversationId, CancelMediaOperationRequest request, CancellationToken cancellationToken = default) - { - using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(ConversationClient)}.{nameof(CancelMediaOperationAsync)}"); - scope.Start(); - try - { - Argument.AssertNotNullOrEmpty(conversationId, nameof(conversationId)); - Argument.AssertNotNull(request, nameof(request)); - - return await RestClient.CancelMediaOperationAsync(conversationId, request, cancellationToken).ConfigureAwait(false); - } - catch (Exception ex) - { - scope.Failed(ex); - throw; - } - } + Argument.AssertNotNull(audioFileUri, nameof(audioFileUri)); - /// - /// Cancel Media Processing. - /// - /// The conversation id. - /// Cancel media request. - /// The cancellation token. - /// - public virtual Response CancelMediaOperation(string conversationId, CancelMediaOperationRequest request, CancellationToken cancellationToken = default) - { - using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(ConversationClient)}.{nameof(CancelMediaOperation)}"); - scope.Start(); - try - { - Argument.AssertNotNullOrEmpty(conversationId, nameof(conversationId)); - Argument.AssertNotNull(request, nameof(request)); + PlayAudioRequest request = new PlayAudioRequest() + { + AudioFileUri = audioFileUri.AbsoluteUri, + Loop = false, + OperationContext = operationContext + }; - return RestClient.CancelMediaOperation(conversationId, request, cancellationToken); + return RestClient.PlayAudio(conversationId, request, cancellationToken); } catch (Exception ex) { diff --git a/sdk/communication/Azure.Communication.Calling.Server/src/Generated/ConversationRestClient.cs b/sdk/communication/Azure.Communication.Calling.Server/src/Generated/ConversationRestClient.cs index a0affa23c5ad8..77876201d30da 100644 --- a/sdk/communication/Azure.Communication.Calling.Server/src/Generated/ConversationRestClient.cs +++ b/sdk/communication/Azure.Communication.Calling.Server/src/Generated/ConversationRestClient.cs @@ -213,90 +213,6 @@ public Response PlayAudio(string conversationId, PlayAudioReq } } - internal HttpMessage CreateCancelMediaOperationRequest(string conversationId, CancelMediaOperationRequest request) - { - var message = _pipeline.CreateMessage(); - var request0 = message.Request; - request0.Method = RequestMethod.Post; - var uri = new RawRequestUriBuilder(); - uri.AppendRaw(endpoint, false); - uri.AppendPath("/calling/conversations/", false); - uri.AppendPath(conversationId, true); - uri.AppendPath("/CancelMediaOperation", false); - uri.AppendQuery("api-version", apiVersion, true); - request0.Uri = uri; - request0.Headers.Add("Accept", "application/json"); - request0.Headers.Add("Content-Type", "application/json"); - var content = new Utf8JsonRequestContent(); - content.JsonWriter.WriteObjectValue(request); - request0.Content = content; - return message; - } - - /// Cancel Media Processing. - /// The conversation id which can be guid or encoded cs url. - /// The cancel media processing request. - /// The cancellation token to use. - /// or is null. - public async Task> CancelMediaOperationAsync(string conversationId, CancelMediaOperationRequest request, CancellationToken cancellationToken = default) - { - if (conversationId == null) - { - throw new ArgumentNullException(nameof(conversationId)); - } - if (request == null) - { - throw new ArgumentNullException(nameof(request)); - } - - using var message = CreateCancelMediaOperationRequest(conversationId, request); - await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); - switch (message.Response.Status) - { - case 200: - { - CancelMediaProcessingResponse value = default; - using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, cancellationToken).ConfigureAwait(false); - value = CancelMediaProcessingResponse.DeserializeCancelMediaProcessingResponse(document.RootElement); - return Response.FromValue(value, message.Response); - } - default: - throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false); - } - } - - /// Cancel Media Processing. - /// The conversation id which can be guid or encoded cs url. - /// The cancel media processing request. - /// The cancellation token to use. - /// or is null. - public Response CancelMediaOperation(string conversationId, CancelMediaOperationRequest request, CancellationToken cancellationToken = default) - { - if (conversationId == null) - { - throw new ArgumentNullException(nameof(conversationId)); - } - if (request == null) - { - throw new ArgumentNullException(nameof(request)); - } - - using var message = CreateCancelMediaOperationRequest(conversationId, request); - _pipeline.Send(message, cancellationToken); - switch (message.Response.Status) - { - case 200: - { - CancelMediaProcessingResponse value = default; - using var document = JsonDocument.Parse(message.Response.ContentStream); - value = CancelMediaProcessingResponse.DeserializeCancelMediaProcessingResponse(document.RootElement); - return Response.FromValue(value, message.Response); - } - default: - throw _clientDiagnostics.CreateRequestFailedException(message.Response); - } - } - internal HttpMessage CreateInviteParticipantsRequest(string conversationId, InviteParticipantsRequestInternal inviteParticipantsRequest) { var message = _pipeline.CreateMessage(); diff --git a/sdk/communication/Azure.Communication.Calling.Server/src/Generated/Models/CancelMediaOperationRequest.Serialization.cs b/sdk/communication/Azure.Communication.Calling.Server/src/Generated/Models/CancelMediaOperationRequest.Serialization.cs deleted file mode 100644 index 5cf88eef6a9ce..0000000000000 --- a/sdk/communication/Azure.Communication.Calling.Server/src/Generated/Models/CancelMediaOperationRequest.Serialization.cs +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -// - -#nullable disable - -using System.Text.Json; -using Azure.Core; - -namespace Azure.Communication.Calling.Server -{ - public partial class CancelMediaOperationRequest : IUtf8JsonSerializable - { - void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) - { - writer.WriteStartObject(); - if (Optional.IsDefined(OperationContext)) - { - writer.WritePropertyName("operationContext"); - writer.WriteStringValue(OperationContext); - } - writer.WritePropertyName("operationId"); - writer.WriteStringValue(OperationId); - writer.WriteEndObject(); - } - } -} diff --git a/sdk/communication/Azure.Communication.Calling.Server/src/Generated/Models/CancelMediaOperationRequest.cs b/sdk/communication/Azure.Communication.Calling.Server/src/Generated/Models/CancelMediaOperationRequest.cs deleted file mode 100644 index 34b3586c59d73..0000000000000 --- a/sdk/communication/Azure.Communication.Calling.Server/src/Generated/Models/CancelMediaOperationRequest.cs +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -// - -#nullable disable - -using System; - -namespace Azure.Communication.Calling.Server -{ - /// The request payload for out call cancel media operation. - public partial class CancelMediaOperationRequest - { - /// Initializes a new instance of CancelMediaOperationRequest. - /// The operation Id of out-call. - /// is null. - public CancelMediaOperationRequest(string operationId) - { - if (operationId == null) - { - throw new ArgumentNullException(nameof(operationId)); - } - - OperationId = operationId; - } - - /// The context for this operation. - public string OperationContext { get; set; } - /// The operation Id of out-call. - public string OperationId { get; } - } -} diff --git a/sdk/communication/Azure.Communication.Calling.Server/src/swagger/Sample-Swagger.json b/sdk/communication/Azure.Communication.Calling.Server/src/swagger/Sample-Swagger.json index 3757ebef522e2..dd65f3550434c 100644 --- a/sdk/communication/Azure.Communication.Calling.Server/src/swagger/Sample-Swagger.json +++ b/sdk/communication/Azure.Communication.Calling.Server/src/swagger/Sample-Swagger.json @@ -445,72 +445,6 @@ } } }, - "/calling/conversations/{conversationId}/CancelMediaOperation": { - "post": { - "tags": [ - "Call" - ], - "summary": "Cancel Media Processing.", - "description": "Cancel Media Processing.", - "operationId": "Conversation_CancelMediaOperation", - "consumes": [ - "application/json" - ], - "produces": [ - "application/json" - ], - "parameters": [ - { - "name": "conversationId", - "in": "path", - "description": "The conversation id which can be guid or encoded cs url", - "required": true, - "type": "string" - }, - { - "name": "request", - "in": "body", - "description": "The cancel media processing request.", - "required": true, - "schema": { - "$ref": "#/definitions/CancelMediaOperationRequest" - } - }, - { - "$ref": "#/parameters/ApiVersionParameter" - } - ], - "responses": { - "200": { - "description": "Returns the cancel media processing response.", - "schema": { - "$ref": "#/definitions/CancelMediaProcessingResponse" - } - }, - "401": { - "description": "Unauthorized", - "schema": { - "$ref": "#/definitions/CommunicationError" - }, - "x-ms-error-response": true - }, - "400": { - "description": "Bad request", - "schema": { - "$ref": "#/definitions/CommunicationError" - }, - "x-ms-error-response": true - }, - "500": { - "description": "Internal server error.", - "schema": { - "$ref": "#/definitions/CommunicationError" - }, - "x-ms-error-response": true - } - } - } - }, "/calling/conversations/{conversationId}/participants": { "post": { "tags": [ @@ -1306,23 +1240,6 @@ } } }, - "CancelMediaOperationRequest": { - "description": "The request payload for out call cancel media operation", - "required": [ - "operationId" - ], - "type": "object", - "properties": { - "operationContext": { - "description": "The context for this operation.", - "type": "string" - }, - "operationId": { - "description": "The operation Id of out-call.", - "type": "string" - } - } - }, "InviteParticipantsRequest": { "description": "The invite participants request.", "required": [ diff --git a/sdk/communication/Azure.Communication.Calling.Server/tests/ConversationClients/ConversationClientsTests.cs b/sdk/communication/Azure.Communication.Calling.Server/tests/ConversationClients/ConversationClientsTests.cs index 6264baeb95315..7759b086fc9a6 100644 --- a/sdk/communication/Azure.Communication.Calling.Server/tests/ConversationClients/ConversationClientsTests.cs +++ b/sdk/communication/Azure.Communication.Calling.Server/tests/ConversationClients/ConversationClientsTests.cs @@ -129,49 +129,26 @@ public async Task GetRecordingState_Passes(string expectedConversationId, string Assert.AreEqual(expectedResponse, actualResponse); } - [TestCaseSource(nameof(TestData_PlayAudioWithRequest))] - public async Task PlayAudioAsyncOverload_Passes(string expectedConversationId, PlayAudioRequest expectedRequest) + [TestCaseSource(nameof(TestData_PlayAudioWithoutRequest))] + public async Task PlayAudioAsync_Passes(string expectedConversationId, Uri expectedAudioFileUri, string expectedOperationContext) { Mock mockConversationClient = new Mock(); Response? expectedResponse = default; CancellationToken cancellationToken = new CancellationTokenSource().Token; - var callExpression = BuildExpression(x => x.PlayAudioAsync(It.IsAny(), It.IsAny(), It.IsAny())); + var callExpression = BuildExpression(x => x.PlayAudioAsync(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny())); mockConversationClient .Setup(callExpression) - .ReturnsAsync((string conversationId, PlayAudioRequest request, CancellationToken token) => + .ReturnsAsync((string conversationId, Uri audioFileUri, string operationContext, CancellationToken token) => { Assert.AreEqual(expectedConversationId, conversationId); - Assert.AreEqual(expectedRequest, request); + Assert.AreEqual(expectedAudioFileUri, audioFileUri); + Assert.AreEqual(expectedOperationContext, operationContext); Assert.AreEqual(cancellationToken, token); return expectedResponse = new Mock>().Object; }); - Response actualResponse = await mockConversationClient.Object.PlayAudioAsync(expectedConversationId, expectedRequest, cancellationToken); - - mockConversationClient.Verify(callExpression, Times.Once()); - Assert.AreEqual(expectedResponse, actualResponse); - } - - [TestCaseSource(nameof(TestData_CancelMediaOperation))] - public async Task CancelMediaOperationAsync_Passes(string expectedConversationId, CancelMediaOperationRequest expectedRequest) - { - Mock mockConversationClient = new Mock() { CallBase = true }; - Response? expectedResponse = default; - CancellationToken cancellationToken = new CancellationTokenSource().Token; - var callExpression = BuildExpression(x => x.CancelMediaOperationAsync(It.IsAny(), It.IsAny(), It.IsAny())); - - mockConversationClient - .Setup(callExpression) - .ReturnsAsync((string conversationId, CancelMediaOperationRequest request, CancellationToken token) => - { - Assert.AreEqual(expectedConversationId, conversationId); - Assert.AreEqual(expectedRequest, request); - Assert.AreEqual(cancellationToken, token); - return expectedResponse = new Mock>().Object; - }); - - Response actualResponse = await mockConversationClient.Object.CancelMediaOperationAsync(expectedConversationId, expectedRequest, cancellationToken); + Response actualResponse = await mockConversationClient.Object.PlayAudioAsync(expectedConversationId, expectedAudioFileUri, expectedOperationContext, cancellationToken); mockConversationClient.Verify(callExpression, Times.Once()); Assert.AreEqual(expectedResponse, actualResponse); @@ -227,35 +204,17 @@ public async Task CancelMediaOperationAsync_Passes(string expectedConversationId }; } - private static IEnumerable TestData_PlayAudioWithRequest() + private static IEnumerable TestData_PlayAudioWithoutRequest() { return new List(){ new object?[] { "sampleConversationId", - new PlayAudioRequest() - { - AudioFileUri = "https://av.ngrok.io/audio/sample-message.wav", - OperationContext = Guid.NewGuid().ToString(), - Loop = true, - AudioFileId = Guid.NewGuid().ToString() - } + new Uri("https://av.ngrok.io/audio/sample-message.wav"), + "sampleOperationContext", } }; } - private static IEnumerable TestData_CancelMediaOperation() - { - return new List(){ - new object?[] { - "sampleConversationId", - new CancelMediaOperationRequest(operationId: "sampleOperationId") - { - OperationContext = "sampleOperationContext" - } - }, - }; - } - private static Expression> BuildExpression(Expression> expression) => expression; } From d4bfc4721207ced7270d9864262661ef8e1114e7 Mon Sep 17 00:00:00 2001 From: Paresh Arvind Patil Date: Thu, 27 May 2021 16:30:22 -0700 Subject: [PATCH 3/5] Updated the PlayAudio url description --- .../src/Generated/Models/PlayAudioRequest.cs | 2 +- .../src/swagger/Sample-Swagger.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/sdk/communication/Azure.Communication.Calling.Server/src/Generated/Models/PlayAudioRequest.cs b/sdk/communication/Azure.Communication.Calling.Server/src/Generated/Models/PlayAudioRequest.cs index b06d0b2e311eb..7684e7ba69315 100644 --- a/sdk/communication/Azure.Communication.Calling.Server/src/Generated/Models/PlayAudioRequest.cs +++ b/sdk/communication/Azure.Communication.Calling.Server/src/Generated/Models/PlayAudioRequest.cs @@ -31,7 +31,7 @@ public PlayAudioRequest() public string OperationContext { get; set; } /// An id for the media in the AudioFileUri, using which we cache the media resource. public string AudioFileId { get; set; } - /// The callback URI. + /// The callback Uri to recieve PlayAudio status notifications. public string CallbackUri { get; set; } } } diff --git a/sdk/communication/Azure.Communication.Calling.Server/src/swagger/Sample-Swagger.json b/sdk/communication/Azure.Communication.Calling.Server/src/swagger/Sample-Swagger.json index dd65f3550434c..2eb33e9b23fe0 100644 --- a/sdk/communication/Azure.Communication.Calling.Server/src/swagger/Sample-Swagger.json +++ b/sdk/communication/Azure.Communication.Calling.Server/src/swagger/Sample-Swagger.json @@ -1101,7 +1101,7 @@ "type": "string" }, "callbackUri": { - "description": "The callback URI.", + "description": "The callback Uri to recieve PlayAudio status notifications.", "type": "string" } } From 09622afe87abe4bc0cc6bdf000ae07fa4c031c99 Mon Sep 17 00:00:00 2001 From: Paresh Arvind Patil Date: Thu, 27 May 2021 17:35:05 -0700 Subject: [PATCH 4/5] Updated as per PR feedback --- .../src/ConversationClient.cs | 2 ++ .../src/swagger/Sample-Swagger.json | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/sdk/communication/Azure.Communication.Calling.Server/src/ConversationClient.cs b/sdk/communication/Azure.Communication.Calling.Server/src/ConversationClient.cs index 60c0e1c4108f8..e209e19acaf8c 100644 --- a/sdk/communication/Azure.Communication.Calling.Server/src/ConversationClient.cs +++ b/sdk/communication/Azure.Communication.Calling.Server/src/ConversationClient.cs @@ -424,6 +424,7 @@ public virtual async Task> PlayAudioAsync(string con Argument.AssertNotNullOrEmpty(conversationId, nameof(conversationId)); Argument.AssertNotNull(audioFileUri, nameof(audioFileUri)); + // Currently looping media is not supported for out-call scenarios, thus setting it to false. PlayAudioRequest request = new PlayAudioRequest() { AudioFileUri = audioFileUri.AbsoluteUri, @@ -454,6 +455,7 @@ public virtual Response PlayAudio(string conversationId, Uri Argument.AssertNotNullOrEmpty(conversationId, nameof(conversationId)); Argument.AssertNotNull(audioFileUri, nameof(audioFileUri)); + // Currently looping media is not supported for out-call scenarios, thus setting it to false. PlayAudioRequest request = new PlayAudioRequest() { AudioFileUri = audioFileUri.AbsoluteUri, diff --git a/sdk/communication/Azure.Communication.Calling.Server/src/swagger/Sample-Swagger.json b/sdk/communication/Azure.Communication.Calling.Server/src/swagger/Sample-Swagger.json index 2eb33e9b23fe0..44eabccc09218 100644 --- a/sdk/communication/Azure.Communication.Calling.Server/src/swagger/Sample-Swagger.json +++ b/sdk/communication/Azure.Communication.Calling.Server/src/swagger/Sample-Swagger.json @@ -1101,7 +1101,7 @@ "type": "string" }, "callbackUri": { - "description": "The callback Uri to recieve PlayAudio status notifications.", + "description": "The callback Uri to receive PlayAudio status notifications.", "type": "string" } } From 5ef9ed5a49db5445aa12b2e681c4a20b2dad4387 Mon Sep 17 00:00:00 2001 From: Paresh Arvind Patil Date: Fri, 28 May 2021 12:56:34 -0700 Subject: [PATCH 5/5] Re-build the swagger updating the auto-genrated files --- .../src/Generated/ConversationRestClient.cs | 84 ------------------- .../Models/PlayAudioRequest.Serialization.cs | 5 -- .../src/Generated/Models/PlayAudioRequest.cs | 2 - 3 files changed, 91 deletions(-) diff --git a/sdk/communication/Azure.Communication.Calling.Server/src/Generated/ConversationRestClient.cs b/sdk/communication/Azure.Communication.Calling.Server/src/Generated/ConversationRestClient.cs index 77876201d30da..62732abd6037f 100644 --- a/sdk/communication/Azure.Communication.Calling.Server/src/Generated/ConversationRestClient.cs +++ b/sdk/communication/Azure.Communication.Calling.Server/src/Generated/ConversationRestClient.cs @@ -129,90 +129,6 @@ public Response JoinCall(string conversationId, JoinCallReques } } - internal HttpMessage CreatePlayAudioRequest(string conversationId, PlayAudioRequest request) - { - var message = _pipeline.CreateMessage(); - var request0 = message.Request; - request0.Method = RequestMethod.Post; - var uri = new RawRequestUriBuilder(); - uri.AppendRaw(endpoint, false); - uri.AppendPath("/calling/conversations/", false); - uri.AppendPath(conversationId, true); - uri.AppendPath("/PlayAudio", false); - uri.AppendQuery("api-version", apiVersion, true); - request0.Uri = uri; - request0.Headers.Add("Accept", "application/json"); - request0.Headers.Add("Content-Type", "application/json"); - var content = new Utf8JsonRequestContent(); - content.JsonWriter.WriteObjectValue(request); - request0.Content = content; - return message; - } - - /// Play audio in a call. - /// The conversation id which can be guid or encoded cs url. - /// Play audio request. - /// The cancellation token to use. - /// or is null. - public async Task> PlayAudioAsync(string conversationId, PlayAudioRequest request, CancellationToken cancellationToken = default) - { - if (conversationId == null) - { - throw new ArgumentNullException(nameof(conversationId)); - } - if (request == null) - { - throw new ArgumentNullException(nameof(request)); - } - - using var message = CreatePlayAudioRequest(conversationId, request); - await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); - switch (message.Response.Status) - { - case 202: - { - PlayAudioResponse value = default; - using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, cancellationToken).ConfigureAwait(false); - value = PlayAudioResponse.DeserializePlayAudioResponse(document.RootElement); - return Response.FromValue(value, message.Response); - } - default: - throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false); - } - } - - /// Play audio in a call. - /// The conversation id which can be guid or encoded cs url. - /// Play audio request. - /// The cancellation token to use. - /// or is null. - public Response PlayAudio(string conversationId, PlayAudioRequest request, CancellationToken cancellationToken = default) - { - if (conversationId == null) - { - throw new ArgumentNullException(nameof(conversationId)); - } - if (request == null) - { - throw new ArgumentNullException(nameof(request)); - } - - using var message = CreatePlayAudioRequest(conversationId, request); - _pipeline.Send(message, cancellationToken); - switch (message.Response.Status) - { - case 202: - { - PlayAudioResponse value = default; - using var document = JsonDocument.Parse(message.Response.ContentStream); - value = PlayAudioResponse.DeserializePlayAudioResponse(document.RootElement); - return Response.FromValue(value, message.Response); - } - default: - throw _clientDiagnostics.CreateRequestFailedException(message.Response); - } - } - internal HttpMessage CreateInviteParticipantsRequest(string conversationId, InviteParticipantsRequestInternal inviteParticipantsRequest) { var message = _pipeline.CreateMessage(); diff --git a/sdk/communication/Azure.Communication.Calling.Server/src/Generated/Models/PlayAudioRequest.Serialization.cs b/sdk/communication/Azure.Communication.Calling.Server/src/Generated/Models/PlayAudioRequest.Serialization.cs index bbb2f26b9d1f9..a3aea81532143 100644 --- a/sdk/communication/Azure.Communication.Calling.Server/src/Generated/Models/PlayAudioRequest.Serialization.cs +++ b/sdk/communication/Azure.Communication.Calling.Server/src/Generated/Models/PlayAudioRequest.Serialization.cs @@ -35,11 +35,6 @@ void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) writer.WritePropertyName("audioFileId"); writer.WriteStringValue(AudioFileId); } - if (Optional.IsDefined(CallbackUri)) - { - writer.WritePropertyName("callbackUri"); - writer.WriteStringValue(CallbackUri); - } writer.WriteEndObject(); } } diff --git a/sdk/communication/Azure.Communication.Calling.Server/src/Generated/Models/PlayAudioRequest.cs b/sdk/communication/Azure.Communication.Calling.Server/src/Generated/Models/PlayAudioRequest.cs index 7684e7ba69315..02b56fad69d3e 100644 --- a/sdk/communication/Azure.Communication.Calling.Server/src/Generated/Models/PlayAudioRequest.cs +++ b/sdk/communication/Azure.Communication.Calling.Server/src/Generated/Models/PlayAudioRequest.cs @@ -31,7 +31,5 @@ public PlayAudioRequest() public string OperationContext { get; set; } /// An id for the media in the AudioFileUri, using which we cache the media resource. public string AudioFileId { get; set; } - /// The callback Uri to recieve PlayAudio status notifications. - public string CallbackUri { get; set; } } }