git » sdk » commit 468720c

Support for CSI

author Stephen Paul Weber
2024-07-10 19:01:06 UTC
committer Stephen Paul Weber
2024-07-10 19:01:06 UTC
parent e14054c3040b791db4f310608bf2b68f0f1c6ef4

Support for CSI

snikket/Client.hx +16 -0
snikket/GenericStream.hx +1 -0
snikket/streams/XmppJsStream.hx +6 -0

diff --git a/snikket/Client.hx b/snikket/Client.hx
index 1cf27db..acc2401 100644
--- a/snikket/Client.hx
+++ b/snikket/Client.hx
@@ -943,6 +943,22 @@ class Client extends EventEmitter {
 		});
 	}
 
+	/**
+		Let the SDK know the UI is in the foreground
+	**/
+	public function setInForeground() {
+		if (!stream.csi) return;
+		stream.sendStanza(new Stanza("active", { xmlns: "urn:xmpp:csi:0" }));
+	}
+
+	/**
+		Let the SDK know the UI is in the foreground
+	**/
+	public function setNotInForeground() {
+		if (!stream.csi) return;
+		stream.sendStanza(new Stanza("inactive", { xmlns: "urn:xmpp:csi:0" }));
+	}
+
 	@:allow(snikket)
 	private function chatActivity(chat: Chat, trigger = true) {
 		if (chat.uiState == Closed) {
diff --git a/snikket/GenericStream.hx b/snikket/GenericStream.hx
index 4ac545c..c21a17e 100644
--- a/snikket/GenericStream.hx
+++ b/snikket/GenericStream.hx
@@ -11,6 +11,7 @@ enum IqResult {
 
 abstract class GenericStream extends EventEmitter {
 	public var clientId: Null<String> = null;
+	public var csi(default, null) = false;
 
 	public function new() {
 		super();
diff --git a/snikket/streams/XmppJsStream.hx b/snikket/streams/XmppJsStream.hx
index 017f51b..ebddc4a 100644
--- a/snikket/streams/XmppJsStream.hx
+++ b/snikket/streams/XmppJsStream.hx
@@ -28,6 +28,7 @@ extern class XmppJsClient {
 		get: (String, String, ({stanza: XmppJsXml})->Any)->Void,
 		set: (String, String, ({stanza: XmppJsXml})->Any)->Void,
 	};
+	var streamFeatures: { use:(String,String,({}, ()->Void, XmppJsXml)->Void)->Void };
 	var streamManagement: { id:String, outbound: Int, inbound: Int, outbound_q: Array<XmppJsXml>, enabled: Bool, allowResume: Bool };
 	var sasl2: Dynamic;
 }
@@ -176,6 +177,11 @@ class XmppJsStream extends GenericStream {
 		new XmppJsScramSha1(xmpp.sasl2);
 		xmpp.streamFrom = this.jid;
 
+		xmpp.streamFeatures.use("csi", "urn:xmpp:csi:0", (ctx, next, feature) -> {
+			csi = true;
+			return next();
+		});
+
 		if(this.debug) {
 			new XmppJsDebug(xmpp, true);
 		}