Share via


Join a Lync 2010 Conference

Use this code example to learn how to join a Microsoft Lync 2010 conference.

Note

The following code examples run on multiple computers. The first computer is used to start a conference by using Microsoft Lync 2010 SDK UI Automation, and the other computers are used to join the conference that started on the first computer.

Starting the Conference

The first computer starts the conference by calling into the BeginStartConversation method and obtaining a new ConversationWindow instance by calling into the EndStartConversation method. The Conversation property returns the Conversation instance used in the following example.

// Create the major API automation object.
Automation _Automation = LyncClient.GetAutomation();


// Create a generic List object to contain a contact URI and be sure a valid URI is added.
List<string> inviteeList = new List<string>();
inviteeList.Add("elise@contoso.com");
inviteeList.Add("sam@contoso.com");


// Create a generic Dictionary object to contain conversation setting objects.
Dictionary<AutomationModalitySettings, object> _ModalitySettings = new Dictionary<AutomationModalitySettings, object>();
AutomationModalities _ChosenMode = AutomationModalities.InstantMessage;

_ModalitySettings.Add(AutomationModalitySettings.FirstInstantMessage, "Weekly project status meeting starts now");
_ModalitySettings.Add(AutomationModalitySettings.SendFirstInstantMessageImmediately, true);

// Start the conversation.
IAsyncResult ar = _Automation.BeginStartConversation(
    _ChosenMode
    , invitees
    , _ModalitySettings
    , null
    , null);

// Block UI thread until conversation is started.
ConversationWindow conferenceWindow = _Automation.EndStartConversation(ar);
Conversation conferenceConversationObject = conferenceWindow.Conversation;

// Register for the property changed event to get notification when the 
// ConferenceUri property has been filled.
conferenceConversationObject.PropertyChanged += Conversation_PropertyChanged;

The conference URI obtained in the previous example must be passed to users on other computers to allow them to join the new conference. The transfer method is out of scope for this discussion but can include email.

Getting the Conference URI

The conversation properties that you use to form a complete conference URI are null at the time that the conversation is created. To get the conference URI properties, you register for the Conversation.PropertyChanged event on the conversation. In the PropertyChanged event handler that is raised when any kind of conversation property is changed, you compare the ConversationPropertyChangedEventArgs.Property to Microsoft.Lync.Model.Conversation.ConversationProperty.ConferencingUri. If the values match then the property whose value has changed is the conference URI. The following example shows how to build the conference URI join string.

The following example builds a conference join URL using properties of the conversation.

        /// <summary>
        /// Handles the event that is raised when a property of a conversation has changed
        /// </summary>
        /// <param name="sender">object. The Conversation whose property has changed.</param>
        /// <param name="e">ConversationPropertyChangedEventArgs. The state of the event</param>
        void Conversation_PropertyChanged(object sender, ConversationPropertyChangedEventArgs e)
        {
            if (e.Property == ConversationProperty.ConferencingUri)
            { 
                string ConferenceUri = "conf:" 
                    + ((Conversation)sender).Properties[ConversationProperty.ConferencingUri]
                    + "?" + ((Conversation)sender).Properties[ConversationProperty.Id];
            }
        }

Joining the Conference

Elise and Sam are invited to the conference explicitly because they were added to the invitee list when the conference was started. These two users receive conversation invitations through Microsoft Lync 2010. Other users who should attend the meeting must get the conference URI and then join the conference using the URI.

Once the conference URI is obtained by another user, use the BeginStartConversation method to join a conference in a Microsoft Lync 2010 SDK application. The string argument of the call is the conference URI.

Important

The UI thread of this sample is blocked until the user joins the conference. The call into EndStartConversation immediately follows BeginStartConversation, but does not return until the conference is joined. If you do not want to block your UI thread while the joining operation is in progress, pass a callback method into BeginStartConversation and then call EndStartConversation inside the passed callback method.

IAsyncResult ar = LyncClient.GetAutomation().BeginStartConversation(
    this.ConferenceUriObtainedFromEmail_string
    , this.Handle.ToInt32()
    , null
    , null);

_Automation.EndStartConversation(ar);

See Also

Concepts

Lync Extensibility Classes

Other Resources

Lync Extensibility API Concepts (Lync 2010 SDK)