Making new friends

When we have identified a device we need access to, we need to update our roster accordingly by annotating the contact with the corresponding groups. If a roster item already exists, we update it. If one does not exist, we add one. We also need to send a presence subscription to the corresponding device, if one is not already available, to be able to communicate with it:

   RosterItem Item = this.xmppClient[this.sensorJid]; 
   if (Item != null) 
   { 
         this.xmppClient.UpdateRosterItem(this.sensorJid, 
               Item.Name, this.AddReference(Item.Groups, 
               "Sensor", Thing.Node)); 
 
         if (Item.State != SubscriptionState.Both && 
               Item.State != SubscriptionState.To) 
         { 
               this.xmppClient.RequestPresenceSubscription( 
                     this.sensorJid); 
         } 
   } 
   else 
   { 
         this.xmppClient.AddRosterItem( 
               new RosterItem(this.sensorJid, string.Empty, 
               this.AddReference(null, "Sensor", Thing.Node))); 
 
         this.xmppClient.RequestPresenceSubscription( 
               this.sensorJid); 
   } 
} 
break;
Here, the AddReference() method does the opposite of what the GetReference() method does: it adds group names encoding the identity of the device. See the GitHub repository for details.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.144.243.184