Detect Office Communicator Audio Call

778 Views Asked by At

What im trying to do is a functionality that will advice users that make audio calls in office communicator over a wireless connection to use a wired connection instead.

i have been looking around but have not been able to find the info im searching for

Im looking for a way to detect if Office Communicator is in an Audio call. is there an easy way to do this?

1

There are 1 best solutions below

1
On BEST ANSWER

I don't think you'll be able to get exactly what you need with Communicator, but you can get close. (you could probably get even closer, or all the way there, if you were to upgrade to Lync).

You'll need to use the Automation API - documentation here, download here.

First thing to try is catching the users status changes:

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

You're looking for a status of MISTATUS_ON_THE_PHONE

The downside of this is that certain statuses will override the MISTATUS_ON_THE_PHONE status. e.g. if the user is set to "Online", and then makes or receives a call, the status will change to MISTATUS_ON_THE_PHONE. But if their status is set to "Do not Disturb" and they make or receive a call, the status will NOT change to MISTATUS_ON_THE_PHONE.

You can maybe work around this a bit by examining the call as it is created. Catching a new conversation window being created is fairly straightforward:

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

Problem is, this will fire for IM and AV conversations, and also for incoming conversations as well as outgoing. There is no way to directly detect whether the call is an outgoing audio call.

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 :)