Bridge Communications

Monday, January 19, 2015

Using Lync enhanced presence.

Today I am going to talk about enhanced presence.  For the sake of this article I am going to assume you understand how to establish a UCMA endpoint.   Ok let's dive in, what is enhanced presence?  Good question, to start let's look at the Lync presence states.













Most Lync users are familiar with these, and for the most part they convey a given user's status.  There are times however it is nice to differentiate between "Busy" eating and "Busy" performing brain surgery.











Yes you can manipulate some of this on the server, but you can have only 4 "other" custom type status indicators.  So let's say we want the front desk staff to be able to mark people out as sick, or change the status of other workers at their request, what do we do?  Fortunately the good folks at Microsoft wrote a great backend engine we can leverage to fill in all the gaps.

In our case we wrote a listening socket on the backend and passed it commands from our attendant console (shameless plug here http://www.bridgeoc.com/lync)  Then we published that presence for a given use using a copy of that user via a user endpoint.  It sounds more complicated than it is, essentially we logged in as them using the application endpoint our UCMA app already had running.

            UserEndpointSettings _userEnpointSettings = new UserEndpointSettings(myuri);
            _userEnpointSettings.AutomaticPresencePublicationEnabled = true;
            
            UserEndpoint _userEndpoint = new UserEndpoint(_collaborationPlatform, _userEnpointSettings);

From there we establish the endpoint, and hang out until it completes.

 _userEndpoint.BeginEstablish(myar =>
                {
                    try
                    {
                        _userEndpoint.EndEstablish(myar);
                        _logger.Log("End Point Established");
                        _logger.Log(_userEndpoint.LocalOwnerPresence.CurrentState.ToString());
                      

                    }
                    catch { }

                }, null);

                int x = 0;

                while (_userEndpoint.State != LocalEndpointState.Established)
                {
                    Thread.Sleep(100);
                    x++;

                    if (x > 500)
                    {
                        break;
                    }
                }


Once we have an established endpoint we simply publish the "State" and the "Words" we want to associate in the enhanced presence part.

PresenceState mypres = new PresenceState(PresenceStateType.UserState, (int)ps.Availability, new PresenceActivity(new LocalizedString(words)));
                mypres.SetExpiryTime(300);
                
                _userEndpoint.PresenceServices.BeginUpdatePresenceState(mypres, ar =>
                {
                    try
                    {
                        _userEndpoint.PresenceServices.EndUpdatePresenceState(ar);
                        _logger.Log("Presence Published - " + ps.Availability.ToString());
                    }
                    catch (Exception ex)
                    {
                        _logger.Log(ex.Message.ToString());
                    }

                
                },null);


That's it, now we can tell the world in more detail what we or others are up to.

As always have a great week, and thanks for checking out our blog.

Doug Routledge, C# Lync, SQL, Exchange, UC Developer

No comments:

Post a Comment

Any spam comments will be deleted and your user account will be disabled.