git » sdk » commit a0aaebe

Pending queue if we try to send before online

author Stephen Paul Weber
2023-10-18 16:23:35 UTC
committer Stephen Paul Weber
2023-10-18 16:23:35 UTC
parent 47f19f76fad99f4886361a5d75ef5eb95f3a5310

Pending queue if we try to send before online

xmpp/streams/XmppJsStream.hx +10 -1

diff --git a/xmpp/streams/XmppJsStream.hx b/xmpp/streams/XmppJsStream.hx
index 1d85252..b597e52 100644
--- a/xmpp/streams/XmppJsStream.hx
+++ b/xmpp/streams/XmppJsStream.hx
@@ -77,6 +77,7 @@ class XmppJsStream extends GenericStream {
 	private var connectionURI:String;
 	private var debug = true;
 	private var state:FSM;
+	private var pending:Array<XmppJsXml> = [];
 
 	override public function new() {
 		super();
@@ -143,6 +144,10 @@ class XmppJsStream extends GenericStream {
 			xmpp.on("online", function (jid) {
 				this.jid = jid;
 				this.state.event("connection-success");
+				var item;
+				while ((item = pending.shift()) != null) {
+					client.send(item);
+				}
 			});
 
 			xmpp.on("offline", function (data) {
@@ -198,7 +203,11 @@ class XmppJsStream extends GenericStream {
 	}
 
 	public function sendStanza(stanza:Stanza) {
-		client.send(convertFromStanza(stanza));
+		if (client == null) {
+			pending.push(convertFromStanza(stanza));
+		} else {
+			client.send(convertFromStanza(stanza));
+		}
 	}
 
 	public function newId():String {