aboutsummaryrefslogtreecommitdiff
path: root/xmpp-vala
diff options
context:
space:
mode:
authorfiaxh <git@lightrise.org>2024-10-18 14:16:10 +0200
committerfiaxh <git@lightrise.org>2024-10-18 14:16:33 +0200
commit1e9a45f48143df6f3e36f3cd056a5b88271f8c2f (patch)
treeb8dd810c8f8536ef0a4801c562d251c65b9f0897 /xmpp-vala
parent3abe9fdb9ef485d048497da6046f0b12e421e869 (diff)
downloaddino-1e9a45f48143df6f3e36f3cd056a5b88271f8c2f.tar.gz
dino-1e9a45f48143df6f3e36f3cd056a5b88271f8c2f.zip
Use XEP-0482 for multi-party call invites
Diffstat (limited to 'xmpp-vala')
-rw-r--r--xmpp-vala/CMakeLists.txt2
-rw-r--r--xmpp-vala/meson.build2
-rw-r--r--xmpp-vala/src/module/xep/0353_call_invite_message.vala127
-rw-r--r--xmpp-vala/src/module/xep/0482_call_invites.vala187
4 files changed, 189 insertions, 129 deletions
diff --git a/xmpp-vala/CMakeLists.txt b/xmpp-vala/CMakeLists.txt
index fa0b08ef..4a213fda 100644
--- a/xmpp-vala/CMakeLists.txt
+++ b/xmpp-vala/CMakeLists.txt
@@ -135,7 +135,6 @@ SOURCES
"src/module/xep/0333_chat_markers.vala"
"src/module/xep/0334_message_processing_hints.vala"
"src/module/xep/0353_jingle_message_initiation.vala"
- "src/module/xep/0353_call_invite_message.vala"
"src/module/xep/0359_unique_stable_stanza_ids.vala"
"src/module/xep/0363_http_file_upload.vala"
"src/module/xep/0380_explicit_encryption.vala"
@@ -145,6 +144,7 @@ SOURCES
"src/module/xep/0428_fallback_indication.vala"
"src/module/xep/0444_reactions.vala"
"src/module/xep/0461_replies.vala"
+ "src/module/xep/0482_call_invites.vala"
"src/module/xep/pixbuf_storage.vala"
"src/util.vala"
diff --git a/xmpp-vala/meson.build b/xmpp-vala/meson.build
index 7d062db3..4d8c0493 100644
--- a/xmpp-vala/meson.build
+++ b/xmpp-vala/meson.build
@@ -108,7 +108,6 @@ sources = files(
'src/module/xep/0313_message_archive_management.vala',
'src/module/xep/0333_chat_markers.vala',
'src/module/xep/0334_message_processing_hints.vala',
- 'src/module/xep/0353_call_invite_message.vala',
'src/module/xep/0353_jingle_message_initiation.vala',
'src/module/xep/0359_unique_stable_stanza_ids.vala',
'src/module/xep/0363_http_file_upload.vala',
@@ -124,6 +123,7 @@ sources = files(
'src/module/xep/0428_fallback_indication.vala',
'src/module/xep/0444_reactions.vala',
'src/module/xep/0461_replies.vala',
+ 'src/module/xep/0482_call_invites.vala',
'src/module/xep/pixbuf_storage.vala',
'src/util.vala',
)
diff --git a/xmpp-vala/src/module/xep/0353_call_invite_message.vala b/xmpp-vala/src/module/xep/0353_call_invite_message.vala
deleted file mode 100644
index c467cde7..00000000
--- a/xmpp-vala/src/module/xep/0353_call_invite_message.vala
+++ /dev/null
@@ -1,127 +0,0 @@
-using Gee;
-namespace Xmpp.Xep.CallInvites {
-
- public const string NS_URI = "urn:xmpp:call-message:1";
-
- public class Module : XmppStreamModule {
- public static ModuleIdentity<Module> IDENTITY = new ModuleIdentity<Module>(NS_URI, "call_invites");
-
- public signal void call_proposed(Jid from, Jid to, string call_id, bool video, Gee.List<StanzaNode> join_methods, MessageStanza message);
- public signal void call_retracted(Jid from, Jid to, string call_id, string message_type);
- public signal void call_accepted(Jid from, Jid to, string call_id, string message_type);
- public signal void call_rejected(Jid from, Jid to, string call_id, string message_type);
- public signal void call_left(Jid from, Jid to, string call_id, string message_type);
-
- public void send_jingle_propose(XmppStream stream, string call_id, Jid invitee, string sid, bool video) {
- StanzaNode jingle_node = new StanzaNode.build("jingle", CallInvites.NS_URI)
- .put_attribute("sid", sid);
- send_propose(stream, call_id, invitee, jingle_node, video, false, MessageStanza.TYPE_CHAT);
- }
-
- public void send_muji_propose(XmppStream stream, string call_id, Jid invitee, Jid muc_jid, bool video, string message_type) {
- StanzaNode muji_node = new StanzaNode.build("muji", Muji.NS_URI).add_self_xmlns()
- .put_attribute("room", muc_jid.to_string());
- send_propose(stream, call_id, invitee, muji_node, video, true, message_type);
- }
-
- private void send_propose(XmppStream stream, string call_id, Jid invitee, StanzaNode inner_node, bool video, bool multiparty, string message_type) {
- StanzaNode invite_node = new StanzaNode.build("propose", NS_URI).add_self_xmlns()
- .put_attribute("id", call_id)
- .put_attribute("video", video.to_string())
- .put_attribute("multi", multiparty.to_string())
- .put_node(inner_node);
- MessageStanza invite_message = new MessageStanza() { to=invitee, type_=message_type };
- MessageProcessingHints.set_message_hint(invite_message, MessageProcessingHints.HINT_STORE);
- invite_message.stanza.put_node(invite_node);
- stream.get_module(MessageModule.IDENTITY).send_message.begin(stream, invite_message);
- }
-
- public void send_retract(XmppStream stream, Jid to, string call_id, string message_type) {
- send_message(stream, to, call_id, "retract", "cancel", message_type);
- }
-
- public void send_accept(XmppStream stream, Jid inviter, string call_id, StanzaNode? inner_node, string message_type) {
- StanzaNode accept_node = new StanzaNode.build("accept", NS_URI).add_self_xmlns()
- .put_attribute("id", call_id);
- if (inner_node != null) accept_node.put_node(inner_node);
- MessageStanza invite_message = new MessageStanza() { to=inviter, type_=message_type };
- MessageProcessingHints.set_message_hint(invite_message, MessageProcessingHints.HINT_STORE);
- invite_message.stanza.put_node(accept_node);
- stream.get_module(MessageModule.IDENTITY).send_message.begin(stream, invite_message);
- }
-
- public void send_reject(XmppStream stream, Jid to, string call_id, string message_type) {
- send_message(stream, to, call_id, "reject", "busy", message_type);
- }
-
- public void send_finish(XmppStream stream, Jid to, string call_id, string message_type) {
- send_message(stream, to, call_id, "finish", "success", message_type);
- }
-
- private void send_message(XmppStream stream, Jid to, string call_id, string action, string? reason, string message_type) {
- StanzaNode inner_node = new StanzaNode.build(action, NS_URI).add_self_xmlns().put_attribute("id", call_id);
- if (reason != null) inner_node.put_node(new StanzaNode.build("reason", NS_URI).put_node(new StanzaNode.build(reason, NS_URI)));
- MessageStanza message = new MessageStanza() { to=to, type_=message_type };
- message.stanza.put_node(inner_node);
- MessageProcessingHints.set_message_hint(message, MessageProcessingHints.HINT_STORE);
- stream.get_module(MessageModule.IDENTITY).send_message.begin(stream, message);
- }
-
- private void on_received_message(XmppStream stream, MessageStanza message) {
- Xmpp.MessageArchiveManagement.MessageFlag? mam_flag = Xmpp.MessageArchiveManagement.MessageFlag.get_flag(message);
- if (mam_flag != null) return;
-
- StanzaNode? relevant_node = null;
-
- foreach (StanzaNode node in message.stanza.sub_nodes) {
- if (node.ns_uri == NS_URI) {
- relevant_node = node;
- break;
- }
- }
- if (relevant_node == null) return;
-
- string? call_id = relevant_node.get_attribute("id");
- if (call_id == null) return;
-
- if (relevant_node.name == "propose") {
- if (relevant_node.sub_nodes.is_empty) return;
-
- // If there's also a JMI node, just use that one instead.
- foreach (StanzaNode node in message.stanza.sub_nodes) {
- if (node.ns_uri == JingleMessageInitiation.NS_URI) return;
- }
-
- bool video = relevant_node.get_attribute_bool("video", false);
- call_proposed(message.from, message.to, call_id, video, relevant_node.sub_nodes, message);
- return;
- }
-
- switch (relevant_node.name) {
- case "accept":
- call_accepted(message.from, message.to, call_id, message.type_);
- break;
- case "retract":
- call_retracted(message.from, message.to, call_id, message.type_);
- break;
- case "reject":
- call_rejected(message.from, message.to, call_id, message.type_);
- break;
- case "finish":
- call_left(message.from, message.to, call_id, message.type_);
- break;
- }
- }
-
- public override void attach(XmppStream stream) {
- stream.get_module(MessageModule.IDENTITY).received_message.connect(on_received_message);
- }
-
- public override void detach(XmppStream stream) {
- stream.get_module(MessageModule.IDENTITY).received_message.disconnect(on_received_message);
- }
-
- public override string get_ns() { return NS_URI; }
- public override string get_id() { return IDENTITY.id; }
- }
-} \ No newline at end of file
diff --git a/xmpp-vala/src/module/xep/0482_call_invites.vala b/xmpp-vala/src/module/xep/0482_call_invites.vala
new file mode 100644
index 00000000..69980d7f
--- /dev/null
+++ b/xmpp-vala/src/module/xep/0482_call_invites.vala
@@ -0,0 +1,187 @@
+using Gee;
+namespace Xmpp.Xep.CallInvites {
+
+ public const string NS_URI = "urn:xmpp:call-invites:0";
+ public const string NS_URI_CUSTOM = "urn:xmpp:call-message:1";
+
+ public class Module : XmppStreamModule {
+ public static ModuleIdentity<Module> IDENTITY = new ModuleIdentity<Module>(NS_URI, "call_invites");
+
+ public signal void call_proposed(Jid from, Jid to, string call_id, bool video, Gee.List<StanzaNode> join_methods, MessageStanza message);
+ public signal void call_retracted(Jid from, Jid to, string call_id, string message_type);
+ public signal void call_accepted(Jid from, Jid to, string call_id, string message_type);
+ public signal void call_rejected(Jid from, Jid to, string call_id, string message_type);
+ public signal void call_left(Jid from, Jid to, string call_id, string message_type);
+
+ public void send_jingle_propose(XmppStream stream, string call_id, Jid invitee, string sid, bool video) {
+ MessageStanza invite_message = new MessageStanza() { to=invitee, type_=MessageStanza.TYPE_CHAT };
+ invite_message.stanza.put_node(
+ new StanzaNode.build("invite", NS_URI).add_self_xmlns()
+ .put_attribute("id", call_id)
+ .put_attribute("video", video.to_string())
+ .put_attribute("multi", false.to_string())
+ .put_node(new StanzaNode.build("jingle", CallInvites.NS_URI).put_attribute("sid", sid))
+ );
+ invite_message.stanza.put_node( // Custom legacy protocol
+ new StanzaNode.build("propose", NS_URI_CUSTOM).add_self_xmlns()
+ .put_attribute("id", call_id)
+ .put_attribute("video", video.to_string())
+ .put_attribute("multi", false.to_string())
+ .put_node(new StanzaNode.build("jingle", CallInvites.NS_URI_CUSTOM).put_attribute("sid", sid))
+ );
+ MessageProcessingHints.set_message_hint(invite_message, MessageProcessingHints.HINT_STORE);
+ stream.get_module(MessageModule.IDENTITY).send_message.begin(stream, invite_message);
+ }
+
+ public void send_muji_propose(XmppStream stream, string call_id, Jid invitee, Jid muc_jid, bool video, string message_type) {
+ MessageStanza invite_message = new MessageStanza() { to=invitee, type_=MessageStanza.TYPE_CHAT };
+ invite_message.stanza.put_node(
+ new StanzaNode.build("invite", NS_URI).add_self_xmlns()
+ .put_attribute("id", call_id)
+ .put_attribute("video", video.to_string())
+ .put_attribute("multi", false.to_string())
+ .put_node(new StanzaNode.build("muji", Muji.NS_URI).add_self_xmlns().put_attribute("room", muc_jid.to_string()))
+ );
+ invite_message.stanza.put_node( // Custom legacy protocol
+ new StanzaNode.build("propose", NS_URI_CUSTOM).add_self_xmlns()
+ .put_attribute("id", call_id)
+ .put_attribute("video", video.to_string())
+ .put_attribute("multi", false.to_string())
+ .put_node(new StanzaNode.build("muji", Muji.NS_URI).add_self_xmlns().put_attribute("room", muc_jid.to_string()))
+ );
+ MessageProcessingHints.set_message_hint(invite_message, MessageProcessingHints.HINT_STORE);
+ stream.get_module(MessageModule.IDENTITY).send_message.begin(stream, invite_message);
+ }
+
+ public void send_jingle_accept(XmppStream stream, Jid inviter, string call_id, string sid, string message_type) {
+ StanzaNode accept_node = new StanzaNode.build("accept", NS_URI).add_self_xmlns().put_attribute("id", call_id)
+ .put_node(new StanzaNode.build("jingle", NS_URI).put_attribute("sid", sid));
+
+ // Custom legacy protocol
+ StanzaNode custom_accept_node = new StanzaNode.build("accept", NS_URI_CUSTOM).add_self_xmlns().put_attribute("id", call_id)
+ .put_node(new StanzaNode.build("jingle", NS_URI_CUSTOM).put_attribute("sid", sid));
+
+ MessageStanza invite_message = new MessageStanza() { to=inviter, type_=message_type };
+ MessageProcessingHints.set_message_hint(invite_message, MessageProcessingHints.HINT_STORE);
+ invite_message.stanza.put_node(accept_node);
+ invite_message.stanza.put_node(custom_accept_node);
+ stream.get_module(MessageModule.IDENTITY).send_message.begin(stream, invite_message);
+ }
+
+ public void send_muji_accept(XmppStream stream, Jid inviter, string call_id, Jid room, string message_type) {
+ StanzaNode accept_node = new StanzaNode.build("accept", NS_URI).add_self_xmlns().put_attribute("id", call_id)
+ .put_node(new StanzaNode.build("muji", Xep.Muji.NS_URI).add_self_xmlns().put_attribute("room", room.to_string()));
+
+ // Custom legacy protocol
+ StanzaNode custom_accept_node = new StanzaNode.build("accept", NS_URI_CUSTOM).add_self_xmlns().put_attribute("id", call_id)
+ .put_node(new StanzaNode.build("muji", Xep.Muji.NS_URI).add_self_xmlns().put_attribute("room", room.to_string()));
+
+ MessageStanza invite_message = new MessageStanza() { to=inviter, type_=message_type };
+ MessageProcessingHints.set_message_hint(invite_message, MessageProcessingHints.HINT_STORE);
+ invite_message.stanza.put_node(accept_node);
+ invite_message.stanza.put_node(custom_accept_node);
+ stream.get_module(MessageModule.IDENTITY).send_message.begin(stream, invite_message);
+ }
+
+ public void send_retract(XmppStream stream, Jid to, string call_id, string message_type) {
+ send_message(stream, to, call_id, "retract", message_type);
+ }
+
+ public void send_reject(XmppStream stream, Jid to, string call_id, string message_type) {
+ send_message(stream, to, call_id, "reject", message_type);
+ }
+
+ public void send_left(XmppStream stream, Jid to, string call_id, string message_type) {
+ MessageStanza message = new MessageStanza() { to=to, type_=message_type };
+
+ StanzaNode inner_node = new StanzaNode.build("left", NS_URI).add_self_xmlns().put_attribute("id", call_id);
+ message.stanza.put_node(inner_node);
+
+ // Custom legacy protocol
+ StanzaNode custom_node = new StanzaNode.build("finish", NS_URI_CUSTOM).add_self_xmlns().put_attribute("id", call_id);
+ message.stanza.put_node(custom_node);
+
+ MessageProcessingHints.set_message_hint(message, MessageProcessingHints.HINT_STORE);
+ stream.get_module(MessageModule.IDENTITY).send_message.begin(stream, message);
+ }
+
+ private void send_message(XmppStream stream, Jid to, string call_id, string action, string message_type) {
+ MessageStanza message = new MessageStanza() { to=to, type_=message_type };
+
+ StanzaNode inner_node = new StanzaNode.build(action, NS_URI).add_self_xmlns().put_attribute("id", call_id);
+ message.stanza.put_node(inner_node);
+
+ // Custom legacy protocol
+ StanzaNode custom_node = new StanzaNode.build(action, NS_URI_CUSTOM).add_self_xmlns().put_attribute("id", call_id);
+ message.stanza.put_node(custom_node);
+
+ MessageProcessingHints.set_message_hint(message, MessageProcessingHints.HINT_STORE);
+ stream.get_module(MessageModule.IDENTITY).send_message.begin(stream, message);
+ }
+
+ private void on_received_message(XmppStream stream, MessageStanza message) {
+ Xmpp.MessageArchiveManagement.MessageFlag? mam_flag = Xmpp.MessageArchiveManagement.MessageFlag.get_flag(message);
+ if (mam_flag != null) return;
+
+ StanzaNode? relevant_node = null;
+
+ foreach (StanzaNode node in message.stanza.sub_nodes) {
+ if (node.ns_uri == NS_URI) {
+ relevant_node = node;
+ break;
+ }
+ }
+ if (relevant_node == null) {
+ foreach (StanzaNode node in message.stanza.sub_nodes) {
+ if (node.ns_uri == NS_URI_CUSTOM) {
+ relevant_node = node;
+ break;
+ }
+ }
+ }
+ if (relevant_node == null) return;
+
+ string? call_id = relevant_node.get_attribute("id");
+ if (call_id == null) return;
+
+ if (relevant_node.name == "invite" || /* custom legacy */relevant_node.name == "propose") {
+ if (relevant_node.sub_nodes.is_empty) return;
+
+ // If there's also a JMI node, just use that one instead.
+ foreach (StanzaNode node in message.stanza.sub_nodes) {
+ if (node.ns_uri == JingleMessageInitiation.NS_URI) return;
+ }
+
+ bool video = relevant_node.get_attribute_bool("video", false);
+ call_proposed(message.from, message.to, call_id, video, relevant_node.sub_nodes, message);
+ return;
+ }
+
+ switch (relevant_node.name) {
+ case "accept":
+ call_accepted(message.from, message.to, call_id, message.type_);
+ break;
+ case "retract":
+ call_retracted(message.from, message.to, call_id, message.type_);
+ break;
+ case "reject":
+ call_rejected(message.from, message.to, call_id, message.type_);
+ break;
+ case "finish":
+ call_left(message.from, message.to, call_id, message.type_);
+ break;
+ }
+ }
+
+ public override void attach(XmppStream stream) {
+ stream.get_module(MessageModule.IDENTITY).received_message.connect(on_received_message);
+ }
+
+ public override void detach(XmppStream stream) {
+ stream.get_module(MessageModule.IDENTITY).received_message.disconnect(on_received_message);
+ }
+
+ public override string get_ns() { return NS_URI; }
+ public override string get_id() { return IDENTITY.id; }
+ }
+} \ No newline at end of file