From ff4e2540ae3bfab6873beb7e03ef5c6a5b9da1da Mon Sep 17 00:00:00 2001 From: fiaxh Date: Mon, 20 Dec 2021 19:44:15 +0100 Subject: xmpp-vala: Fix muji issues when waiting for peer to prepare --- xmpp-vala/src/module/xep/0272_muji.vala | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) (limited to 'xmpp-vala/src') diff --git a/xmpp-vala/src/module/xep/0272_muji.vala b/xmpp-vala/src/module/xep/0272_muji.vala index 290c4fab..2bdc068e 100644 --- a/xmpp-vala/src/module/xep/0272_muji.vala +++ b/xmpp-vala/src/module/xep/0272_muji.vala @@ -19,8 +19,9 @@ namespace Xmpp.Xep.Muji { if (result == null || result.nick == null) return null; debug(@"[%s] MUJI joining as %s done", stream.get_flag(Bind.Flag.IDENTITY).my_jid.to_string(), group_call.our_nick); + // Determine all participants that have finished preparation. Those are the ones we have to initiate the call with. Gee.List other_presences = yield wait_for_preparing_peers(stream, muc_jid); - var other_resources = new ArrayList(); + var finished_real_jids = new ArrayList(Jid.equals_func); foreach (Presence.Stanza presence in other_presences) { if (presence.stanza.get_deep_subnode(NS_URI + ":muji", NS_URI + ":preparing") != null) continue; Jid? real_jid = stream.get_flag(Muc.Flag.IDENTITY).get_real_jid(presence.from); @@ -28,10 +29,11 @@ namespace Xmpp.Xep.Muji { warning("Don't know the real jid for %s", presence.from.to_string()); continue; } - other_resources.add(real_jid); + finished_real_jids.add(real_jid); } - group_call.peers_to_connect_to.add_all(other_resources); + group_call.peers_to_connect_to.add_all(finished_real_jids); + // Build+send our own MUJI presence StanzaNode muji_node = new StanzaNode.build("muji", NS_URI).add_self_xmlns(); foreach (string media in video ? new string[] { "audio", "video" } : new string[] { "audio" }) { @@ -64,12 +66,12 @@ namespace Xmpp.Xep.Muji { private async Gee.List wait_for_preparing_peers(XmppStream stream, Jid muc_jid) { var promise = new Promise>(); - ArrayList preparing_peers = new ArrayList(); + ArrayList preparing_peers = new ArrayList(Jid.equals_func); Gee.List presences = get_other_presences(stream, muc_jid); foreach (Presence.Stanza presence in presences) { - StanzaNode? preparing_node = presence.stanza.get_deep_subnode(NS_URI + "muji", NS_URI + ":preparing"); + StanzaNode? preparing_node = presence.stanza.get_deep_subnode(NS_URI + ":muji", NS_URI + ":preparing"); if (preparing_node != null) { preparing_peers.add(presence.from); } @@ -81,8 +83,6 @@ namespace Xmpp.Xep.Muji { return presences; } - - GroupCall group_call = stream.get_flag(Flag.IDENTITY).calls[muc_jid]; group_call.waiting_for_finish_prepares[promise] = preparing_peers; @@ -201,10 +201,13 @@ namespace Xmpp.Xep.Muji { } private void on_jid_finished_preparing(XmppStream stream, Jid jid, GroupCall group_call) { + debug("Muji peer finished preparing %s", jid.to_string()); foreach (Promise> promise in group_call.waiting_for_finish_prepares.keys) { + debug("Waiting for finish prepares %i", group_call.waiting_for_finish_prepares[promise].size); Gee.List outstanding_prepares = group_call.waiting_for_finish_prepares[promise]; if (outstanding_prepares.contains(jid)) { outstanding_prepares.remove(jid); + debug("Waiting for finish prepares %i", group_call.waiting_for_finish_prepares[promise].size); if (outstanding_prepares.is_empty) { Gee.List presences = get_other_presences(stream, jid.bare_jid); @@ -252,7 +255,7 @@ namespace Xmpp.Xep.Muji { public class GroupCall { public string our_nick; public Jid muc_jid; - public ArrayList peers_to_connect_to = new ArrayList(); + public ArrayList peers_to_connect_to = new ArrayList(Jid.equals_func); public ArrayList peers = new ArrayList(Jid.equals_func); public HashMap real_jids = new HashMap(Jid.hash_func, Jid.equals_func); public HashMap> waiting_for_finish_prepares = new HashMap>(); -- cgit v1.2.3-70-g09d2