private void HangUpVideoCallInstance(string userId) { Contact contact = this.ContactManager.GetContactByUri(userId); if (contact == null) { return; } ConversationInfo info = this.ConversationInfos.Values.Where(convInfo => convInfo.Contact == contact).FirstOrDefault(); if (info != null) { var conversation = info.Conversation; this.ConversationInfos.Remove(conversation); info.StopVideo(); if (info.ConversationEnded != null) { info.ConversationEnded(null); } info.Dispose(); //if the conversation is active, will end it if (conversation.State != ConversationState.Terminated) { //ends the conversation which will disconnect all modalities try { conversation.End(); } catch (LyncClientException lyncClientException) { Console.WriteLine(lyncClientException); } catch (SystemException systemException) { if (Utilities.IsLyncException(systemException)) { // Log the exception thrown by the Lync Model API. Console.WriteLine("Error: " + systemException); } else { // Rethrow the SystemException which did not come from the Lync Model API. throw; } } } } }
//***************************************************************************************** // ConversationManager Event Handling // // ConversationAdded occurs when: // 1) A new conversation was created by this application // 2) A new conversation was created by another third party application or Lync itself // 2) An invite was received at this endpoint (InstantMessaging / AudioVideo) // // ConversationRemoved occurs when: // 1) A conversation is terminated // //***************************************************************************************** /// <summary> /// Called when a new conversation is added (incoming or outgoing). /// /// Will create a window for this new conversation and show it. /// </summary> void ConversationManager_ConversationAdded(object sender, ConversationManagerEventArgs e) { //***************************************************************************************** // Registering for events // // It is very important that registering for an object's events happens within the handler // of that object's added event. In another words, the application should register for the // conversation events within the ConversationAdded event handler. // // This is required to avoid timing issues which would cause the application to miss events. // While this handler method is executing, the Lync client is unable to process events for // this application (synce its thread is running this method), so no events will be lost. // // By registering for events here, we guarantee that all conversation related events will be // caught the first time they occur. // // We want to show the availability of the buttons in the conversation window based // on the ActionAvailability events. The solution below uses a lock to allow the window // to load while holding the event queue. This prevents events from being raised even // before the user interface controls get a change to load. // //***************************************************************************************** //posts the execution into the UI thread UiThreadControl.BeginInvoke(new MethodInvoker(delegate() { //shows the new window //window.Show(this); //creates a new window (which will register for Conversation and child object events) ConversationInfo info = new ConversationInfo(e.Conversation, _LyncClient, this.lastHandle, this.lastBounds, this.lastConversationEndedCallback, this.lastVideoCallStartedCallback); this.ConversationInfos.Add(e.Conversation, info); this.lastConversationEndedCallback = null; this.lastVideoCallStartedCallback = null; //conversationWindowLock.Set(); info.StartVideo(); })); //waits until the window is loaded to release the SDK thread //conversationWindowLock.WaitOne(); }
/// <summary> /// Called when a conversation is removed. /// /// Will dispose the window associated with the removed conversation. /// </summary> void ConversationManager_ConversationRemoved(object sender, ConversationManagerEventArgs e) { //posts the execution into the UI thread UiThreadControl.BeginInvoke(new MethodInvoker(delegate() { //checks if a conversation window was created, and dispose it if (this.ConversationInfos.ContainsKey(e.Conversation)) { //gets the existing conversation window ConversationInfo info = ConversationInfos[e.Conversation]; //remove the conversation from the dictionary this.ConversationInfos.Remove(e.Conversation); if (info.ConversationEnded != null) { info.ConversationEnded(null); } //cleanup info.Dispose(); } })); }