onUserPresenceChanged Method

onUserPresenceChanged Method

Ff749503.note(en-us,MSDN.10).gifNote:
Current information about Live Connect is now available in the Windows Live Developer Center. The information in the following sections is provided for legacy purposes only.

Registers the user-presence-changed callback handler.

Script:  http://js.live.net/4.1/loader.js
Feature:  Microsoft.Live
Namespace:  Microsoft.Live
 

instance.onUserPresenceChanged(callback);

Parameters

callback
Type: Microsoft.Live..::.UserPresenceChangedCallback

The callback handler that is executed when the user's presence is changed.

The following example uses the OnUserPresenceChanged callback handler to detect when the user's status is set to away, and then sets the user's personal message to display how long the user has been gone.

//Get the messenger context while the user signs in
messengerContext = wl.App.get_messengerContext();
messengerContext.onUserPresenceChanged(onUserPresenceChanged);
var userPresence;
//Executed when the user presence is changed.
function onUserPresenceChanged(name, value)
{
    var userPresence;
    
    //If the property being changed is the user's presence status
    if (name == "status")
    {
        //And if the new presence status is away
        if (value == Microsoft.Live.Messenger.PresenceStatus.away)
        {
            //Get the current user presence value of the current user and the time of day.
            user = messengerContext.get_user();
            userPresence = user.get_presence();
            var currentTime = new Date();
            var awayDate = new String();
            var hours = currentTime.getHours();
            var minutes = currentTime.getMinutes();
            if (minutes < 10)
            {
                minutes = "0" + minutes;
            }
            if(hours > 11)
            {
                awayDate = (hours + ":" + minutes + " PM");
            } 
            else 
            {
                awayDate = (hours + ":" + minutes + " AM");
            }
            
            //Update the user's personal message to display how long they have been away.
            userPresence.set_personalMessage(user.get_displayName() + " has been away since " + awayDate);
        }
    }
}

Windows Live Messenger Connect

Supported in: 4.1

Internet Explorer 8.0, Internet Explorer 7.0, Internet Explorer 6.0, Firefox 3.6, Firefox 3.5, Firefox 3.0, Firefox 2.0, Firefox 1.5, Chrome 4.0, Chrome 3.0, Chrome 2.0, Chrome 1.0, Safari 4.0, Safari 3.0

Show:
© 2016 Microsoft