git » sdk » commit 70d170f

Add conditional compilation flags for Jingle and OMEMO

author Matthew Wild
2024-12-05 12:38:50 UTC
committer Matthew Wild
2025-04-15 16:14:42 UTC
parent 5d32596548fd3496e3bdf8a4762dc806c00c4d36

Add conditional compilation flags for Jingle and OMEMO

This allows builds to work on non-CPP/JS targets, such as when running the
tests through the interpreter (where we don't need the full stack of media and
crypto dependencies just for the basic tests).

snikket/Chat.hx +10 -2
snikket/Client.hx +29 -2
snikket/Persistence.hx +7 -1
snikket/persistence/Dummy.hx +9 -1
snikket/persistence/Sqlite.hx +4 -1
test.hxml +9 -2

diff --git a/snikket/Chat.hx b/snikket/Chat.hx
index 44120e4..c179fa4 100644
--- a/snikket/Chat.hx
+++ b/snikket/Chat.hx
@@ -11,8 +11,10 @@ import snikket.ID;
 import snikket.Message;
 import snikket.MessageSync;
 import snikket.Reaction;
+#if !NO_JINGLE
 import snikket.jingle.PeerConnection;
 import snikket.jingle.Session;
+#end
 import snikket.queries.DiscoInfoGet;
 import snikket.queries.MAMQuery;
 using Lambda;
@@ -53,8 +55,10 @@ abstract class Chat {
 		ID of this Chat
 	**/
 	public var chatId(default, null):String;
+#if !NO_JINGLE
 	@:allow(snikket)
 	private var jingleSessions: Map<String, snikket.jingle.Session> = [];
+#end
 	@:allow(snikket)
 	private var displayName:String;
 	/**
@@ -548,10 +552,11 @@ abstract class Chat {
 		Can audio calls be started in this Chat?
 	**/
 	public function canAudioCall():Bool {
+#if !NO_JINGLE
 		for (resource => p in presence) {
 			if (p.caps?.features?.contains("urn:xmpp:jingle:apps:rtp:audio") ?? false) return true;
 		}
-
+#end
 		return false;
 	}
 
@@ -559,13 +564,15 @@ abstract class Chat {
 		Can video calls be started in this Chat?
 	**/
 	public function canVideoCall():Bool {
+#if !NO_JINGLE
 		for (resource => p in presence) {
 			if (p.caps?.features?.contains("urn:xmpp:jingle:apps:rtp:video") ?? false) return true;
 		}
-
+#end
 		return false;
 	}
 
+#if !NO_JINGLE
 	/**
 		Start a new call in this Chat
 
@@ -632,6 +639,7 @@ abstract class Chat {
 	public function videoTracks(): Array<MediaStreamTrack> {
 		return jingleSessions.flatMap((session) -> session.videoTracks());
 	}
+#end
 
 	@:allow(snikket)
 	private function markReadUpToId(upTo: String, upToBy: String, ?callback: ()->Void) {
diff --git a/snikket/Client.hx b/snikket/Client.hx
index 29acb75..6824402 100644
--- a/snikket/Client.hx
+++ b/snikket/Client.hx
@@ -5,18 +5,22 @@ import sha.SHA256;
 import haxe.crypto.Base64;
 import haxe.io.Bytes;
 import haxe.io.BytesData;
-import snikket.jingle.IceServer;
-import snikket.jingle.PeerConnection;
 import snikket.Caps;
 import snikket.Chat;
 import snikket.ChatMessage;
 import snikket.Message;
 import snikket.EventEmitter;
 import snikket.EventHandler;
+#if !NO_OMEMO
 import snikket.OMEMO;
+#end
 import snikket.PubsubEvent;
 import snikket.Stream;
+#if !NO_JINGLE
+import snikket.jingle.IceServer;
+import snikket.jingle.PeerConnection;
 import snikket.jingle.Session;
+#end
 import snikket.queries.BlocklistGet;
 import snikket.queries.BoB;
 import snikket.queries.DiscoInfoGet;
@@ -72,6 +76,7 @@ class Client extends EventEmitter {
 			"http://jabber.org/protocol/nick+notify",
 			"urn:xmpp:bookmarks:1+notify",
 			"urn:xmpp:mds:displayed:0+notify",
+#if !NO_JINGLE
 			"urn:xmpp:jingle-message:0",
 			"urn:xmpp:jingle:1",
 			"urn:xmpp:jingle:apps:dtls:0",
@@ -79,7 +84,10 @@ class Client extends EventEmitter {
 			"urn:xmpp:jingle:apps:rtp:audio",
 			"urn:xmpp:jingle:apps:rtp:video",
 			"urn:xmpp:jingle:transports:ice-udp:1",
+#end
+#if !NO_OMEMO
 			"eu.siacs.conversations.axolotl.devicelist+notify"
+#end
 		]
 	);
 	private var _displayName: String;
@@ -87,7 +95,10 @@ class Client extends EventEmitter {
 	private var token: Null<String> = null;
 	private final pendingCaps: Map<String, Array<(Null<Caps>)->Chat>> = [];
 
+#if !NO_OMEMO
+	@:allow(snikket)
 	private final omemo: OMEMO;
+#end
 
 	@:allow(snikket)
 	private var inSync(default, null) = false;
@@ -104,7 +115,9 @@ class Client extends EventEmitter {
 		this.jid = JID.parse(address);
 		this._displayName = this.jid.node;
 		this.persistence = persistence;
+#if !NO_OMEMO
 		this.omemo = new OMEMO(this, persistence);
+#end
 		stream = new Stream();
 		stream.on("status/online", this.onConnected);
 		stream.on("status/offline", (data) -> {
@@ -206,6 +219,7 @@ class Client extends EventEmitter {
 					// ignore
 			}
 
+#if !NO_JINGLE
 			final jmiP = stanza.getChild("propose", "urn:xmpp:jingle-message:0");
 			if (jmiP != null && jmiP.attr.get("id") != null) {
 				final session = new IncomingProposedSession(this, from, jmiP.attr.get("id"));
@@ -260,6 +274,7 @@ class Client extends EventEmitter {
 					chat.jingleSessions.remove(session.sid);
 				}
 			}
+#end
 
 			if (stanza.attr.get("type") != "error") {
 				final chatState = stanza.getChild(null, "http://jabber.org/protocol/chatstates");
@@ -348,6 +363,7 @@ class Client extends EventEmitter {
 
 				trace("pubsubNode == "+pubsubNode);
 
+#if !NO_OMEMO
 				if(pubsubNode == "eu.siacs.conversations.axolotl.devicelist") {
 					if(isOwnAccount) {
 						omemo.onAccountUpdatedDeviceList(pubsubEvent.getItems());
@@ -355,11 +371,13 @@ class Client extends EventEmitter {
 						omemo.onContactUpdatedDeviceList(fromBare, pubsubEvent.getItems());
 					}
 				}
+#end
 			}
 
 			return EventUnhandled; // Allow others to get this event as well
 		});
 
+#if !NO_JINGLE
 		stream.onIq(Set, "jingle", "urn:xmpp:jingle:1", (stanza) -> {
 			final from = stanza.attr.get("from") == null ? null : JID.parse(stanza.attr.get("from"));
 			final jingle = stanza.getChild("jingle", "urn:xmpp:jingle:1");
@@ -410,6 +428,7 @@ class Client extends EventEmitter {
 			// jingle requires useless replies to every iq
 			return IqResult;
 		});
+#end
 
 		stream.onIq(Get, "query", "http://jabber.org/protocol/disco#info", (stanza) -> {
 			return IqResultElement(caps.discoReply());
@@ -1116,6 +1135,7 @@ class Client extends EventEmitter {
 		});
 	}
 
+#if !NO_JINGLE
 	/**
 		Event fired when a new call comes in
 
@@ -1178,6 +1198,7 @@ class Client extends EventEmitter {
 			return EventHandled;
 		});
 	}
+#end
 
 	/**
 		Let the SDK know the UI is in the foreground
@@ -1277,6 +1298,7 @@ class Client extends EventEmitter {
 		);
 	}
 
+#if !NO_JINGLE
 	@:allow(snikket)
 	private function getIceServers(callback: (Array<IceServer>)->Void) {
 		final extDiscoGet = new ExtDiscoGet(jid.domain);
@@ -1304,6 +1326,7 @@ class Client extends EventEmitter {
 		});
 		sendQuery(extDiscoGet);
 	}
+#end
 
 	@:allow(snikket)
 	private function discoverServices(target: JID, ?node: String, callback: ({ jid: JID, name: Null<String>, node: Null<String> }, Caps)->Void) {
@@ -1458,6 +1481,7 @@ class Client extends EventEmitter {
 		}
 	}
 
+#if !NO_JINGLE
 	private function onMAMJMI(sid: String, stanza: Stanza) {
 		if (stanza.attr.get("from") == null) return;
 		final from = JID.parse(stanza.attr.get("from"));
@@ -1470,6 +1494,7 @@ class Client extends EventEmitter {
 		chatActivity(chat);
 		session.ring();
 	}
+#end
 
 	private function doSync(callback: Null<(Bool)->Void>, lastId: Null<String>) {
 		var thirtyDaysAgo = Date.format(
@@ -1524,6 +1549,7 @@ class Client extends EventEmitter {
 				if (sync.hasMore()) {
 					sync.fetchNext();
 				} else {
+#if !NO_JINGLE
 					for (sid => stanza in sync.jmi) {
 						onMAMJMI(sid, stanza);
 					}
@@ -1532,6 +1558,7 @@ class Client extends EventEmitter {
 						final chat = getChat(chatId);
 						if (chat == null) getDirectChat(chatId);
 					}
+#end
 					if (callback != null) callback(true);
 				}
 			},
diff --git a/snikket/Persistence.hx b/snikket/Persistence.hx
index 7672d65..b0cd9c5 100644
--- a/snikket/Persistence.hx
+++ b/snikket/Persistence.hx
@@ -5,9 +5,10 @@ import snikket.Chat;
 import snikket.ChatMessage;
 import snikket.Message;
 
+#if !NO_OMEMO
 import snikket.OMEMO;
-
 using snikket.SignalProtocol;
+#end
 
 #if cpp
 @:build(HaxeSwiftBridge.expose())
@@ -38,6 +39,7 @@ interface Persistence {
 	public function storeStreamManagement(accountId:String, data:Null<BytesData>):Void;
 	public function getStreamManagement(accountId:String, callback: (Null<BytesData>)->Void):Void;
 	public function storeService(accountId:String, serviceId:String, name:Null<String>, node:Null<String>, caps:Caps):Void;
+#if !NO_OMEMO
 	public function getOmemoId(login:String, callback:(omemoId:Null<Int>)->Void):Void;
 	public function storeOmemoId(login:String, omemoId:Int):Void;
 	public function storeOmemoIdentityKey(login:String, keypair:IdentityKeyPair):Void;
@@ -49,6 +51,10 @@ interface Persistence {
 	public function storeOmemoSignedPreKey(login:String, signedPreKey:OMEMOBundleSignedPreKey):Void;
 	public function getOmemoSignedPreKey(login:String, keyId:Int, callback: (OMEMOBundleSignedPreKey)->Void):Void;
 	public function getOmemoPreKeys(login:String, callback: (Array<PreKeyPair>)->Void):Void;
+	public function storeOmemoContactIdentityKey(account:String, address:String, identityKey:IdentityPublicKey):Void;
+	public function getOmemoContactIdentityKey(account:String, address:String, callback:(IdentityPublicKey)->Void):Void;
+#end
+
 
 	@HaxeCBridge.noemit
 	public function findServicesWithFeature(accountId:String, feature:String, callback:(Array<{serviceId:String, name:Null<String>, node:Null<String>, caps: Caps}>)->Void):Void;
diff --git a/snikket/persistence/Dummy.hx b/snikket/persistence/Dummy.hx
index 79c05b0..65b8b46 100644
--- a/snikket/persistence/Dummy.hx
+++ b/snikket/persistence/Dummy.hx
@@ -7,9 +7,11 @@ import haxe.io.BytesData;
 import snikket.Caps;
 import snikket.Chat;
 import snikket.Message;
+#if !NO_OMEMO
 import snikket.OMEMO;
-
 using snikket.SignalProtocol;
+#end
+
 
 // TODO: consider doing background threads for operations
 
@@ -142,6 +144,7 @@ class Dummy implements Persistence {
 		callback([]);
 	}
 
+#if !NO_OMEMO
 	@HaxeCBridge.noemit
 	public function getOmemoId(login:String, callback:(omemoId:Null<Int>)->Void):Void { }
 
@@ -171,4 +174,9 @@ class Dummy implements Persistence {
 	@HaxeCBridge.noemit
 	public function getOmemoPreKeys(login:String, callback: (Array<PreKeyPair>)->Void):Void { }
 
+	@HaxeCBridge.noemit
+	public function storeOmemoContactIdentityKey(account:String, address:String, identityKey:IdentityPublicKey):Void { }
+	@HaxeCBridge.noemit
+	public function getOmemoContactIdentityKey(account:String, address:String, callback:(IdentityPublicKey)->Void):Void { }
+#end
 }
diff --git a/snikket/persistence/Sqlite.hx b/snikket/persistence/Sqlite.hx
index 405affd..edd6ea4 100644
--- a/snikket/persistence/Sqlite.hx
+++ b/snikket/persistence/Sqlite.hx
@@ -14,7 +14,9 @@ import snikket.Chat;
 import snikket.Message;
 import snikket.Reaction;
 import snikket.ReactionUpdate;
+#if !NO_OMEMO
 import snikket.OMEMO;
+#end
 
 using Lambda;
 
@@ -824,6 +826,7 @@ class Sqlite implements Persistence implements KeyValueStore {
 		}));
 	}
 
+#if !NO_OMEMO
 	// OMEMO
 	// TODO
 	@HaxeCBridge.noemit
@@ -831,5 +834,5 @@ class Sqlite implements Persistence implements KeyValueStore {
 
 	@HaxeCBridge.noemit
 	public function storeOmemoId(login:String, omemoId:Int):Void { }
-
+#end
 }
diff --git a/test.hxml b/test.hxml
index 4c9ebd2..9276a7f 100644
--- a/test.hxml
+++ b/test.hxml
@@ -1,8 +1,15 @@
+--library HtmlParser
+--library datetime
 --library haxe-strings
 --library hsluv
+--library hxtsdgen
+--library sha
+--library thenshim
+--library tink_http
+
 --library utest
---library HtmlParser
---library datetime
 
+-D NO_JINGLE
+-D NO_OMEMO
 --run
 test.TestAll