private void EstablishCall() { // Create a new Conversation. Conversation conversation = new Conversation(_appEndpoint); // Create a new IM call. _imCall = new InstantMessagingCall(conversation); try { // Establish the IM call. _imCall.BeginEstablish(_destinationSipUri, new CallEstablishOptions(), result => { try { // Finish the asynchronous operation. _imCall.EndEstablish(result); } catch (RealTimeException ex) { // Catch and log exceptions. _logger.Log("Failed establishing IM call", ex); } }, null ); } catch (InvalidOperationException ioex) { _logger.Log("Failed establishing IM call", ioex); } }
void IMCall_EstablishCompleted(IAsyncResult result) { try { InstantMessagingCall imCall = result.AsyncState as InstantMessagingCall; imCall.EndEstablish(result); Message m = new Message("InstantMessagingCall Established. Call state: " + _instantMessagingCall.State.ToString() + ". CallId: " + _instantMessagingCall.CallId + ".", _instantMessagingCall.RemoteEndpoint.Participant.DisplayName, _instantMessagingCall.RemoteEndpoint.Participant.UserAtHost, _instantMessagingCall.RemoteEndpoint.Participant.Uri, MessageType.InstantMessage, _transcriptRecorder.Conversation.Id, MessageDirection.Incoming); _transcriptRecorder.OnMessageReceived(m); _transcriptRecorder.OnRemoteParticipantAdded(null, imCall.RemoteEndpoint); } catch (RealTimeException ex) { NonBlockingConsole.WriteLine("Error: imCall.EndEstablish failed. Exception: {0}", ex.ToString()); // TODO: error message } finally { _state = TranscriptRecorderState.Active; this._waitForIMCallEstablished.Set(); } }
/// <summary> /// Im call establish completed callback method. /// </summary> /// <param name="asyncResult">Async result.</param> private void InstantMessagingCallEstablishCompleted(IAsyncResult asyncResult) { Exception exceptionCaught = null; bool exceptionEncountered = true; try { m_imCall.EndEstablish(asyncResult); exceptionEncountered = false; } catch (RealTimeException rte) { Helper.Logger.Info("Exception = {0}", EventLogger.ToString(rte)); exceptionCaught = rte; } finally { if (exceptionEncountered) { OperationFault operationFault = null; if (exceptionCaught != null) { operationFault = FaultHelper.CreateClientOperationFault(exceptionCaught.Message, exceptionCaught.InnerException); } else { operationFault = FaultHelper.CreateServerOperationFault(FailureStrings.GenericFailures.UnexpectedException, null /*innerException*/); } this.CompleteEstablishOperationWithException(new FaultException <OperationFault>(operationFault)); } else { InstantMessagingCallContext imCallContext = m_imCall.ApplicationContext as InstantMessagingCallContext; Debug.Assert(null != imCallContext, "Im call context is null"); Debug.Assert(null != imCallContext.WebImcall, "Im call in Imcall context is null"); //Stamp im call. m_webConversation.WebImCall = imCallContext.WebImcall; EstablishInstantMessagingCallResponse response = new EstablishInstantMessagingCallResponse(m_establishImCallRequest, imCallContext.WebImcall); this.CompleteEstablishOperationSuccessfully(response); } } }
private void EstablishCall() { // Create a new Conversation. Conversation conversation = new Conversation(_appEndpoint); // Create a new IM call. _imCall = new InstantMessagingCall(conversation); try { // Establish the IM call. _imCall.BeginEstablish(_destinationSipUri, new CallEstablishOptions(), result => { try { // Finish the asynchronous operation. _imCall.EndEstablish(result); _imCall.Flow.MessageReceived += new EventHandler<InstantMessageReceivedEventArgs>(OnMessageReceived); SendMessage("Jackdaws love my big sphinx of quartz."); } catch (RealTimeException ex) { // Catch and log exceptions. _logger.Log("Failed establishing IM call", ex); } }, null ); } catch (InvalidOperationException ioex) { _logger.Log("Failed establishing IM call", ioex); } }
private void CallEstablishCompleted(IAsyncResult result) { InstantMessagingCall instantMessagingCall = result.AsyncState as InstantMessagingCall; Exception ex = null; try { instantMessagingCall.EndEstablish(result); Console.WriteLine("The call is now in the established state."); } catch (OperationFailureException opFailEx) { // OperationFailureException: Indicates failure to connect the // call to the remote party. // TODO (Left to the reader): Write real error handling code. ex = opFailEx; } catch (RealTimeException rte) { // Other errors may cause other RealTimeExceptions to be thrown. // TODO (Left to the reader): Write real error handling code. ex = rte; } finally { if (ex != null) { // If the action threw an exception, terminate the sample, // and print the exception to the console. // TODO (Left to the reader): Write real error handling code. Console.WriteLine(ex.ToString()); Console.WriteLine("Shutting down platform due to error"); _helper.ShutdownPlatform(); } } }
//Callback method for the InstantMessagingCall.BeginEstablish method. private void CallEstablishCompleted(IAsyncResult res) { ImCall.EndEstablish(res); }