I'm publishing a user presence in a Trusted Application Endpoint, but I also would like to clear this presence when it is no longer needed.
Is the only option to do so to terminate the UserEndpoint instance?
I'm using this code snippet:
user.Endpoint.LocalOwnerPresence.BeginPublishPresence(
user.categories,
arBeginPublishPresence =>
{
try
{
user.Endpoint.PresenceServices.EndUpdatePresenceState(arBeginPublishPresence);
logger.log("Published presence for {0} with state {1}.", user.SipUserUri, newState.Availability);
}
catch (RealTimeException ex)
{
logger.log("Failed publishing presence for {0}. {1}", user.SipUserUri, ex);
}
},
null);
where user.Endpoint is the UserEndpoint for that user, and user.categories are the list of PresenceCategoryWithMetaData objects.
First - I'm amazed this actually works! you're calling BeginPublishPresence on the LocalOwnerPresence object, and then in the aysnc callback calling EndUpdatePresenceState on the PresenceServices object. Please tell me this is a typo, otherwise i'm going to have to throw out everything I thought I knew about Lync development and async programming ;o)
Anyway - assuming you're publishing presence with
LocalOwnerPresence.BeginPublishPresence
(and calling the corresponding EndPublishPresence in the async callback), you can call
LocalOwnerPresence.BeginDeletePresence
to delete the publication.