首页 > 解决方案 > 检测对话是传入还是传出

问题描述

我使用 Lync SDK 2013 并尝试检查新对话是传入还是传出。我不想只检查音频/视频通话,我想检查每种模式类型。

private void Conversation_Added(object sender, ConversationManagerEventArgs e)
{
    Conversation conversation = e.Conversation;
    IDictionary<ModalityTypes, Modality> modalities = conversation.Modalities;
    bool conversationIsIncoming = modalities.Any(modality => modality.Value.State == ModalityState.Notified);
}

当事件被触发并且涉及到Any我得到这个错误的方法时

NullReferenceException对象引用未设置为对象的实例。System.Collections.Generic.KeyValuePair.Value.get 返回 null。

所以很明显我必须在这里使用空检查,但也许整个代码可能是错误的?如何检查对话是传入还是传出?

标签: c#lyncskypedeveloperlync-2013lync-client-sdk

解决方案


您的想法基本上是正确的,但是当您检查通知状态时是不正确的。

您需要挂钩 ModalityStateChanged 事件,如果您只想了解音频/视频“通话”,那么您也只需要挂钩具有 AudioVideo 模态类型的对话。

例如

private void ConversationManager_ConversationAdded(object sender, ConversationManagerEventArgs e)
{
    if (e.Conversation.Modalities.TryGetValue(ModalityTypes.AudioVideo, out var avModality))
    {
        avModality.ModalityStateChanged += AvModalityOnStateChanged;
    }
}

private void AvModalityOnStateChanged(object sender, ModalityStateChangedEventArgs e)
{
    if (e.NewState == ModalityState.Notified)
    {
        bool conversationIsIncoming = true;
    }
}

当您不再需要知道状态更改时,不要忘记从 ModalityStateChanged 中解脱。


推荐阅读