【问题标题】:Detect if a conversation is incoming or outgoing检测对话是传入还是传出
【发布时间】:2019-01-24 13:11:32
【问题描述】:

我使用 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 返回空值。

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

【问题讨论】:

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


【解决方案1】:

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

您需要挂钩 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 中解开。

【讨论】:

  • 对不起,我不仅想了解音频/视频,还想检查所有模态类型
  • 那么你需要挂钩所有的模态,而不仅仅是avmodality。代码基本相同。
  • 你介意再帮我一次吗,我试图设置你的代码,但似乎我不明白hastebin.com/rulizivihi.cs
  • 我现在如何在我的Conversation_Added 事件中设置布尔=?
  • 重点是,使用 lync api,直到模态状态更改回调才能判断呼叫是否传入。另外,如果您错过了活动或不记录,则无法分辨。
猜你喜欢
  • 1970-01-01
  • 2010-11-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-11-06
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多