xmppjs / xmpp.js

XMPP for JavaScript
ISC License
2.18k stars 371 forks source link

Added function to send an ack on demand #995

Open bmatasar opened 9 months ago

bmatasar commented 9 months ago

In the specs it says:

Either party MAY send an element at any time (e.g., after it has received a certain number of stanzas, or after a certain period of time), even if it has not received an element from the other party. It is RECOMMENDED that initiating entities (usually clients) send an element right before they gracefully close the stream, in order to inform the peer about received stanzas. Otherwise it can happen that stanzas are re-sent (usually by the server) although they were actually received.

I added a simple function to do that. Usage: client.streamManagement.sendAck()

singpolyma commented 8 months ago

Should this also automatically call right before disconnect?

bmatasar commented 8 months ago

This is a good question. In XEP-0198 they don't mention such a thing. They have 2 scenarios, one where an ack is sent after every message, the other with an ack sent every 5th message. In my use case I get seldom a couple of packets and the second scenario might leave some in the air, so I preferred to send an ack after processing a bulk.

Sending an ack before going offline might seem a good idea. Adding a config property to send automatically an ack after every n-th message would be another useful thing.

Please let me know if I can help with any of the 2.

singpolyma commented 8 months ago

It's right in your quote in the OP here:

It is RECOMMENDED that initiating entities (usually clients) send an element right before they gracefully close the stream, in order to inform the peer about received stanzas

otherwise I would only send when asked by the other side, as is done now.

bmatasar commented 8 months ago

I added the sending of the ack before going offline. I hope that is enough.