简体   繁体   English

检测对话是传入还是传出

[英]Detect if a conversation is incoming or outgoing

I use the Lync SDK 2013 and try to check if a new conversation is incoming or outgoing. 我使用Lync SDK 2013,并尝试检查是否有新的对话传入或传出。 I don't want to check for audio/video calls only, I want to check in on each modality type. 我不想只检查音频/视频呼叫,我想检查每种方式类型。

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

When the event gets triggered and it comes to the Any method I get this error 当事件被触发并涉及Any方法时,出现此错误

NullReferenceException object reference not set to an instance of an object. NullReferenceException对象引用未设置为对象的实例。 System.Collections.Generic.KeyValuePair.Value.get returned null. System.Collections.Generic.KeyValuePair.Value.get返回null。

So obviously I have to use a null check here but maybe the whole code may be wrong? 因此,显然我必须在此处使用null检查,但也许整个代码可能是错误的? How can I check if the conversation is incoming or outgoing? 如何检查对话是传入还是传出?

Your idea is basically correct but when you check for the notified state is incorrect. 您的想法基本上是正确的,但是当您检查通知的状态时是不正确的。

You need to hook the ModalityStateChanged event, and if you only want to know about audio/video "Calls" then you also only need to hook for conversations that have AudioVideo modality type. 您需要挂接ModalityStateChanged事件,并且如果您只想了解音频/视频“呼叫”,则还需要挂接具有AudioVideo模态类型的对话。

eg 例如

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

Don't forget to unhook from the ModalityStateChanged when you don't need to know the state change any longer. 当您不再需要了解状态更改时,请不要忘记从ModalityStateChanged中脱钩。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM