Exemple #1
0
        /// <summary> Play audio in the call. </summary>
        /// <param name="conversationId"> The conversation id that can be a group id or a encoded conversation url retrieve from client. </param>
        /// <param name="options"> Play audio request. </param>
        /// <param name="cancellationToken"> The cancellation token. </param>
        /// <exception cref="RequestFailedException">The server returned an error. See <see cref="Exception.Message"/> for details returned from the server.</exception>
        /// <exception cref="ArgumentNullException"> <paramref name="options"/> is null. </exception>
        public virtual Response <PlayAudioResponse> PlayAudio(string conversationId, PlayAudioOptions options, CancellationToken cancellationToken = default)
        {
            using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(ConversationClient)}.{nameof(PlayAudio)}");
            scope.Start();
            try
            {
                Argument.AssertNotNull(options, nameof(options));

                // Currently looping media is not supported for out-call scenarios, thus setting it to false.
                return(RestClient.PlayAudio(
                           conversationId: conversationId,
                           audioFileUri: options.AudioFileUri?.AbsoluteUri,
                           loop: false,
                           audioFileId: options.AudioFileId,
                           callbackUri: options.CallbackUri?.AbsoluteUri,
                           operationContext: options.OperationContext,
                           cancellationToken: cancellationToken
                           ));
            }
            catch (Exception ex)
            {
                scope.Failed(ex);
                throw;
            }
        }
Exemple #2
0
        /// <summary> Play audio in the call. </summary>
        /// <param name="callLegId"> The call leg id. </param>
        /// <param name="options"> Play audio request. </param>
        /// <param name="cancellationToken"> The cancellation token. </param>
        /// <exception cref="RequestFailedException">The server returned an error. See <see cref="Exception.Message"/> for details returned from the server.</exception>
        /// <exception cref="ArgumentNullException"> <paramref name="options"/> is null. </exception>
        public virtual Response <PlayAudioResponse> PlayAudio(string callLegId, PlayAudioOptions options, CancellationToken cancellationToken = default)
        {
            using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(CallClient)}.{nameof(PlayAudio)}");
            scope.Start();
            try
            {
                Argument.AssertNotNull(options, nameof(options));

                return(RestClient.PlayAudio(
                           callId: callLegId,
                           audioFileUri: options.AudioFileUri?.AbsoluteUri,
                           loop: options.Loop,
                           audioFileId: options.AudioFileId,
                           callbackUri: options.CallbackUri?.AbsoluteUri,
                           operationContext: options.OperationContext,
                           cancellationToken: cancellationToken
                           ));
            }
            catch (Exception ex)
            {
                scope.Failed(ex);
                throw;
            }
        }
        /// <summary> Play audio in the call. </summary>
        /// <param name="options"> Play audio request. </param>
        /// <param name="cancellationToken"> The cancellation token. </param>
        /// <exception cref="RequestFailedException">The server returned an error. See <see cref="Exception.Message"/> for details returned from the server.</exception>
        /// <exception cref="ArgumentNullException"> <paramref name="options"/> is null. </exception>
        public virtual async Task <Response <PlayAudioResult> > PlayAudioAsync(PlayAudioOptions options, CancellationToken cancellationToken = default)
        {
            using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(CallConnection)}.{nameof(PlayAudio)}");
            scope.Start();
            try
            {
                Argument.AssertNotNull(options, nameof(options));

                return(await RestClient.PlayAudioAsync(
                           callConnectionId : CallConnectionId,
                           audioFileUri : options.AudioFileUri?.AbsoluteUri,
                           loop : options.Loop,
                           audioFileId : options.AudioFileId,
                           callbackUri : options.CallbackUri?.AbsoluteUri,
                           operationContext : options.OperationContext,
                           cancellationToken : cancellationToken
                           ).ConfigureAwait(false));
            }
            catch (Exception ex)
            {
                scope.Failed(ex);
                throw;
            }
        }