Forced messages broadcast to all connected resources with Prosody Jabber server

My PC (serving also as NAS, HTPC, music player...) is turned on 24/7. So I'm nonstop logged into my jabber server from this PC. Even when I'm away. I own Nokia N900 and I have purchased celluar data program so I'm logging into jabber via this smartphone when I am away from PC.

XMPP handles multiple connected resources via resource priority routing. So the initial message will be delivered to resource with lower priority number (lower integer value = higher priority where 0 is the highest priority) or to all resources if you have set ignore_presence_priority in config (in case you are using Prosody Jabber server like me). But if you reply to message, client on the other side will be propably replying directly to resource from which you replied until you write or reply from another resource. So messages are delivered only to the one resource and you must manually switch resource by sending message from different one. There is a chance you'll miss some messages with this behaviour (they will be delivered to another resource you used before). Or maybe there is a buggy client on the other side which can't handle resources in standard way.

This could be solved by XEP-0280 unfortunately this feature isn't supported by clients yet. So this is why I decided to ask on channel.

Solution which I got was hacky module written by MattJ (many thanks to him). This module forces messages to be broadcasted to all connected resources. Hack rating (4/5) described in comment means this module breaks proper XMPP routing and also it's better to restart Prosody server if you are using it (not to reload only). This cons aren't very important for me because I always restart my Prosody Jabber server when I am changing something. And broken XMPP routing in that way is what I want. :P

Source code of module:

-- mod_message_forced_broadcast
-- Broadcast incoming messages to all resources with the highest
-- priority, regardless of whether they were addressed to a
-- specific resource.
-- You probably want to set ignore_presence_priority = true
-- in the config file as well.
-- Module hack rating: 4/5.
local jid_bare = require "util.jid".bare;
local process_to_bare;
module:hook("message/full", function(data)
        local origin, stanza = data.origin, data.stanza;
        local type = stanza.attr.type;
        if type == "chat" or type == "headline" then -- Broadcast instead
                return process_to_bare(jid_bare(, origin, stanza);
end, 0.9);"server-started", function () -- COMPAT w/0.8-: Switch to module:global_hook()
        local message_full_handler = next(modulemanager.unload.hooks:get(,'message')['message/full']);
        process_to_bare = message_full_handler.process_to_bare;

So what we will need to make this work?

Download the mod_message_forced_broadcast.lua module and save it to /usr/lib/prosody/modules (on Debian GNU/Linux OS)

 ... then add
ignore_presence_priority = true
to your config.

 ... then add
to modules_enabled block.

 ... and restart Prosody Jabber server

Enjoy ;-)

author: (Jaroslav Petráš)

date: Tue, 18 Oct 2011 17:19:57 +0000