Esempio n. 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ContactResourcePresence"/> class using
        /// the given session.
        /// </summary>
        /// <param name="session"></param>
        internal ContactResourcePresence(ContactResource resource)
        {
            var transport = XmppTransportManager.GetTransport();

            this.resource       = resource;
            this.presenceStream = new Subject <ContactResource>();
            this.ShowAs         = ShowType.Offline;

            transport.StateChanged
            .Where(state => state == XmppTransportState.Closing)
            .Subscribe(state => OnDisconnecting());
        }
Esempio n. 2
0
        private async Task OnPresenceChangedAsync(Presence message)
        {
            var transport = XmppTransportManager.GetTransport();
            var resource  = this.resources.SingleOrDefault(contactResource => contactResource.Address == message.From);

            if (resource == null)
            {
                resource = new ContactResource(message.From, message);

                this.resources.Add(resource);
                this.newResourceStream.OnNext(resource);

                if (transport.ServerCapabilities != null && resource.SupportsEntityCapabilities)
                {
                    await resource.DiscoverCapabilitiesAsync().ConfigureAwait(false);
                }
            }
            else
            {
                if (message.TypeSpecified)
                {
                    switch (message.Type)
                    {
                    case PresenceType.Probe:
                        break;

                    case PresenceType.Subscribe:
                        // auto-accept subscription requests
                        await this.AcceptSubscriptionAsync().ConfigureAwait(false);

                        break;

                    case PresenceType.Unavailable:
                        this.UpdateResource(resource, message);
                        break;

                    case PresenceType.Unsubscribe:
                        await this.UnsuscribedAsync().ConfigureAwait(false);

                        break;
                    }
                }
                else
                {
                    this.UpdateResource(resource, message);
                }
            }

            this.RaisePropertyChanged(() => Resources);
            this.RaisePropertyChanged(() => HighPriorityResource);
        }
Esempio n. 3
0
        private void UpdateResource(ContactResource resource, Presence message)
        {
            resource.Update(message);

            // Remove the resource information if the contact has gone offline
            if (resource.IsOffline)
            {
                this.resources.Remove(resource);
                this.removedResourceStream.OnNext(resource);
            }

            this.RaisePropertyChanged(() => Resources);
            this.RaisePropertyChanged(() => HighPriorityResource);
        }
Esempio n. 4
0
 private void OnDisconnecting()
 {
     this.resource = null;
     this.presenceStream.Dispose();
 }