Skip to content

Commit

Permalink
Support for CSI
Browse files Browse the repository at this point in the history
  • Loading branch information
singpolyma committed Jul 10, 2024
1 parent e14054c commit 468720c
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
16 changes: 16 additions & 0 deletions snikket/Client.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions snikket/GenericStream.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
6 changes: 6 additions & 0 deletions snikket/streams/XmppJsStream.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit 468720c

Please sign in to comment.