Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
ConnectedDevice.cs
1using System.Collections.Generic;
2using System.Threading.Tasks;
8
9namespace Waher.Things.Xmpp
10{
15 {
20 : base()
21 {
22 }
23
27 [Page(2, "XMPP", 100)]
28 [Header(3, "JID:")]
29 [ToolTip(4, "XMPP Address.")]
30 public string JID { get; set; }
31
37 public override Task<string> GetTypeNameAsync(Language Language)
38 {
39 return Language.GetStringAsync(typeof(ConcentratorDevice), 56, "XMPP Device");
40 }
41
47 public override Task<bool> AcceptsParentAsync(INode Parent)
48 {
49 return Task.FromResult(Parent is Root);
50 }
51
57 public override Task<bool> AcceptsChildAsync(INode Child)
58 {
59 return Task.FromResult(false);
60 }
61
69 public string GetRemoteFullJid(XmppClient Client, out bool HasContact, out bool HasSubscription)
70 {
71 HasContact = false;
72 HasSubscription = false;
73
74 RosterItem Contact = Client[this.JID];
75 if (Contact is null)
76 return null;
77
78 HasContact = true;
79
80 if (!(Contact.State == SubscriptionState.Both || Contact.State == SubscriptionState.To))
81 return null;
82
83 HasSubscription = true;
84
85 return Contact.LastPresenceFullJid;
86 }
87
91 public override Task<IEnumerable<ICommand>> Commands => this.GetCommands();
92
93 private async Task<IEnumerable<ICommand>> GetCommands()
94 {
95 List<ICommand> Result = new List<ICommand>();
96 Result.AddRange(await base.Commands);
97
98 XmppClient Client = await this.GetClient();
99 if (!(Client is null))
100 {
101 this.GetRemoteFullJid(Client, out bool HasContact, out bool HasSubscription);
102
103 if (!HasContact || !HasSubscription)
104 Result.Add(new SubscribeToPresence(this));
105 }
106
107 return Result.ToArray();
108 }
109 }
110}
Maintains information about an item in the roster.
Definition: RosterItem.cs:75
SubscriptionState State
roup Current subscription state.
Definition: RosterItem.cs:268
string LastPresenceFullJid
Full JID of last resource sending online presence.
Definition: RosterItem.cs:343
Manages an XMPP client connection. Implements XMPP, as defined in https://tools.ietf....
Definition: XmppClient.cs:59
Contains information about a language.
Definition: Language.cs:17
Task< string > GetStringAsync(Type Type, int Id, string Default)
Gets the string value of a string ID. If no such string exists, a string is created with the default ...
Definition: Language.cs:209
INode Parent
Parent Node, or null if a root node.
Class for the root node of the Metering topology.
Definition: Root.cs:11
Sends a presence subscription request.
Node representing an XMPP concentrator.
Node representing a device that is connected to XMPP.
override Task< bool > AcceptsChildAsync(INode Child)
If the node accepts a presumptive child, i.e. can receive as a child (if that child accepts the node ...
override Task< string > GetTypeNameAsync(Language Language)
Gets the type name of the node.
ConnectedDevice()
Node representing a device that is connected to XMPP.
override Task< bool > AcceptsParentAsync(INode Parent)
If the node accepts a presumptive parent, i.e. can be added to that parent (if that parent accepts th...
override Task< IEnumerable< ICommand > > Commands
Available command objects. If no commands are available, null is returned.
string GetRemoteFullJid(XmppClient Client, out bool HasContact, out bool HasSubscription)
Gets the Full JID of the connected device.
Abstract base class for devices on the XMPP network.
Definition: XmppDevice.cs:13
async Task< XmppClient > GetClient()
Gets the XMPP Client associated with node.
Definition: XmppDevice.cs:36
Interface for nodes that are published through the concentrator interface.
Definition: INode.cs:49
SubscriptionState
State of a presence subscription.
Definition: RosterItem.cs:16