You need to monitor the states of the modalities on the conversation. The two avaiable modalities are IM and AV, so you'll need to watch for state changes on these, like so:
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 sample is using the ConversationAdded event to wire up the event handlers for modality changes, so this will only work for conversations that are started while your application is running. To do the same for conversations that are already active before your application starts, you could add this code to your application's startup routine:
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);
}