Software /
code /
prosody-modules
Comparison
mod_cloud_notify/mod_cloud_notify.lua @ 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 |
parent | 4718:6e3254e13fb7 |
child | 4827:fe5303da99cb |
comparison
equal
deleted
inserted
replaced
4729:fae4e1335593 | 4730:1da4b815d2fe |
---|---|
251 end | 251 end |
252 return true; | 252 return true; |
253 end | 253 end |
254 module:hook("iq-set/self/"..xmlns_push..":disable", push_disable); | 254 module:hook("iq-set/self/"..xmlns_push..":disable", push_disable); |
255 | 255 |
256 -- urgent stanzas should be delivered without delay | |
257 local function is_urgent(stanza) | |
258 -- TODO | |
259 if stanza.name == "message" then | |
260 if stanza:get_child("propose", "urn:xmpp:jingle-message:0") then | |
261 return true, "jingle call"; | |
262 end | |
263 end | |
264 end | |
265 | |
256 -- is this push a high priority one (this is needed for ios apps not using voip pushes) | 266 -- is this push a high priority one (this is needed for ios apps not using voip pushes) |
257 local function is_important(stanza) | 267 local function is_important(stanza) |
258 local st_name = stanza and stanza.name or nil; | 268 local st_name = stanza and stanza.name or nil; |
259 if not st_name then return false; end -- nonzas are never important here | 269 if not st_name then return false; end -- nonzas are never important here |
260 if st_name == "presence" then | 270 if st_name == "presence" then |
526 | 536 |
527 -- only notify if the stanza destination is the mam user we store it for | 537 -- only notify if the stanza destination is the mam user we store it for |
528 if event.for_user == to then | 538 if event.for_user == to then |
529 local user_push_services = push_store:get(to); | 539 local user_push_services = push_store:get(to); |
530 | 540 |
531 -- only notify nodes with no active sessions (smacks is counted as active and handled separate) | 541 -- Urgent stanzas are time-sensitive (e.g. calls) and should |
532 local notify_push_services = {}; | 542 -- be pushed immediately to avoid getting stuck in the smacks |
533 for identifier, push_info in pairs(user_push_services) do | 543 -- queue in case of dead connections, for example |
534 local identifier_found = nil; | 544 local is_urgent_stanza, urgent_reason = is_urgent(event.stanza); |
535 for _, session in pairs(user_session) do | 545 |
536 if session.push_identifier == identifier then | 546 local notify_push_services; |
537 identifier_found = session; | 547 if is_urgent_stanza then |
538 break; | 548 module:log("debug", "Urgent push for %s (%s)", to, urgent_reason); |
549 notify_push_services = user_push_services; | |
550 else | |
551 -- only notify nodes with no active sessions (smacks is counted as active and handled separate) | |
552 notify_push_services = {}; | |
553 for identifier, push_info in pairs(user_push_services) do | |
554 local identifier_found = nil; | |
555 for _, session in pairs(user_session) do | |
556 if session.push_identifier == identifier then | |
557 identifier_found = session; | |
558 break; | |
559 end | |
539 end | 560 end |
540 end | 561 if identifier_found then |
541 if identifier_found then | 562 identifier_found.log("debug", "Not cloud notifying '%s' of new MAM stanza (session still alive)", identifier); |
542 identifier_found.log("debug", "Not cloud notifying '%s' of new MAM stanza (session still alive)", identifier); | 563 else |
543 else | 564 notify_push_services[identifier] = push_info; |
544 notify_push_services[identifier] = push_info; | 565 end |
545 end | 566 end |
546 end | 567 end |
547 | 568 |
548 handle_notify_request(event.stanza, to, notify_push_services, true); | 569 handle_notify_request(event.stanza, to, notify_push_services, true); |
549 end | 570 end |