Skip to content

Commit

Permalink
change playsource input from object to enumerable (Azure#36456)
Browse files Browse the repository at this point in the history
* change playsource input from object to enumerable

* update netstandard2.0

* change playSourceInfo to playSources
  • Loading branch information
wangrui-msft authored May 24, 2023
1 parent 98f2787 commit 279909e
Show file tree
Hide file tree
Showing 23 changed files with 265 additions and 88 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,8 @@ public static partial class CallAutomationModelFactory
public static Azure.Communication.CallAutomation.ChoiceResult ChoiceResult(string label = null, string recognizedPhrase = null) { throw null; }
public static Azure.Communication.CallAutomation.CollectTonesResult CollectTonesResult(System.Collections.Generic.IEnumerable<Azure.Communication.CallAutomation.DtmfTone> tones = null) { throw null; }
public static Azure.Communication.CallAutomation.ContinuousDtmfRecognitionStopped ContinuousDtmfRecognitionStopped(string callConnectionId = null, string serverCallId = null, string correlationId = null, string operationContext = null, Azure.Communication.CallAutomation.ResultInformation resultInformation = null) { throw null; }
public static Azure.Communication.CallAutomation.ContinuousDtmfRecognitionToneFailed ContinuousDtmfRecognitionToneFailed(string callConnectionId = null, string serverCallId = null, string correlationId = null, string operationContext = null, Azure.Communication.CallAutomation.ResultInformation resultInformation = null) { throw null; }
public static Azure.Communication.CallAutomation.ContinuousDtmfRecognitionToneReceived ContinuousDtmfRecognitionToneReceived(Azure.Communication.CallAutomation.ToneInfo toneInfo = null, string callConnectionId = null, string serverCallId = null, string correlationId = null, string operationContext = null, Azure.Communication.CallAutomation.ResultInformation resultInformation = null) { throw null; }
public static Azure.Communication.CallAutomation.ContinuousDtmfRecognitionToneFailed ContinuousDtmfRecognitionToneFailed(string callConnectionId = null, string serverCallId = null, string correlationId = null, Azure.Communication.CallAutomation.ResultInformation resultInformation = null, string operationContext = null) { throw null; }
public static Azure.Communication.CallAutomation.ContinuousDtmfRecognitionToneReceived ContinuousDtmfRecognitionToneReceived(Azure.Communication.CallAutomation.ToneInfo toneInfo = null, string callConnectionId = null, string serverCallId = null, string correlationId = null, Azure.Communication.CallAutomation.ResultInformation resultInformation = null, string operationContext = null) { throw null; }
public static Azure.Communication.CallAutomation.CreateCallResult CreateCallResult(Azure.Communication.CallAutomation.CallConnection callConnection = null, Azure.Communication.CallAutomation.CallConnectionProperties callConnectionProperties = null) { throw null; }
public static Azure.Communication.CallAutomation.DtmfResult DtmfResult(System.Collections.Generic.IEnumerable<Azure.Communication.CallAutomation.DtmfTone> tones = null) { throw null; }
public static Azure.Communication.CallAutomation.MuteParticipantsResponse MuteParticipantsResponse(string operationContext = null) { throw null; }
Expand Down Expand Up @@ -291,12 +291,16 @@ protected CallMedia() { }
public virtual System.Threading.Tasks.Task<Azure.Response<Azure.Communication.CallAutomation.CancelAllMediaOperationsResult>> CancelAllMediaOperationsAsync(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual Azure.Response<Azure.Communication.CallAutomation.PlayResult> Play(Azure.Communication.CallAutomation.PlayOptions options, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual Azure.Response<Azure.Communication.CallAutomation.PlayResult> Play(Azure.Communication.CallAutomation.PlaySource playSource, System.Collections.Generic.IEnumerable<Azure.Communication.CommunicationIdentifier> playTo, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual Azure.Response<Azure.Communication.CallAutomation.PlayResult> Play(System.Collections.Generic.IEnumerable<Azure.Communication.CallAutomation.PlaySource> playSources, System.Collections.Generic.IEnumerable<Azure.Communication.CommunicationIdentifier> playTo, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual System.Threading.Tasks.Task<Azure.Response<Azure.Communication.CallAutomation.PlayResult>> PlayAsync(Azure.Communication.CallAutomation.PlayOptions options, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual System.Threading.Tasks.Task<Azure.Response<Azure.Communication.CallAutomation.PlayResult>> PlayAsync(Azure.Communication.CallAutomation.PlaySource playSource, System.Collections.Generic.IEnumerable<Azure.Communication.CommunicationIdentifier> playTo, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual System.Threading.Tasks.Task<Azure.Response<Azure.Communication.CallAutomation.PlayResult>> PlayAsync(System.Collections.Generic.IEnumerable<Azure.Communication.CallAutomation.PlaySource> playSources, System.Collections.Generic.IEnumerable<Azure.Communication.CommunicationIdentifier> playTo, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual Azure.Response<Azure.Communication.CallAutomation.PlayResult> PlayToAll(Azure.Communication.CallAutomation.PlaySource playSource, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual Azure.Response<Azure.Communication.CallAutomation.PlayResult> PlayToAll(Azure.Communication.CallAutomation.PlayToAllOptions options, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual Azure.Response<Azure.Communication.CallAutomation.PlayResult> PlayToAll(System.Collections.Generic.IEnumerable<Azure.Communication.CallAutomation.PlaySource> playSources, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual System.Threading.Tasks.Task<Azure.Response<Azure.Communication.CallAutomation.PlayResult>> PlayToAllAsync(Azure.Communication.CallAutomation.PlaySource playSource, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual System.Threading.Tasks.Task<Azure.Response<Azure.Communication.CallAutomation.PlayResult>> PlayToAllAsync(Azure.Communication.CallAutomation.PlayToAllOptions options, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual System.Threading.Tasks.Task<Azure.Response<Azure.Communication.CallAutomation.PlayResult>> PlayToAllAsync(System.Collections.Generic.IEnumerable<Azure.Communication.CallAutomation.PlaySource> playSources, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual Azure.Response<Azure.Communication.CallAutomation.SendDtmfResult> SendDtmf(System.Collections.Generic.IEnumerable<Azure.Communication.CallAutomation.DtmfTone> tones, Azure.Communication.CommunicationIdentifier targetParticipant, string operationContext = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual System.Threading.Tasks.Task<Azure.Response<Azure.Communication.CallAutomation.SendDtmfResult>> SendDtmfAsync(System.Collections.Generic.IEnumerable<Azure.Communication.CallAutomation.DtmfTone> tones, Azure.Communication.CommunicationIdentifier targetParticipant, string operationContext = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual Azure.Response StartContinuousDtmfRecognition(Azure.Communication.CommunicationIdentifier targetParticipant, string operationContext = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
Expand Down Expand Up @@ -775,9 +779,10 @@ internal PlayFailed() { }
public partial class PlayOptions
{
public PlayOptions(Azure.Communication.CallAutomation.PlaySource playSource, System.Collections.Generic.IEnumerable<Azure.Communication.CommunicationIdentifier> playTo) { }
public PlayOptions(System.Collections.Generic.IEnumerable<Azure.Communication.CallAutomation.PlaySource> playSources, System.Collections.Generic.IEnumerable<Azure.Communication.CommunicationIdentifier> playTo) { }
public bool Loop { get { throw null; } set { } }
public string OperationContext { get { throw null; } set { } }
public Azure.Communication.CallAutomation.PlaySource PlaySource { get { throw null; } }
public System.Collections.Generic.IReadOnlyList<Azure.Communication.CallAutomation.PlaySource> PlaySources { get { throw null; } }
public System.Collections.Generic.IReadOnlyList<Azure.Communication.CommunicationIdentifier> PlayTo { get { throw null; } }
}
public partial class PlayResult
Expand All @@ -789,14 +794,15 @@ internal PlayResult() { }
public abstract partial class PlaySource
{
protected PlaySource() { }
public string PlaySourceId { get { throw null; } set { } }
public string PlaySourceCacheId { get { throw null; } set { } }
}
public partial class PlayToAllOptions
{
public PlayToAllOptions(Azure.Communication.CallAutomation.PlaySource playSource) { }
public PlayToAllOptions(System.Collections.Generic.IEnumerable<Azure.Communication.CallAutomation.PlaySource> playSources) { }
public bool Loop { get { throw null; } set { } }
public string OperationContext { get { throw null; } set { } }
public Azure.Communication.CallAutomation.PlaySource PlaySource { get { throw null; } }
public System.Collections.Generic.IReadOnlyList<Azure.Communication.CallAutomation.PlaySource> PlaySources { get { throw null; } }
}
public partial class RecognizeCanceled : Azure.Communication.CallAutomation.CallAutomationEventBase
{
Expand Down
130 changes: 121 additions & 9 deletions sdk/communication/Azure.Communication.CallAutomation/src/CallMedia.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,41 @@ public virtual async Task<Response<PlayResult>> PlayAsync(PlaySource playSource,
}
}

/// <summary>
/// Play list of media sources to specified participant(s) async.
/// </summary>
/// <param name="playSources"></param>
/// <param name="cancellationToken"></param>
/// <param name="playTo"></param>
/// <returns>Returns <see cref="PlayResult"/>, which can be used to wait for Play's related events.</returns>
public virtual async Task<Response<PlayResult>> PlayAsync(IEnumerable<PlaySource> playSources, IEnumerable<CommunicationIdentifier> playTo, CancellationToken cancellationToken = default)
{
using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(CallMedia)}.{nameof(Play)}");
scope.Start();
try
{
var playOptions = new PlayOptions(playSources, playTo)
{
Loop = false,
OperationContext = null
};

PlayRequestInternal request = CreatePlayRequest(playOptions);

var response = await CallMediaRestClient.PlayAsync(CallConnectionId, request, cancellationToken).ConfigureAwait(false);

var result = new PlayResult();
result.SetEventProcessor(EventProcessor, CallConnectionId, request.OperationContext);

return Response.FromValue(result, response);
}
catch (Exception ex)
{
scope.Failed(ex);
throw;
}
}

/// <summary>
/// Plays audio to specified participant(s).
/// </summary>
Expand Down Expand Up @@ -166,13 +201,48 @@ public virtual Response<PlayResult> Play(PlaySource playSource, IEnumerable<Comm
}
}

/// <summary>
/// Plays a file.
/// </summary>
/// <param name="playSources"></param>
/// <param name="cancellationToken"></param>
/// <param name="playTo"></param>
/// <returns>Returns <see cref="PlayResult"/>, which can be used to wait for Play's related events.</returns>
public virtual Response<PlayResult> Play(IEnumerable<PlaySource> playSources, IEnumerable<CommunicationIdentifier> playTo, CancellationToken cancellationToken = default)
{
using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(CallMedia)}.{nameof(Play)}");
scope.Start();
try
{
var playOptions = new PlayOptions(playSources, playTo)
{
Loop = false,
OperationContext = null
};

PlayRequestInternal request = CreatePlayRequest(playOptions);

var response = CallMediaRestClient.Play(CallConnectionId, request, cancellationToken);

var result = new PlayResult();
result.SetEventProcessor(EventProcessor, CallConnectionId, request.OperationContext);

return Response.FromValue(result, response);
}
catch (Exception ex)
{
scope.Failed(ex);
throw;
}
}

private static PlayRequestInternal CreatePlayRequest(PlayOptions options)
{
PlaySourceInternal sourceInternal = TranslatePlaySourceToInternal(options.PlaySource);
List<PlaySourceInternal> sources = options.PlaySources.Select(source => TranslatePlaySourceToInternal(source)).ToList();

if (sourceInternal != null)
if (sources != null)
{
PlayRequestInternal request = new PlayRequestInternal(sourceInternal);
PlayRequestInternal request = new PlayRequestInternal(sources);
request.PlayTo = options.PlayTo.Select(t => CommunicationIdentifierSerializer.Serialize(t)).ToList();

if (options != null)
Expand All @@ -189,7 +259,7 @@ private static PlayRequestInternal CreatePlayRequest(PlayOptions options)
return request;
}

throw new NotSupportedException(options.PlaySource.GetType().Name);
throw new NotSupportedException(options.PlaySources.GetType().Name);
}

/// <summary>
Expand All @@ -204,7 +274,7 @@ public virtual async Task<Response<PlayResult>> PlayToAllAsync(PlayToAllOptions
scope.Start();
try
{
PlayOptions playOptions = new PlayOptions(options.PlaySource, Enumerable.Empty<CommunicationIdentifier>());
PlayOptions playOptions = new PlayOptions(options.PlaySources, Enumerable.Empty<CommunicationIdentifier>());
playOptions.OperationContext = options.OperationContext;
playOptions.Loop = options.Loop;
return await PlayAsync(playOptions, cancellationToken).ConfigureAwait(false);
Expand Down Expand Up @@ -237,6 +307,27 @@ public virtual async Task<Response<PlayResult>> PlayToAllAsync(PlaySource playSo
}
}

/// <summary>
/// Play to all participants async.
/// </summary>
/// <param name="playSources"></param>
/// <param name="cancellationToken"></param>
/// <returns>Returns <see cref="PlayResult"/>, which can be used to wait for Play's related events.</returns>
public virtual async Task<Response<PlayResult>> PlayToAllAsync(IEnumerable<PlaySource> playSources, CancellationToken cancellationToken = default)
{
using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(CallMedia)}.{nameof(PlayToAll)}");
scope.Start();
try
{
return await PlayAsync(playSources, Enumerable.Empty<CommunicationIdentifier>(), cancellationToken).ConfigureAwait(false);
}
catch (Exception ex)
{
scope.Failed(ex);
throw;
}
}

/// <summary>
/// Play audio to all participants.
/// </summary>
Expand All @@ -249,7 +340,7 @@ public virtual Response<PlayResult> PlayToAll(PlayToAllOptions options, Cancella
scope.Start();
try
{
PlayOptions playOptions = new PlayOptions(options.PlaySource, Enumerable.Empty<CommunicationIdentifier>());
PlayOptions playOptions = new PlayOptions(options.PlaySources, Enumerable.Empty<CommunicationIdentifier>());
playOptions.OperationContext = options.OperationContext;
playOptions.Loop = options.Loop;
return Play(playOptions, cancellationToken);
Expand Down Expand Up @@ -282,6 +373,27 @@ public virtual Response<PlayResult> PlayToAll(PlaySource playSource, Cancellatio
}
}

/// <summary>
/// Play to all participants.
/// </summary>
/// <param name="playSources"></param>
/// <param name="cancellationToken"></param>
/// <returns>Returns <see cref="PlayResult"/>, which can be used to wait for Play's related events.</returns>
public virtual Response<PlayResult> PlayToAll(IEnumerable<PlaySource> playSources, CancellationToken cancellationToken = default)
{
using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(CallMedia)}.{nameof(PlayToAll)}");
scope.Start();
try
{
return Play(playSources, Enumerable.Empty<CommunicationIdentifier>(), cancellationToken);
}
catch (Exception ex)
{
scope.Failed(ex);
throw;
}
}

/// <summary>
/// Cancel any media operation to all participants.
/// </summary>
Expand Down Expand Up @@ -507,7 +619,7 @@ private static PlaySourceInternal TranslatePlaySourceToInternal(PlaySource playS
{
sourceInternal = new PlaySourceInternal(PlaySourceTypeInternal.File);
sourceInternal.FileSource = new FileSourceInternal(fileSource.FileUri.AbsoluteUri);
sourceInternal.PlaySourceId = fileSource.PlaySourceId;
sourceInternal.PlaySourceCacheId = fileSource.PlaySourceCacheId;
return sourceInternal;
}
else if (playSource != null && playSource is TextSource textSource)
Expand All @@ -517,14 +629,14 @@ private static PlaySourceInternal TranslatePlaySourceToInternal(PlaySource playS
sourceInternal.TextSource.SourceLocale = textSource.SourceLocale ?? null;
sourceInternal.TextSource.VoiceGender = textSource.VoiceGender ?? GenderType.Male;
sourceInternal.TextSource.VoiceName = textSource.VoiceName ?? null;
sourceInternal.PlaySourceId = textSource.PlaySourceId;
sourceInternal.PlaySourceCacheId = textSource.PlaySourceCacheId;
return sourceInternal;
}
else if (playSource != null && playSource is SsmlSource ssmlSource)
{
sourceInternal = new PlaySourceInternal(PlaySourceTypeInternal.Ssml);
sourceInternal.SsmlSource = new SsmlSourceInternal(ssmlSource.SsmlText);
sourceInternal.PlaySourceId = ssmlSource.PlaySourceId;
sourceInternal.PlaySourceCacheId = ssmlSource.PlaySourceCacheId;
return sourceInternal;
}
else
Expand Down
Loading

0 comments on commit 279909e

Please sign in to comment.