By default, XMPP presence is published to all those who are subscribed to that person. Is it possible to send something like an iq call to get presence tag of an id whos not present in my roster?
If all you want to know whether a XMPP entity is connected or not, you can use XMPP Ping (XEP-0199). Given below is an example of two xmpp users “user1” and “user2”. They are not on each others roaster list. I am using ejabberd and PSI for the below example.
IQ:
<iq from='[email protected]'
to='[email protected]/BANL07R9AME9X' type='get' id='e2e1'>
<ping xmlns='urn:xmpp:ping'/>
</iq>
Response:
<iq from="[email protected]/BANL07R9AME9X" type="result" xml:lang="en" to="[email protected]/BANL07R9AME9X" id="e2e1" />
IQ:
<iq from='[email protected]'
to='[email protected]/BANL07R9AME9X' type='get' id='e2e1'>
<ping xmlns='urn:xmpp:ping'/>
</iq>
Response:
<iq from="[email protected]/BANL07R9AME9X" type="error" xml:lang="en" to="[email protected]/BANL07R9AME9X" id="e2e1" >
<ping xmlns="urn:xmpp:ping"/>
<error type="cancel" code="503" >
<service-unavailable xmlns="urn:ietf:params:xml:ns:xmpp-stanzas"/>
</error>
</iq>
I don't think so. Have a look at the rfc, section 5.1.3. Specifically, it says:
Upon receiving a presence probe from the user, the contact's server
SHOULD reply as follows:If the user is not in the contact's roster with a subscription state of "From", "From + Pending Out", or "Both" (as defined under Subscription States (Section 9)), the contact's server MUST return a presence stanza of type "error" in response to the presence probe.
You will probably get an error or forbidden in a response.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With