From 16ae290d9b05778ef470adabb5fd72a8c36ad2c0 Mon Sep 17 00:00:00 2001 From: lazedo Date: Thu, 22 Jun 2017 18:23:34 +0100 Subject: [PATCH] KAZOO-5581 add unique subscribers --- kamailio/nodes-role.cfg | 9 +++++++-- kamailio/presence-role.cfg | 13 +++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/kamailio/nodes-role.cfg b/kamailio/nodes-role.cfg index 04c88a2..534a073 100644 --- a/kamailio/nodes-role.cfg +++ b/kamailio/nodes-role.cfg @@ -45,13 +45,18 @@ route[NODES_ADVERTISE_ROUTE] #!ifdef PRESENCE_ROLE route(COUNT_ALL_SUBSCRIBERS); $var(Subscriptions) = $_s("Subscriptions" : {"message-summary" : $xavp(watchers=>message-summary), "dialog" : $xavp(watchers=>dialog), "presence" : $xavp(watchers=>presence)}); + route(COUNT_ALL_PRESENTITIES); $var(Presentities) = $_s("Presentities" : {"message-summary" : $xavp(watchers=>message-summary), "dialog" : $xavp(watchers=>dialog), "presence" : $xavp(watchers=>presence)}); - $var(Presence) = $_s("Presence" : {$var(Subscriptions), $var(Presentities)}); + + route(COUNT_UNIQUE_SUBSCRIBERS); + $var(Subscribers) = $_s("Subscribers" : {"message-summary" : $xavp(watchers=>message-summary), "dialog" : $xavp(watchers=>dialog), "presence" : $xavp(watchers=>presence)}); + + $var(Presence) = $_s("Presence" : {$var(Subscribers), $var(Subscriptions), $var(Presentities)}); #!else $var(Presence) = ""; #!endif - + $var(Roles) = $_s("Roles" : {$var(Dispatcher), $var(Presence) , $var(Registrar)}); $var(Payload) = '{"Event-Category" : "nodes", "Event-Name" : "advertise", "Expires" : 5000, "Used-Memory" : $(stat(real_used_size){s.int}), "Startup" : $Tb, "XWhApps" : {"kamailio" : {"Startup" : $Tb }}, $var(Roles)}'; kazoo_publish("nodes", "", $var(Payload)); diff --git a/kamailio/presence-role.cfg b/kamailio/presence-role.cfg index c928021..08705c9 100644 --- a/kamailio/presence-role.cfg +++ b/kamailio/presence-role.cfg @@ -235,6 +235,19 @@ route[COUNT_SUBSCRIBERS] xavp_params_explode($var(p), "watchers"); } +route[COUNT_UNIQUE_SUBSCRIBERS] +{ + $var(Query) = $_s(select event, (select count(distinct watcher_username || "@" || watcher_domain) from active_watchers b where b.event = a.event) count from event_list a); + $var(p) = "uri=none"; + if (sql_xquery("cb", "$var(Query)", "subs") == 1) + { + while($xavp(subs) != $null) { + $var(p) = $var(p) + ";" + $xavp(subs=>event) + "=" + $xavp(subs=>count); + pv_unset("$xavp(subs)"); + } + } + xavp_params_explode($var(p), "watchers"); +} event_route[kazoo:consumer-event-presence-dialog-update] {