git » sdk » commit 4057a93

Try again with password if FAST fails

author Stephen Paul Weber
2024-07-03 14:49:25 UTC
committer Stephen Paul Weber
2024-07-03 14:49:25 UTC
parent 40a29b5049364e7036d74801d03eb68ee9aa509d

Try again with password if FAST fails

snikket/Client.hx +9 -0
snikket/streams/XmppJsStream.hx +15 -1

diff --git a/snikket/Client.hx b/snikket/Client.hx
index 2c829cb..c66ab06 100644
--- a/snikket/Client.hx
+++ b/snikket/Client.hx
@@ -473,6 +473,15 @@ class Client extends EventEmitter {
 								this.stream.trigger("auth/password", { password: token, mechanism: fastMechanism, fastCount: fastCount });
 							}
 						});
+						stream.on("auth/fail", (data) -> {
+							if (token != null) {
+								token = null;
+								stream.connect(jid.asString(), smId == null || smId == "" ? null : { id: smId, outbound: smOut, inbound: smIn, outbound_q: smOutQ });
+							} else {
+								this.trigger("auth/fail", data);
+							}
+							return EventHandled;
+						});
 						stream.connect(jid.asString(), smId == null || smId == "" ? null : { id: smId, outbound: smOut, inbound: smIn, outbound_q: smOutQ });
 					});
 				});
diff --git a/snikket/streams/XmppJsStream.hx b/snikket/streams/XmppJsStream.hx
index d052293..7d7f9ef 100644
--- a/snikket/streams/XmppJsStream.hx
+++ b/snikket/streams/XmppJsStream.hx
@@ -76,6 +76,14 @@ extern class XmppJsId {
 	static function id():String;
 }
 
+@:jsRequire("@xmpp/error")
+extern class XmppJsError {
+	public final name: String;
+	public final condition: String;
+	public final text: String;
+	public final application: String;
+}
+
 typedef HostMetaRecord = {
 	rel : String,
 	href : String,
@@ -224,7 +232,13 @@ class XmppJsStream extends GenericStream {
 
 		resumed = false;
 		xmpp.start().catchError(function (err) {
-			trace(err);
+			this.state.event("connection-error");
+			final xmppError = Std.downcast(err, XmppJsError);
+			if (xmppError?.name == "SASLError") {
+				this.trigger("auth/fail", xmppError);
+			} else {
+				trace(err);
+			}
 		});
 	}