1

我试图做的是一个功能,它会建议通过无线连接在办公室通信器中进行音频呼叫的用户改用有线连接。

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

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

4

1 回答 1

2

我认为您无法通过 Communicator 获得所需的确切信息,但您可以接近。(如果您要升级到 Lync,您可能会更接近或一直到那里)。

您需要在此处使用自动化 API 文档,此处下载。

首先要尝试的是捕捉用户状态变化:

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 状态。例如,如果用户设置为“在线”,然后拨打或接听电话,则状态将更改为 MISTATUS_ON_THE_PHONE。但是,如果他们的状态设置为“请勿打扰”并且他们拨打或接听电话,则状态不会更改为 MISTATUS_ON_THE_PHONE。

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

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

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

You can also catch the "Contact Added" event, this will give you some info about which recipients get added to the conversation, and when. It's possible that the order in which this happens will give you some info as to whether its outgoing or incoming, and you could look for "tel:" uri's being added to tell you if the call is to a phone (although this won't help for communicator to communicator calls)

_communicator.OnIMWindowContactAdded += new DMessengerEvents_OnIMWindowContactAddedEventHandler(_communicator_OnIMWindowContactAdded);

The best thing to do is to have a play around with the events, and see what happens under which circumstances. This code should get you up and running with that.

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

By the way, don't forget to accept this as the answer using the "tick", if you feel that it helped :)

于 2011-04-20T09:56:33.170 回答