Detecting an incoming call in Lync

♀尐吖头ヾ 提交于 2019-12-10 13:43:41

问题


I'm trying to detect an incoming call in the Lync client . This is done by subscribing to ConversationManager.ConversationAdded event in the Lync client as described in this post

However, by using this method I'm not able to detect incoming calls if a conversation window with the caller is already open before the caller is calling. For instance if I'm chatting with a friend and therefore have a open conversation windows and this friend decides to call me, the ConversationAdded event is not triggered.

How would I detect incoming calls when I already have an active conversation with the caller?

Thanks, Nicklas


回答1:


You should subscribe to the ModalityStateChanged event on Conversation.Modalities[ModalityTypes.AudioVideo], this will give you events when the AV modality is created or changes state.




回答2:


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);
}


来源:https://stackoverflow.com/questions/9207549/detecting-an-incoming-call-in-lync

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!