/// <summary>
        /// Start audio video call
        /// </summary>
        /// <param name="subject"></param>
        /// <param name="to"></param>
        /// <param name="callbackUrl"></param>
        /// <returns></returns>
        private async Task <IAudioVideoInvitation> StartAudioVideoAsync(string href, string subject, string to, string callbackContext, string callbackUrl, LoggingContext loggingContext = null)
        {
            (Parent as Application).GetCallbackUrlAndCallbackContext(ref callbackUrl, ref callbackContext);

            var operationId = Guid.NewGuid().ToString();
            var tcs         = new TaskCompletionSource <IInvitation>();

            HandleNewInviteOperationKickedOff(operationId, tcs);
            IInvitation invite = null;
            var         input  = new AudioVideoInvitationInput
            {
                OperationContext = operationId,
                To              = to,
                Subject         = subject,
                CallbackContext = callbackContext,
                CallbackUrl     = callbackUrl,
                MediaHost       = MediaHostType.Remote
            };

            Uri startAudioVideoUri = UriHelper.CreateAbsoluteUri(this.BaseUri, href);

            await this.PostRelatedPlatformResourceAsync(startAudioVideoUri, input, new ResourceJsonMediaTypeFormatter(), loggingContext).ConfigureAwait(false);

            try
            {
                invite = await tcs.Task.TimeoutAfterAsync(WaitForEvents).ConfigureAwait(false);
            }
            catch (TimeoutException)
            {
                throw new RemotePlatformServiceException("Timeout to get incoming audioVideo invitation started event from platformservice!");
            }

            // We are sure that the invite is there now.
            var result = invite as AudioVideoInvitation;

            if (result == null)
            {
                throw new RemotePlatformServiceException("Platformservice do not deliver a AudioVideoInvitation resource with operationId " + operationId);
            }

            return(result);
        }
Beispiel #2
0
        /// <summary>
        /// Add AudioVideo to an already estalished conversation.
        /// </summary>
        /// <param name="loggingContext"><see cref="LoggingContext"/> to use for logging</param>
        /// <returns><see cref="AudioVideoInvitation"/> which tracks the outgoing invite.</returns>
        public override async Task <IAudioVideoInvitation> EstablishAsync(LoggingContext loggingContext = null)
        {
            string href = PlatformResource?.AddAudioVideoLink?.Href;

            if (string.IsNullOrWhiteSpace(href))
            {
                throw new CapabilityNotAvailableException("Link to establish AudioVideo is not available.");
            }

            Logger.Instance.Information("[AudioVideo] Calling AddAudioVideo. LoggingContext: {0}",
                                        loggingContext == null ? string.Empty : loggingContext.ToString());

            var conversation = base.Parent as Conversation;

            if (conversation == null)
            {
                Logger.Instance.Error("[AudioVideo] Conversation from AudioVideo base parent is null");
                throw new Exception("[AudioVideo] Failed to get Conversation from AudioVideo base parent");
            }
            var communication = conversation.Parent as Communication;

            if (communication == null)
            {
                Logger.Instance.Error("[AudioVideo] Communication from conversation base parent is null");
                throw new Exception("[AudioVideo] Failed to get communication from conversation base parent");
            }

            string operationId = Guid.NewGuid().ToString();
            var    tcs         = new TaskCompletionSource <IInvitation>();

            //Tracking the incoming invitation from communication resource
            communication.HandleNewInviteOperationKickedOff(operationId, tcs);

            IInvitation invite = null;
            var         input  = new AudioVideoInvitationInput
            {
                OperationContext = operationId,
                MediaHost        = MediaHostType.Remote
            };

            var addAudioVideoUri = UriHelper.CreateAbsoluteUri(this.BaseUri, href);

            await this.PostRelatedPlatformResourceAsync(addAudioVideoUri, input, new ResourceJsonMediaTypeFormatter(), loggingContext).ConfigureAwait(false);

            try
            {
                invite = await tcs.Task.TimeoutAfterAsync(WaitForEvents).ConfigureAwait(false);
            }
            catch (TimeoutException)
            {
                throw new RemotePlatformServiceException("Timeout to get incoming AudioVideo invitation started event from platformservice!");
            }

            //We are sure the invite sure be there now.
            var result = invite as AudioVideoInvitation;

            if (result == null)
            {
                throw new RemotePlatformServiceException("Platformservice do not deliver a AudioVideoInvitation resource with operationId " + operationId);
            }

            return(result);
        }