检测Office Communicator音频呼叫

时间:2011-04-20 08:32:37

标签: c# office-communicator

我想要做的是一个功能,将建议用户 通过无线连接在办公室通信器中进行音频呼叫以使用 而是有线连接。

我一直在环顾四周,但一直无法找到我正在搜索的信息

我正在寻找一种方法来检测Office Communicator是否在音频呼叫中。 是否有捷径可寻?

1 个答案:

答案 0 :(得分:2)

我不认为您能够准确地获得Communicator所需的内容,但您可以近距离接触。 (如果你要升级到Lync,你可能会更接近,或者一直到那里)。

您需要使用自动化API - 文档here,下载here

首先要尝试捕获用户状态更改:

MessengerClass _communicator;

public Form1()
{
    InitializeComponent();
    _communicator = new MessengerClass();
    _communicator.OnMyStatusChange += new DMessengerEvents_OnMyStatusChangeEventHandler(_communicator_OnMyStatusChange);
}

void _communicator_OnMyStatusChange(int hr, MISTATUS mMyStatus)
{
    AddText(string.Format("My Status changed to '{0}'", mMyStatus));
}

您正在寻找MISTATUS_ON_THE_PHONE

的状态

这样做的缺点是某些状态会覆盖MISTATUS_ON_THE_PHONE状态。例如如果用户设置为" Online",然后拨打或接听电话,状态将更改为MISTATUS_ON_THE_PHONE。但是,如果他们的状态设置为"请勿打扰"他们拨打或接听电话,状态不会改为MISTATUS_ON_THE_PHONE。

您可以通过检查创建的呼叫来解决这个问题。捕获正在创建的新对话窗口非常简单:

_communicator = new MessengerClass();
_communicator.OnIMWindowCreated += new DMessengerEvents_OnIMWindowCreatedEventHandler(_communicator_OnIMWindowCreated);

问题是,这将触发IM和AV对话,以及传入的会话和传出。无法直接检测呼叫是否是拨出的音频呼叫。

您还可以抓住"已添加联系人"事件,这将为您提供有关哪些收件人被添加到对话以及何时添加的一些信息。发生这种情况的顺序可能会为您提供有关其传出或传入的信息,您可以查找" tel:" uri被添加以告诉您呼叫是否是电话(虽然这对通信者呼叫的通信者没有帮助)

_communicator.OnIMWindowContactAdded += new DMessengerEvents_OnIMWindowContactAddedEventHandler(_communicator_OnIMWindowContactAdded);

最好的办法是玩弄事件,看看在什么情况下会发生什么。这段代码应该可以让你开始运行。

MessengerClass _communicator;

public Form1()
{
    InitializeComponent();
    _communicator = new MessengerClass();
    _communicator.OnIMWindowCreated += new DMessengerEvents_OnIMWindowCreatedEventHandler(_communicator_OnIMWindowCreated);
    _communicator.OnIMWindowDestroyed += new DMessengerEvents_OnIMWindowDestroyedEventHandler(_communicator_OnIMWindowDestroyed);
    _communicator.OnIMWindowContactAdded += new DMessengerEvents_OnIMWindowContactAddedEventHandler(_communicator_OnIMWindowContactAdded);
    _communicator.OnIMWindowContactRemoved += new DMessengerEvents_OnIMWindowContactRemovedEventHandler(_communicator_OnIMWindowContactRemoved);
    _communicator.OnMyStatusChange += new DMessengerEvents_OnMyStatusChangeEventHandler(_communicator_OnMyStatusChange);
}

void _communicator_OnMyStatusChange(int hr, MISTATUS mMyStatus)
{
    AddText(string.Format("My Status changed to '{0}'", mMyStatus));
}

void _communicator_OnIMWindowContactRemoved(object pContact, object pIMWindow)
{
    AddText(string.Format("{0}   - Participant removed - '{1}'", ((IMessengerConversationWndAdvanced)pIMWindow).HWND, ((IMessengerContactAdvanced)pContact).SigninName));
}

void _communicator_OnIMWindowContactAdded(object pContact, object pIMWindow)
{
    AddText(string.Format("{0}   - Participant added - '{1}'", ((IMessengerConversationWndAdvanced)pIMWindow).HWND, ((IMessengerContactAdvanced)pContact).SigninName));
}

void _communicator_OnIMWindowDestroyed(object pIMWindow)
{
    AddText(string.Format("{0} Conversation Closed, duration = {1}", ((IMessengerConversationWndAdvanced)pIMWindow).HWND, (DateTime.Now - _start).ToString()));
}

void _communicator_OnIMWindowCreated(object pIMWindow)
{
    try
    {
        AddText(string.Format("{0} Conversation Created", ((IMessengerConversationWndAdvanced)pIMWindow).HWND));
    }
    catch (Exception ex)
    {
        MessageBox.Show(ex.ToString());
    }
}

private delegate void AddTextDelegate(string text);

private void AddText(string text)
{
    if (textBox1.InvokeRequired)
    {
        textBox1.Invoke(new AddTextDelegate(AddText), text);
        return;
    }
    textBox1.Text += text + "\r\n";
}

顺便说一句,如果您觉得它有帮助,请不要忘记接受这个作为答案,使用" tick&#34 ;.