You need to track the modality states in the conversation. The two available modalities are IM and AV, so you will need to monitor the state changes on them, for example:
void ConversationManager_ConversationAdded(object sender, Microsoft.Lync.Model.Conversation.ConversationManagerEventArgs e) { e.Conversation.Modalities[ModalityTypes.InstantMessage].ModalityStateChanged += IMModalityStateChanged; e.Conversation.Modalities[ModalityTypes.AudioVideo].ModalityStateChanged += AVModalityStateChanged; } void IMModalityStateChanged(object sender, ModalityStateChangedEventArgs e) { if (e.NewState == ModalityState.Connected) MessageBox.Show("IM Modality Connected"); } void AVModalityStateChanged(object sender, ModalityStateChangedEventArgs e) { if (e.NewState == ModalityState.Connected) MessageBox.Show("AV Modality Connected"); }
This example uses the ConversationAdded event to connect event handlers to modality changes, so this will only work for conversations that are fired while your application is running. To do the same for conversations that are already active prior to launching your application, you can add this code to your application launcher:
foreach (var conv in _lync.ConversationManager.Conversations) { conv.Modalities[ModalityTypes.InstantMessage].ModalityStateChanged += new EventHandler<ModalityStateChangedEventArgs>(IMModalityStateChanged); conv.Modalities[ModalityTypes.AudioVideo].ModalityStateChanged += new EventHandler<ModalityStateChangedEventArgs>(AVModalityStateChanged); }
source share