# HG changeset patch # User Matthew Wild # Date 1613999495 0 # Node ID 8ed1989e99f95f3b931b9a6a1c17cd6e902e5a2f # Parent 89e54247ade6ff436a77678fed25f0a853a7a2f3 mod_cloud_notify_encrypted: Update to latest spec, fixes unreliable call notifications diff -r 89e54247ade6 -r 8ed1989e99f9 mod_cloud_notify_encrypted/mod_cloud_notify_encrypted.lua --- a/mod_cloud_notify_encrypted/mod_cloud_notify_encrypted.lua Sun Feb 21 16:15:21 2021 +0100 +++ b/mod_cloud_notify_encrypted/mod_cloud_notify_encrypted.lua Mon Feb 22 13:11:35 2021 +0000 @@ -1,8 +1,10 @@ +local array = require "util.array"; local base64 = require "util.encodings".base64; local ciphers = require "openssl.cipher"; local jid = require "util.jid"; local json = require "util.json"; local random = require "util.random"; +local set = require "util.set"; local st = require "util.stanza"; local xmlns_jmi = "urn:xmpp:jingle-message:0"; @@ -76,6 +78,14 @@ if jmi_propose then push_payload.type = "call"; push_payload.sid = jmi_propose.attr.id; + local media_types = set.new(); + for description in jmi_propose:childtags("description") do + local media_type = description.attr.media; + if media_type then + media_types:add(media_type); + end + end + push_payload.media = array.collect(media_types:items()); else push_payload.type = "chat"; end @@ -94,6 +104,10 @@ local encrypted_payload = base64.encode(ciphers.new("AES-128-GCM"):encrypt(key_binary, iv):final(push_json)..string.rep("\0", 16)); local encrypted_element = st.stanza("encrypted", { xmlns = xmlns_push_encrypt, iv = base64.encode(iv) }) :text(encrypted_payload); + if push_payload.type == "call" then + encrypted_payload.attr.type = "voip"; + event.important = true; + end -- Replace the unencrypted notification data with the encrypted one event.notification_payload :remove_children("x", "jabber:x:data") @@ -101,4 +115,4 @@ end module:hook("cloud_notify/registration", handle_register); -module:hook("cloud_notify/push", handle_push); +module:hook("cloud_notify/push", handle_push, 1);