Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an asynchronous function to send stanzas. #764

Closed
wants to merge 1 commit into from

Conversation

jinyu2022
Copy link

Add an asynchronous function to send stanzas.

@EarzuChan
Copy link

Nice

* - If the server returns an error, it rejects with the error stanza.
* - If the request times out, it rejects with null.
*/
sendAsync(stanza, timeout = 3000) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your PR.

AFAIK the IQ stanza is the only one for which you can reasonably expect a responding stanza, and Strophe already has a sendIQ method. In fact this method looks largely like a copy/paste of that one except that it also returns a Promise.

For what other stanzas/use-cases besides IQ stanzas do you expect to use this method for?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have added a generic compatibility interface designed to support the more elegant and modern approach of asynchronous programming with Promises. While IQ stanzas are the primary use case, I hope this method can provide flexibility for other types of stanzas, especially in scenarios where asynchronous results need to be handled. For instance, there may be cases where you need to retrieve the unique stanza ID of a message, or when we need to send a message and wait for confirmation.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With XMPP, if you send a stanza that requires a confirmation, then you send an IQ stanza. For other types of stanzas you cannot expect any kind of confirmation or return stanza.

This change largely just duplicates the already existing sendIQ stanza. If we want to add promises, then we need to add them to the existing methods instead of duplicating them as is done here.

Copy link
Author

@jinyu2022 jinyu2022 Dec 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the suggestion! To avoid potential compatibility issues, I've created a new method that supports promises.

If we decide to modify the existing method, I can update it to check for a callback function. If a callback is provided, it will continue to function as before; if not, it will return a Promise.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can update it to check for a callback function. If a callback is provided, it will continue to function as before; if not, it will return a Promise.

Yes I think this will be a better approach. 👍

@jcbrand jcbrand closed this Dec 12, 2024
@jcbrand
Copy link
Contributor

jcbrand commented Dec 12, 2024

Closing for now. Feel free to create a new MR with the changes as discussed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants