git » sdk » commit 75543e6

Wait until client is connected

author Stephen Paul Weber
2024-09-18 18:10:22 UTC
committer Stephen Paul Weber
2024-09-18 18:10:22 UTC
parent b72f25c07112aef4076e03f91b58dd3dd8d31242

Wait until client is connected

If sending after client exists but before it is connected (or while it
is reconnecting) then calling client.send will throw an error and not
save anything into SM state. So push these stanzas into pending to be
sent when coming online.

Not that this is not part of SM state and is not persisted at all, so a
full crash/reset will lose these stanzas right now, unlike un-acked SM stanzas.

snikket/streams/XmppJsStream.hx +2 -1

diff --git a/snikket/streams/XmppJsStream.hx b/snikket/streams/XmppJsStream.hx
index ebddc4a..1364128 100644
--- a/snikket/streams/XmppJsStream.hx
+++ b/snikket/streams/XmppJsStream.hx
@@ -293,7 +293,8 @@ class XmppJsStream extends GenericStream {
 	}
 
 	public function sendStanza(stanza:Stanza) {
-		if (client == null) {
+		if (client == null || client.status != "online") {
+			// TODO: these aren't part of the sm state so they can get lost
 			pending.push(convertFromStanza(stanza));
 		} else {
 			client.send(convertFromStanza(stanza));