| author | Stephen Paul Weber
<singpolyma@singpolyma.net> 2024-04-16 13:56:08 UTC |
| committer | Stephen Paul Weber
<singpolyma@singpolyma.net> 2024-04-16 13:56:08 UTC |
| parent | 5eda91d1f032c56e9a29f780ea44c3d7a3b26975 |
| snikket/streams/XmppStropheStream.hx | +11 | -1 |
diff --git a/snikket/streams/XmppStropheStream.hx b/snikket/streams/XmppStropheStream.hx index 0ae68b7..8ea21fb 100644 --- a/snikket/streams/XmppStropheStream.hx +++ b/snikket/streams/XmppStropheStream.hx @@ -149,6 +149,8 @@ class XmppStropheStream extends GenericStream { extern private var ctx:StropheCtx; extern private var conn:StropheConn; private var iqHandlers: Map<IqRequestType, Map<String, Stanza->IqResult>> = [IqRequestType.Get => [], IqRequestType.Set => []]; + private final pending: Array<Stanza> = []; + private var ready = false; override public function new() { super(); @@ -220,6 +222,10 @@ class XmppStropheStream extends GenericStream { public static function strophe_connect(conn:StropheConn, event:StropheConnEvent, error:cpp.Int32, stream_error:StropheStreamError, userdata:RawPointer<Void>) { var stream: XmppStropheStream = untyped __cpp__("static_cast<hx::Object*>(userdata)"); if (event == untyped __cpp__("XMPP_CONN_CONNECT")) { + stream.ready = true; + while (stream.pending.length > 0) { + stream.sendStanza(stream.pending.shift()); + } stream.trigger("status/online", {}); } if (event == untyped __cpp__("XMPP_CONN_DISCONNECT")) { @@ -313,7 +319,11 @@ class XmppStropheStream extends GenericStream { } public function sendStanza(stanza:Stanza) { - StropheConn.send(conn, convertFromStanza(stanza)); + if (ready) { + StropheConn.send(conn, convertFromStanza(stanza)); + } else { + pending.push(stanza); + } } public function finalize() {