-
Notifications
You must be signed in to change notification settings - Fork 365
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
Conversation
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) { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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. 👍
Closing for now. Feel free to create a new MR with the changes as discussed. |
Add an asynchronous function to send stanzas.