Invite a Participant
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.
The CreateParticipant method requires an instance of UccUri representing the remote user to invite and allows an optional Operational Context as the second parameter. The example uses the following programming pattern:
- Create an object of the UccUri type by calling ParseUri on an uri manager. Pass a SIP URI formatted string.
- Use an IUccSession object, calling CreateParticipant. Pass the new UccUri object in the first argument position. The call to the method returns an IUccSessionParticipant interface that you use to instantiate your declaration of IUccSessionParticipant.
- If the participant is created, add the participant to the active IM session.
- Register for the session participant events raised by this new participant.
- If the added participant is an Office Communicator client, the remote added participant sees an invitation to join the conversation before you call IUccInstantMessagingSession::SendMessage.
The following example invites a remote user to a peer-to-peer IM session using an active IM session and SIP-formatted URI string representing the remote user to be invited.
/// <summary>
/// Adds a participant to the current session (this._session)
/// </summary>
/// <param name="u">UccUri representing the user to be added</param>
/// <returns>true if participant was created and the client
/// succeeded in calling AddParticipant</returns>
public Boolean addParticipant(IUccSession pSession, string contactURI )
{
try
{
//create a session participant using the passed SIP uri
UccUriManager uriManager = new UccUriManagerClass();
UccUri u = uriManager.ParseUri(contactURI);
UccContext ctx = new UccContextClass();
ctx.AddNamedProperty("User", u.User);
IUccSessionParticipant p = pSession.CreateParticipant(
u,
ctx);
UccOperationContext operationContext = new UccOperationContext();
UccContext pContext = new UccContextClass();
pContext.AddNamedProperty("OpCaller", "session.AddParticipant");
operationContext.Initialize(1, pContext);
pSession.AddParticipant(p, operationContext);
return true;
}
catch (COMException ce)
{
MessageBox.Show(
"sampleUCCPClient.session on add participant: COM Exception. " +
ce.Message);
return false;
}
}
void _IUccSessionParticipantCollectionEvents.OnParticipantAdded(
IUccSession pEventSource,
IUccSessionParticipantCollectionEvent pEventData)
{
UCC_Advise<_IUccSessionParticipantEvents>(
pEventData.Participant,
this);
UCC_Advise<_IUccInstantMessagingSessionParticipantEvents>(
pEventData.Participant,
this);
}
After adding a participant to a session, a client can verify whether the session is established by checking the participant state of the remote participant. The client can do so in the event handler (OnStateChanged for the state changed events raised by the remote participant (IUccSessionParticipant object). If the session is established, the participant state changes from UCC_SESSION_ENTITY_STATE.UCCSPS_CONNECTING (OldState) to UCC_SESSION_ENTITY_STATE.UCCSPS_CONNECTED (NewState).