I want all the contact list in the roster to be displayed with presence of type online if they are connected and offline if they are not.

what i did ? I Requested the user's roster from the xmpp server and I Created IQ stanza to request the user's stanza then I Sent the IQ stanza to the server so I Received the Requested Roster then I Extracted all roster items from response's query element and store it in userRosterClone

const userRosterClone = this.userRoster.slice(); 

what i want to do now is to display online presence for each user in the roster so i created a function and send the roster list

 this.requestUserPresence(userRosterClone);

 requestUserPresence(contactList): void{
  for (let i = 0 ; i<contactList.length; i++){

  console.log("Requesting the user\'s presence...");

  // 1. Creating presence stanza to request the user's contact list stanza

  const presence = $pres({
 id: generateUUIDv4(),
 to: contactList[i].contactJid,
 type: "subscribe"

   })

  console.log("presence to request the user's presence:", 
   presence.tree());

  // 2. Sending the presence stanza to the server


   this.connection.addHandler(this. 
   onReceivingRequestedPresence.bind(this), null, "presence");

   this.connection.sendPresence(presence);

    }

the problem is onReceivingRequestedPresence is not working i can't send presence to the roster of type subscribed.

   onReceivingRequestedPresence(presence){

   console.log("Server Response to roster presence request: ", 
    presence);

   const pres= $pres({
    from: presence.to,
    id: presence.id,
    to: this.connection.jid,
    type: "subscribed"
    })

  // 2. Sending the IQ stanza to the server

this.connection.sendPresence(pres)


  }

0 Answers