git » sdk » commit 33ee721

Allow timeout when waiting for candidates

author Stephen Paul Weber
2024-12-03 06:08:04 UTC
committer Stephen Paul Weber
2024-12-03 16:41:23 UTC
parent 654a63fb37ceb33745237fa088d16b25b39165ea

Allow timeout when waiting for candidates

If it takes too long just send what we have.

Also, if no caps for this resource use caps for any resource as a proxy
in this case.

snikket/Chat.hx +2 -2
snikket/jingle/Session.hx +14 -6

diff --git a/snikket/Chat.hx b/snikket/Chat.hx
index a5fb50c..ee1d179 100644
--- a/snikket/Chat.hx
+++ b/snikket/Chat.hx
@@ -466,8 +466,8 @@ abstract class Chat {
 	}
 
 	@:allow(snikket)
-	private function getResourceCaps(resource:String):Caps {
-		return presence[resource]?.caps ?? new Caps("", [], []);
+	private function getResourceCaps(resource:String, defaultToAny = false):Caps {
+		return presence[resource]?.caps ?? (defaultToAny ? presence.iterator().next()?.caps : null) ?? new Caps("", [], []);
 	}
 
 	@:allow(snikket)
diff --git a/snikket/jingle/Session.hx b/snikket/jingle/Session.hx
index f84d9cc..ae47101 100644
--- a/snikket/jingle/Session.hx
+++ b/snikket/jingle/Session.hx
@@ -290,7 +290,6 @@ class InitiatedSession implements Session {
 	private var afterMedia: Null<()->Void> = null;
 	private final initiator: Bool;
 	private var candidatesDone: Null<()->Void> = null;
-	private final caps: Caps;
 
 	@:allow(snikket)
 	private function new(client: Client, counterpart: JID, sid: String, remoteDescription: Null<SessionDescription>) {
@@ -299,7 +298,6 @@ class InitiatedSession implements Session {
 		this._sid = sid;
 		this.remoteDescription = remoteDescription;
 		this.initiator = remoteDescription == null;
-		this.caps = client.getDirectChat(counterpart.asBare().asString()).getResourceCaps(counterpart.resource);
 	}
 
 	@:allow(snikket)
@@ -555,13 +553,23 @@ class InitiatedSession implements Session {
 	}
 
 	private function setupLocalDescription(type: String, ?filterMedia: Array<String>, ?filterOut: Bool = false, ?beforeSend: (SessionDescription)->Void) {
-		return pc.setLocalDescription(null).then((_) ->
-			if ((type == "session-initiate" || type == "session-accept") && caps.features.contains("urn:ietf:rfc:3264")) {
-				new Promise((resolve, reject) -> candidatesDone = () -> resolve(true));
+		return pc.setLocalDescription(null).then((_) -> {
+			final caps = client.getDirectChat(counterpart.asBare().asString()).getResourceCaps(counterpart.resource, true);
+			return if ((type == "session-initiate" || type == "session-accept") && caps.features.contains("urn:ietf:rfc:3264")) {
+				new Promise((resolve, reject) -> {
+					final timeout = haxe.Timer.delay(() -> {
+						candidatesDone = () -> {};
+						resolve(false);
+					}, 3000);
+					candidatesDone = () -> {
+						timeout.stop();
+						resolve(true);
+					}
+				});
 			} else {
 				null;
 			}
-		).then((_) -> {
+		}).then((_) -> {
 			localDescription = SessionDescription.parse(pc.localDescription.sdp);
 			var descriptionToSend = localDescription;
 			if (filterMedia != null) {