次の方法で共有


How to make calls via Office Communicator SDK

Starting Office Communicator calls from your code is one of the simplest and most powerful features you can add to your application using the Office Communicator Automation API. 

This video shows some examples of the types of calls you can start in your code:

Let’s dive into the code.  When making calls via the Office Communicator Automation API you call the IMessengerAdvanced.StartConversation() method and specify the participants, the media type (IM, audio, video) and any call specific information (such as the conversation window title).  You get a reference to the IMessengerAdvanced interface by casting an instance of Messenger class.

For example, the following console application code starts an IM call with a single contact (kf@fabrikam.com) and sets the title of the conversation window to “My IM Call”:

    1:  using System;
    2:  using System.Collections.Generic;
    3:  using System.Linq;
    4:  using System.Text;
    5:   
    6:  using CommunicatorAPI;
    7:  using System.Runtime.InteropServices;
    8:   
    9:  namespace StartConversation
   10:  {
   11:      class Program
   12:      {
   13:          private static Messenger _messenger;
   14:          private static IMessengerAdvanced _messengerAdv;
   15:   
   16:          static void Main(string[] args)
   17:          {
   18:              _messenger = new Messenger();
   19:              _messengerAdv = (IMessengerAdvanced)_messenger;
   20:   
   21:              object[] sipUris = new object[] { "kf@fabrikam.com" };
   22:   
   23:              _messengerAdv.StartConversation(
   24:                  // The call media.            
   25:                  CONVERSATION_TYPE.CONVERSATION_TYPE_IM,
   26:                  // The participants.
   27:                  sipUris,
   28:                  // Not supported.
   29:                  null,
   30:                  // The conversation window title as as string.
   31:                  "My IM Call",
   32:                  // Not supported.  Pass "1".
   33:                  "1",
   34:                  // Not supported.
   35:                  null);
   36:   
   37:              Console.WriteLine("Press the Enter key to exit the application.");
   38:              Console.ReadLine();
   39:   
   40:              Marshal.ReleaseComObject(_messenger);
   41:              _messenger = null;
   42:              Marshal.ReleaseComObject(_messengerAdv);
   43:              _messengerAdv = null;
   44:          }
   45:      }
   46:  }

Changing the call media is just a matter of passing a different value from the CONVERSATION_TYPE enum.  For example, the follow code starts an audio call:

    1:              _messengerAdv.StartConversation(
    2:                  // The call media.            
    3:                  CONVERSATION_TYPE.CONVERSATION_TYPE_AUDIO,
    4:                  // The participants.
    5:                  sipUris,
    6:                  // Not supported.
    7:                  null,
    8:                  // The conversation window title as as string.
    9:                  "My Audio Call",
   10:                  // Not supported.  Pass "1".
   11:                  "1",
   12:                  // Not supported.
   13:                  null);

Starting a conference is just a matter of starting a call with multiple participants.  For example, the following code starts a video conference:

    1:              object[] sipUris = new object[] { "kf@fabrikam.com", "cb@fabrikam.com" };
    2:   
    3:              _messengerAdv.StartConversation(
    4:                  // The call media.            
    5:                  CONVERSATION_TYPE.CONVERSATION_TYPE_VIDEO,
    6:                  // The participants.
    7:                  sipUris,
    8:                  // Not supported.
    9:                  null,
   10:                  // The conversation window title as as string.
   11:                  "My Video Conference",
   12:                  // Not supported.  Pass "1".
   13:                  "1",
   14:                  // Not supported.
   15:                  null);

If you’d like to try this code out for yourself, you’ll need to download the Office Communicator 2007 SDK and setup a UC development environment.

More details, tips and tricks on UC development can be found in the Programming for Unified Communications book.

Thanks,

Chris