mod_presence

Show who is viewing a shared location using browser presence messages. Enable mod_presence on the site; no module configuration keys are required. The widgets use Zotonic's widget initialization and Cotonic broker bridge.

Template usage

Load the widgets and give both widgets the same location identifier:

{% lib "js/modules/z.presence.js" "js/modules/z.presenceview.js" %}
<span class="do_presence do_presenceview" data-presence-where="foo"></span>

do_presence publishes the current browser's status. do_presenceview displays the users at that location and can be used on its own. The viewer also accepts data-presenceview-where. Locations are client-chosen strings. The module includes the scripts in the admin and adds presence indicators for resource editing and overview lists using mod_admin/<resource-id>. Override _presence_user.tpl to customize the user-name fragment.

Messages and display

The publisher sends QoS 0 messages on bridge/origin/presence/status/<where> with user_id, a browser-widget unique_id, where and numeric status. Viewers request an update on bridge/origin/presence/request/<where>. The publisher checks activity each second and sends on changes or when more than seven seconds have elapsed.

Status codes are 0 gone, 1 away, 2 idle, 3 present and 4 active. Activity ages through thresholds of 10, 60 and 300 seconds; page lifecycle and element removal also feed status changes. Viewers sort by status, hide gone entries and combine multiple entries for the same user. Present and active users use label-success, idle users label-info, and away users label-default. This is transient browser state, not a stored attendance log.

Topic permissions

The ACL observer handles non-wildcard topics starting with presence. For presence/<kind>/mod_<name>/..., it checks use permission for that module; an unknown module atom is denied. Other non-wildcard presence topics require authentication. These rules apply regardless of the MQTT action. Wildcard topics and unrelated ACL requests return undefined for other ACL handlers to decide. Presence payloads are supplied by clients; this observer checks topic access, not the identity fields in those payloads.

Observes

Notifications

observe_acl_is_allowed/2

Check if a user is authorized to perform an operation on a an object (some resource or module). Observe this notification to do complex or more fine-grained…