Click to Rate and Give Feedback
MSDN
MSDN Library
Online Services
Live Services SDK
User Class
User Properties
 OnlineContacts Property
Collapse All/Expand All Collapse All
Windows Live Messenger Web Toolkit Class Reference
User..::.OnlineContacts Property

Gets the SortedContactCollection containing all contacts that are currently online.

Script:  http://www.wlmessenger.net/api/3.5/loader.js
Feature:  Messenger.Core
Namespace:  Microsoft.Live.Messenger
 
JavaScript
// To retrieve:
var onlineContacts = instance.get_onlineContacts();
C# (Script#)
public SortedContactCollection OnlineContacts { get; }
When a contact's status changes from offline to online, or vice-versa, the CollectionChanged event is fired for both OnlineContacts and OfflineContacts collections to indicate that changes have occurred within each respective collection. You can subscribe to these events to track the online/offline status of users. When a contact changes from being online to offline (or vice versa), there can be slight delays where the status of the contact does not match the collection it is in. For example, when an online contact becomes offline, there may be a short interval during which reading the status of the contact shows offline and the contact remains in the online collection. Use the OnlineContacts and OfflineContacts collections to display the users contact lists in your application. Note that these collections are sorted.
The following example demonstrates how to maintain a separate contacts structure that remains in sync with a ContactCollection.
JavaScript
            var user = null;
            var onlineContacts = [];
            var offlineContacts = [];
            
            // Handle authentication - sign the user in.
            function onAuthCompleted(sender, e) {
                user = new Microsoft.Live.Messenger.User(e.get_identity());
                user.get_onlineContacts().add_collectionChanged(onOnlineContactsChanged);
                user.get_offlineContacts().add_collectionChanged(onOfflineContactsChanged);
                user.signIn();
            }
            
            // Responsible for updating the onlineContacts array to match
            // the User.OnlineContacts collection.
            function onOnlineContactsChanged(sender, e) {
                switch (e.get_action()) {
                    case Microsoft.Live.Messenger.NotifyCollectionChangedAction.add:
                        onlineContacts.splice(e.get_newStartingIndex(), 0, e.get_newItems());
                        break;
            
                    case Microsoft.Live.Messenger.NotifyCollectionChangedAction.remove:
                        onlineContacts.splice(e.get_oldStartingIndex(), e.get_oldItems().length);
                        break;
            
                    case Microsoft.Live.Messenger.NotifyCollectionChangedAction.reset:
                        onlineContacts = new Array(sender.get_count());
            
                        for (var i = 0; i < sender.get_count(); i++) {
                            onlineContacts[i] = sender.get_item(i);
                        }
                        break;
                }
            } 
            
            // Responsible for updating the offlineContacts array to match
            // the User.OfflineContacts collection.
            function onOfflineContactsChanged(sender, e) {
                switch (e.get_action()) {
                    case Microsoft.Live.Messenger.NotifyCollectionChangedAction.add:
                        offlineContacts.splice(e.get_newStartingIndex(), 0, e.get_newItems());
                        break;
            
                    case Microsoft.Live.Messenger.NotifyCollectionChangedAction.remove:
                        offlineContacts.splice(e.get_oldStartingIndex(), e.get_oldItems().length);
                        break;
            
                    case Microsoft.Live.Messenger.NotifyCollectionChangedAction.reset:
                        offlineContacts = new Array(sender.get_count());
            
                        for (var i = 0; i < sender.get_count(); i++) {
                            offlineContacts[i] = sender.get_item(i);
                        }
                        break;
                }
            } 
            

Windows Live Messenger Web Toolkit

Supported in: 3.5, 3.1, 3.0, 2.5, 2.0

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

© 2009 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks | Privacy Statement | Site Feedback
Page view tracker