From 468720c90c4b126ddb2032c0929542a581eb38c7 Mon Sep 17 00:00:00 2001 From: Stephen Paul Weber Date: Wed, 10 Jul 2024 14:01:06 -0500 Subject: [PATCH] Support for CSI --- snikket/Client.hx | 16 ++++++++++++++++ snikket/GenericStream.hx | 1 + snikket/streams/XmppJsStream.hx | 6 ++++++ 3 files changed, 23 insertions(+) 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 = 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, 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); }