Esempio n. 1
0
        /// <summary>
        /// Gets the presence of the given user.
        /// </summary>
        /// <param name="targetJid">User JID</param>
        public void GetPresence(XmppJid targetJid)
        {
            Presence presence = new Presence
            {
                Id      = XmppIdentifierGenerator.Generate(),
                Type    = PresenceType.Probe,
                From    = this.session.UserId,
                To      = targetJid
            };

            this.session.Send(presence);
        }
Esempio n. 2
0
        internal void Update(Presence presence)
        {
            if (presence.TypeSpecified &&
                presence.Type == PresenceType.Unavailable)
            {
                this.PresenceStatus = XmppPresenceState.Offline;
            }
            else
            {
                this.PresenceStatus = XmppPresenceState.Available;
            }

            foreach (object item in presence.Items)
            {
                if (item is sbyte)
                {
                    this.Priority = (sbyte)item;
                }
                if (item is int)
                {
                    this.Priority = (int)item;
                }
                else if (item is ShowType)
                {
                    this.PresenceStatus = this.DecodeShowAs((ShowType)item);
                }
                else if (item is Status)
                {
                    this.StatusMessage = ((Status)item).Value;
                }
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Processes the presence message.
        /// </summary>
        /// <param name="presence">The presence.</param>
        /// <returns></returns>
        private bool ProcessPresenceMessage(Presence presence)
        {
            this.onPresenceMessage.OnNext(presence);

            return true;
        }
Esempio n. 4
0
        /// <summary>
        /// Request subscription to the given user
        /// </summary>
        /// <param name="contactId"></param>
        public void RequestSubscription(XmppJid jid)
        {
            Presence presence = new Presence
            {
                Type   = PresenceType.Subscribe,
                To     = jid
            };

            this.session.Send(presence);
        }
Esempio n. 5
0
        /// <summary>
        /// Sets the presence as Unavailable
        /// </summary>
        public void SetUnavailable()
        {
            Presence presence = new Presence
            {
                Type = PresenceType.Unavailable
            };

            this.session.Send(presence);
        }
Esempio n. 6
0
        /// <summary>
        /// Subscribes to presence updates of the current user
        /// </summary>
        /// <param name="jid"></param>
        public void Unsuscribed(XmppJid jid)
        {
            Presence presence = new Presence
            {
                Type    = PresenceType.Unsubscribed,
                To      = jid
            };

            this.session.Send(presence);
        }
Esempio n. 7
0
        /// <summary>
        /// Sets the initial presence against the given user.
        /// </summary>
        /// <param name="target">JID of the target user.</param>
        public void SetInitialPresence(XmppJid target)
        {
            Presence presence = new Presence();

            if (target != null && target.ToString().Length > 0)
            {
                presence.To = target.ToString();
            }

            this.session.Send(presence);
        }
Esempio n. 8
0
        /// <summary>
        /// Sets the presence state with the given state, status message and priority
        /// </summary>
        /// <param name="showAs"></param>
        /// <param name="statusMessage"></param>
        /// <param name="priority"></param>
        public void SetPresence(XmppPresenceState showAs, string statusMessage, int priority)
        {
            Presence    presence    = new Presence();
            Status      status      = new Status();

            status.Value    = statusMessage;
            presence.Id     = XmppIdentifierGenerator.Generate();

            presence.Items.Add((ShowType)showAs);
            presence.Items.Add(status);

            this.session.Send(presence);
        }
Esempio n. 9
0
        internal void AddDefaultResource()
        {
            Presence            defaultPresence = new Presence();
            XmppContactResource contactResource = new XmppContactResource(this.session, this, this.ContactId);
            XmppJid             resourceJid     = new XmppJid(this.contactId.UserName, this.ContactId.DomainName, Guid.NewGuid().ToString());

            // Add a default resource
            defaultPresence.TypeSpecified   = true;
            defaultPresence.From            = resourceJid;
            defaultPresence.Type            = PresenceType.Unavailable;

            defaultPresence.Items.Add(XmppContactResource.DefaultPresencePriorityValue);

            contactResource.Update(defaultPresence);

            this.resources.Add(contactResource);
        }
Esempio n. 10
0
        internal void UpdatePresence(XmppJid jid, Presence presence)
        {
            lock (this.syncObject)
            {
                XmppContactResource resource = this.resources
                    .Where(contactResource => contactResource.ResourceId.Equals(jid))
                    .SingleOrDefault();

                if (resource == null)
                {
                    resource = new XmppContactResource(this.session, this, jid);
                    this.resources.Add(resource);
                }

                resource.Update(presence);

                // Remove the resource information if the contact has gone offline
                if (!resource.IsDefaultResource &&
                    resource.Presence.PresenceStatus == XmppPresenceState.Offline)
                {
                    this.resources.Remove(resource);
                }

                this.NotifyPropertyChanged(() => Presence);
                this.NotifyPropertyChanged(() => Resource);
            }
        }
Esempio n. 11
0
        internal void Update(Presence presence)
        {
            this.Presence.Update(presence);

            if (this.IsDefaultResource && this.Presence.PresenceStatus == XmppPresenceState.Offline)
            {
                string cachedHash = this.session.AvatarStorage.GetAvatarHash(this.ResourceId.BareIdentifier);

                // Grab stored images for offline users
                if (!String.IsNullOrEmpty(cachedHash))
                {
                    // Dipose Avatar Streams
                    this.DisposeAvatarStream();

                    // Update the avatar hash and file Paths
                    this.avatarHash = cachedHash;
                    this.Avatar     = this.session.AvatarStorage.ReadAvatar(this.ResourceId.BareIdentifier);
                }
            }

            foreach (object item in presence.Items)
            {
                if (item is Error)
                {
            #warning TODO: Handle the error
                }
                else if (item is VCardAvatar)
                {
                    VCardAvatar vcard = (VCardAvatar)item;

                    if (vcard.Photo != null && vcard.Photo.Length > 0)
                    {
                        if (!String.IsNullOrEmpty(vcard.Photo))
                        {
                            // Check if we have the avatar cached
                            string cachedHash = this.session.AvatarStorage.GetAvatarHash(this.ResourceId.BareIdentifier);

                            if (cachedHash == vcard.Photo)
                            {
                                // Dispose Avatar Streams
                                this.DisposeAvatarStream();

                                // Update the avatar hash and file Paths
                                this.avatarHash = vcard.Photo;
                                this.Avatar     = this.session.AvatarStorage.ReadAvatar(this.ResourceId.BareIdentifier);
                            }
                            else
                            {
                                // Update the avatar hash
                                this.avatarHash = vcard.Photo;

                                // Avatar is not cached request the new avatar information
                                this.RequestAvatar();
                            }
                        }
                    }
                }
                else if (item is EntityCapabilities)
                {
                    EntityCapabilities caps = (EntityCapabilities)item;

                    // Request capabilities only if they aren't cached yet for this resource
                    // or the verfiication string differs from the one that is cached
                    if (this.Capabilities == null || this.Capabilities.VerificationString != caps.VerificationString)
                    {
                        this.Capabilities.Node 					= caps.Node;
                        this.Capabilities.HashAlgorithmName 	= caps.HashAlgorithmName;
                        this.Capabilities.VerificationString 	= caps.VerificationString;
                        this.Capabilities.Identities.Clear();
                        this.Capabilities.Features.Clear();

                        // Check if we have the capabilities in the storage
                        if (this.session.ClientCapabilitiesStorage.Exists(caps.Node, caps.VerificationString))
                        {
                            this.Capabilities = this.session.ClientCapabilitiesStorage.Get(caps.Node, caps.VerificationString);
                        }
                        else if ((this.contact.Subscription == XmppContactSubscriptionType.Both ||
                             this.contact.Subscription == XmppContactSubscriptionType.To) &&
                             (!presence.TypeSpecified || presence.Type == PresenceType.Unavailable))
                        {
                            // Discover Entity Capabilities Extension Features
                            this.DiscoverCapabilities();
                        }

                        this.NotifyPropertyChanged(() => Capabilities);
                    }
                }
            }
        }
        public void AdvertiseCapabilities()
        {
            if (!String.IsNullOrEmpty(this.ServiceDiscoveryName) &&
                !String.IsNullOrEmpty(this.Node) &&
                this.Identities.Count > 0)
            {
                Presence presence = new Presence
                {
                    Id = XmppIdentifierGenerator.Generate()
                };

                if (this.session.Capabilities != null)
                {
                    presence.Items.Add(this.GetEntityCapabilities());
                }

                this.session.Send(presence);
            }
        }
Esempio n. 13
0
        private void OnPresenceMessageReceived(Presence message)
        {
            //<presence to='[email protected]/Home' from='[email protected]/carlosga'>
            //    <x xmlns='http://jabber.org/protocol/muc#user'>
            //        <item jid='[email protected]/Home' affiliation='owner' role='moderator'/>
            //        <status code='110'/>
            //    </x>
            //</presence>

            if (message.Items != null && message.Items.Count > 0)
            {
                foreach (object item in message.Items)
                {
                    if (item is MucUser)
                    {
                        this.ProcessMucUser(item as MucUser);
                    }
                }
            }

            this.createChatRoomEvent.Set();
            this.seekEnterChatRoomEvent.Set();
        }
Esempio n. 14
0
        /// <summary>
        /// Enters to the chat room
        /// </summary>
        /// <returns></returns>
        public XmppChatRoom Enter()
        {
            Presence presence = new Presence
            {
                From = this.Session.UserId,
                To = this.Identifier
            };

            presence.Items.Add(new Muc());

            this.Session.Send(presence);

            this.createChatRoomEvent.WaitOne();

            return this;
        }
Esempio n. 15
0
        /// <summary>
        /// Closes the chatroom
        /// </summary>
        public void Close()
        {
            Presence presence = new Presence
            {
                Id      = XmppIdentifierGenerator.Generate(),
                To      = this.Identifier,
                Type    = PresenceType.Unavailable
            };

            this.PendingMessages.Add(presence.Id);

            this.Session.Send(presence);
        }