ContactPresenceChangedCallback Delegate

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.

Represents the method that is called when a contact's presence changes.

Feature:  Microsoft.Live
Namespace:  Microsoft.Live

function contactPresenceChangedCallback(cid, name, value) {



Type: String

The ID of the contact.

Type: String

The name of the property.

Type: Object

The new value of the property.

A ContactPresenceChangedCallback delegate can be specified when you use the Windows Live Messenger communication and sharing services. In this scenario, you obtain the messengerContext property from the App instance and pass the ContactPresenceChangedCallback delegate as an argument to the onContactPresenceChanged method of the IMessengerContext interface..

ContactPresenceChangedCallback monitors changes in the status of the signed-in users' contacts. Status changes can be monitored by use of the UserPresenceChangedCallback delegate. The status of a contact is represented by the values of the PresenceStatus enumeration.

The following examples demonstrate how to use the UserPresenceChangedCallback and ContactPresenceChangedCallback delegates together. Two presence status controls are shown: one for the signed-in user and one for a contact of the user. The first example shows the markup that supports the JavaScript code in the second example.

In the first example a sign in control, contact list, and presence status control are defined declaratively.

<wl:signin onsignin="onSignedInCallback"></wl:signin>
Your status:<wl:status id="PresenceControlUser" mode="both" cid="$user">
<br /> 
<span id="contactPresenceName" >[choose a contact]</span>
<wl:status id="PresenceControlContact" mode="both">
<wl:contact-list onselected="onContactSelectedCallback">
Your Status Details: <br/>
<span id="Output"></span>

In the second the code that supports the markup is shown.

var messengerContext;
var loggedInUser;
var monitoredUserCid;
function onUserPresenceChangedCallback(name, value) {
    // names and values from the Microsoft.Live.Messenger.PresenceStatus enumeration
    var displayValue = value;
    if (typeof (value) == "number") {
        displayValue = Microsoft.Live.Messenger.PresenceStatus.toString(value);
    if (name === "displayPictureUrl") {
        $get('Output').innerHTML += name + ": <img src='" + displayValue + "' alt='thumbnail' width='25px'/><br/>";
    else {
        $get('Output').innerHTML += name + ": " + displayValue + "<br/>";
function onContactPresenceChangedCallback(cid, name, value) {
    // names and values are  Microsoft.Live.Messenger.ContactPresence properties
    if (name === "Status") {
        if (cid === monitoredUserCid) {
            var name = messengerContext.findContact(cid).get_firstName();
            alert(name + ' just changed status to ' + Microsoft.Live.Messenger.PresenceStatus.toString(value) + '.');
function onSignedInCallback(signInCompletedEventArgs) {
    if (signInCompletedEventArgs.get_resultCode() !== Microsoft.Live.AsyncResultCode.success) {
        alert("sign-in failed: " + signInCompletedEventArgs.get_resultCode());
    messengerContext = Microsoft.Live.App.get_messengerContext();
    messengerContext.onSignedIn(function () {
        loggedInUser = messengerContext.get_user().get_contact().get_firstName();
// Handler wired to contact-list called when user selects contact. 
function onContactSelectedCallback(contactSelectedEventArgs) {
    monitoredUserCid = contactSelectedEventArgs.get_contact().get_cid();
    var name = messengerContext.findContact(monitoredUserCid).get_firstName();

    var presenceControl = $find('PresenceControlContact');
    $get('contactPresenceName').innerHTML = name;
    alert("You selected: " + name + "(" + monitoredUserCid + ")");

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