changeset 4730:1da4b815d2fe

mod_cloud_notify: Identify (and immediately push) urgent stanzas, e.g. calls This covers the following things: - A session that appears online, but has a broken TCP connection - Clients such as Siskin and Snikket iOS that require a push for calls to work It allows the stanza to be pushed immediately instead of waiting for the session to hibernate or an ack to timeout. It shouldn't break any existing cases.
author Matthew Wild <mwild1@gmail.com>
date Wed, 27 Oct 2021 19:12:03 +0100
parents fae4e1335593
children d71beacaec3b
files mod_cloud_notify/mod_cloud_notify.lua
diffstat 1 files changed, 34 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/mod_cloud_notify/mod_cloud_notify.lua	Wed Oct 27 14:07:07 2021 +0200
+++ b/mod_cloud_notify/mod_cloud_notify.lua	Wed Oct 27 19:12:03 2021 +0100
@@ -253,6 +253,16 @@
 end
 module:hook("iq-set/self/"..xmlns_push..":disable", push_disable);
 
+-- urgent stanzas should be delivered without delay
+local function is_urgent(stanza)
+	-- TODO
+	if stanza.name == "message" then
+		if stanza:get_child("propose", "urn:xmpp:jingle-message:0") then
+			return true, "jingle call";
+		end
+	end
+end
+
 -- is this push a high priority one (this is needed for ios apps not using voip pushes)
 local function is_important(stanza)
 	local st_name = stanza and stanza.name or nil;
@@ -528,20 +538,31 @@
 	if event.for_user == to then
 		local user_push_services = push_store:get(to);
 
-		-- only notify nodes with no active sessions (smacks is counted as active and handled separate)
-		local notify_push_services = {};
-		for identifier, push_info in pairs(user_push_services) do
-			local identifier_found = nil;
-			for _, session in pairs(user_session) do
-				if session.push_identifier == identifier then
-					identifier_found = session;
-					break;
+		-- Urgent stanzas are time-sensitive (e.g. calls) and should
+		-- be pushed immediately to avoid getting stuck in the smacks
+		-- queue in case of dead connections, for example
+		local is_urgent_stanza, urgent_reason = is_urgent(event.stanza);
+
+		local notify_push_services;
+		if is_urgent_stanza then
+			module:log("debug", "Urgent push for %s (%s)", to, urgent_reason);
+			notify_push_services = user_push_services;
+		else
+			-- only notify nodes with no active sessions (smacks is counted as active and handled separate)
+			notify_push_services = {};
+			for identifier, push_info in pairs(user_push_services) do
+				local identifier_found = nil;
+				for _, session in pairs(user_session) do
+					if session.push_identifier == identifier then
+						identifier_found = session;
+						break;
+					end
 				end
-			end
-			if identifier_found then
-				identifier_found.log("debug", "Not cloud notifying '%s' of new MAM stanza (session still alive)", identifier);
-			else
-				notify_push_services[identifier] = push_info;
+				if identifier_found then
+					identifier_found.log("debug", "Not cloud notifying '%s' of new MAM stanza (session still alive)", identifier);
+				else
+					notify_push_services[identifier] = push_info;
+				end
 			end
 		end