【问题标题】:Detect Office Communicator Audio Call检测 Office Communicator 音频呼叫
【发布时间】:2011-04-20 17:56:33
【问题描述】:

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

我一直在四处寻找,但无法找到我正在搜索的信息

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

【问题讨论】:

    标签: c# office-communicator


    【解决方案1】:

    我认为您无法通过 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 状态。例如如果用户设置为“在线”,然后拨打或接听电话,状态将更改为 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";
    }
    

    顺便说一句,如果您觉得它有帮助,请不要忘记使用“勾号”作为答案:)

    【讨论】:

    • 您的回答确实给了我很多可以使用的信息,希望能引导我到达那里。我真的不在乎电话是打出来的还是打进来的。
    猜你喜欢
    • 2021-12-31
    • 1970-01-01
    • 2014-05-29
    • 2016-04-06
    • 1970-01-01
    • 2021-02-09
    • 2023-03-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多