xmpp.js icon indicating copy to clipboard operation
xmpp.js copied to clipboard

Response to PING

Open Pistacchione opened this issue 6 years ago • 11 comments

Hi,

I try to response a ping request, but every time the library sent this message:

<iq to="fakedomain" from="user1@fakedomain/491531e" id="89FD2BFFB1DBCB38" type="error" xmlns="jabber:client">
  <ping xmlns="urn:xmpp:ping"/>
  <error type="cancel">
    <service-unavailable xmlns="urn:ietf:params:xml:ns:xmpp-stanzas"/>
  </error>
</iq>

How can I manage the ping?

Pistacchione avatar Jan 22 '19 17:01 Pistacchione

After some trial and error I manage the ping using iq package in this way:

iqCallee.get('urn:xmpp:ping', 'ping', ctx => { return {} })

but I don't known for sure if this is the right way to manage ping request

Pistacchione avatar Jan 23 '19 10:01 Pistacchione

Please note that an error reply is a correct ping response as it fulfils its purpose.

iqCallee.get('urn:xmpp:ping', 'ping', ctx => { return {} }) is correct, it replies with an empty response

Is there any specific reason why answering with an error wasn't enough? I can imagine enabling ping namespace response in @xmpp/client.

sonnyp avatar Jan 29 '19 12:01 sonnyp

Hi @sonnyp

I'm not an expert of XMPP but based on ping documentation https://xmpp.org/extensions/xep-0199.html if I received a ping message:

<iq from='capulet.lit' to='[email protected]/balcony' id='s2c1' type='get'>
  <ping xmlns='urn:xmpp:ping'/>
</iq>

I must return a response like this:

<iq from='[email protected]/balcony' to='capulet.lit' id='s2c1' type='result'/>

I must return an error only if I don't support ping namespace:

<iq from='[email protected]/balcony' to='capulet.lit' id='s2c1' type='error'>
  <ping xmlns='urn:xmpp:ping'/>
  <error type='cancel'>
    <service-unavailable xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/>
  </error>
</iq>

Correct me if I say something wrong :) Thanks

Pistacchione avatar Jan 29 '19 13:01 Pistacchione

@Pistacchione you're right, my point is that answering a ping request with an error is considered a ping response anyway because it fulfils the purpose of the ping.

Anyway, I will add ping response to @xmpp/client to remove the ambiguity

sonnyp avatar Jan 29 '19 13:01 sonnyp

This ping response as an error keeps happening, right?

dlameri avatar May 14 '19 17:05 dlameri

This ping response as an error keeps happening, right?

I tested this problem. It's bug is did not fixed. After some time to be disconnected.

IProudNoob avatar Apr 26 '20 09:04 IProudNoob

Was the ping response added to @xmpp/client?

gabsoftware avatar Nov 25 '20 09:11 gabsoftware

Up until v0.13.0, xmpp.js seems to respond with the error as discussed above.

I put in place a ping-response implementation:

client.on('stanza', (stanza) => {
  // XEP-0199: XMPP Ping
  if (stanza.is('iq') && stanza.attrs.type === 'get' && stanza.getChild('ping', 'urn:xmpp:ping')) {
    client.send(
      xml("iq", { from: stanza.attrs.to, to: stanza.attrs.from, id: stanza.attrs.id, type: 'result' })
    );
  }
});

This results in double response to the same ping:

IN
<iq type="get" id="792-276" from="my-server" to="2cwdh9zdl8@my-server/2cwdh9zdl8"><ping xmlns="urn:xmpp:ping"/></iq>
OUT
<iq from="2cwdh9zdl8@my-server/2cwdh9zdl8" to="my-server" id="792-276" type="result"/>
OUT
<iq to="my-server" from="2cwdh9zdl8@my-server/2cwdh9zdl8" id="792-276" type="error"><ping xmlns="urn:xmpp:ping"/><error type="cancel"><service-unavailable xmlns="urn:ietf:params:xml:ns:xmpp-stanzas"/></error></iq>

While this seems to be accepted by my XMPP Server (Openfire), it surely isn't pretty.

netmikey avatar Aug 28 '21 11:08 netmikey

@netmikey this is not how you're supposed to reply to iqs with xmpp.js. The solution is in https://github.com/xmppjs/xmpp.js/issues/629#issuecomment-458528741

See https://github.com/xmppjs/xmpp.js/tree/main/packages/iq#callee

sonnyp avatar Aug 28 '21 12:08 sonnyp

Thanks for correcting me, @sonnyp! I had looked at the @xmpp/client documentation but had overseen the fact that iq handling is (understandably) documented in the iq package.

netmikey avatar Aug 28 '21 14:08 netmikey

@netmikey this is not how you're supposed to reply to iqs with xmpp.js. The solution is in #629 (comment)

See https://github.com/xmppjs/xmpp.js/tree/main/packages/iq#callee

Thanks. I think it should be prebuilt/by-default since it's in the spec.

iravan avatar Nov 03 '23 18:11 iravan