Leave a Conference

This content is no longer actively maintained. It is provided as is, for anyone who may still be using these technologies, with no warranties or claims of accuracy with regard to the most recent product version or service release.

When the local participant chooses to leave a conference, a Unified Communications Client API application calls the Leave method on the active conference session. Because a conference can hold other communications sessions, the application must also make sure to close any of these sessions that are still active. The application must close all the contained communications session before attempting to leave the conference.

The application can check the operational status after calling the Leave method by implementing the OnLeave. It should also register for the _IUccConferenceSessionEvents when the conference session object is first created. A code example for handling this event is also shown below.

OnLeave is raised on a local client when any of the three following conditions are met

  • The conference administrator has removed the local participant from a conference.
  • The conference has been terminated. In this case, all conference participants receive the OnLeave event.
  • The local user has chosen to leave the conference with a call into Leave on the conference session object.

The following example cleans up a conference session by terminating all active conference media sessions and leaves the conference.

public partial class Conference
{

    /// <summary>
    /// Cleans up if application was closed without leaving the conference
    /// </summary>
    public void cleanup()
    {
        if (this.conferenceSessionState == State.Connected)
        {                
            this.DisconnectMediaAndExit();
        }
    }


    /// <summary>
    /// Leave the Room i.e. terminate the media session and leave the conferencing session.
    /// </summary>
    public void DisconnectMediaAndExit()
    {
        try
        {
            if (this.mediaSessionState == State.Connected && this.mediaSession != null)
            {
                // Terminate the media session
                this.mediaSession.Terminate(UCC_REJECT_OR_TERMINATE_REASON.UCCTR_NORMAL, null);
            }
            if (this.conferenceSessionState == State.Connected && this.conferenceSession != null)
            {
                // Leave the conference. Note that Leave is used here and not Terminate 
                // as Terminate ends the conferencing session for everyone                    

                this.conferenceSession.Leave(null);
            }
        }
        catch (COMException ex)
        {
            MessageBox.Show("COM Exception: " + ex.Message);
        }
    }
}

The following C# code snippet illustrates event handling for the OnLeave event.

public partial class Conference : _IUccConferenceSessionEvents
{
    /// <summary>
    /// Event fired when Leave operation is completed.
    /// </summary>
    /// <param name="pEventSource">Conference Session</param>
    /// <param name="pEventData">Containes information about operation's status (success/failure) </param>
    void _IUccConferenceSessionEvents.OnLeave(
        UccConferenceSession pEventSource,
        IUccOperationProgressEvent pEventData
        )
    {
        // Leave succeeded, set conference session state to Idle and clean up
        if (pEventData.StatusCode >= 0)
        {
            if (thisSession.Participants.Count <= 1)
            {
               this.conferenceSession = null;
            }
            else
            {
                IUccSession thisSession = pEventSource as IUccSession;
                foreach (IUccSessionParticipant p in thisSession.Participants)
                {
                    MessageBox.Show(p.Uri.User + " is still in conference");
                }
            }

        }
        else
        {
            //Leave failed, conference is still connected
            MessageBox.Show("Leave conference failed: " + pEventData.StatusCode.ToString() + pEventData.StatusText);
        }
    }
}

See Also

Concepts

Join a Conference Session
Obtain Conference Media
List Conference Participants
List Conference Participants
Leave a Conference