Browse Source

update presence handling

4.3
lazedo 7 years ago
committed by Luis Azedo
parent
commit
3fba5c0dc7
2 changed files with 18 additions and 45 deletions
  1. +4
    -5
      kamailio/db_queries_kazoo.cfg
  2. +14
    -40
      kamailio/presence-role.cfg

+ 4
- 5
kamailio/db_queries_kazoo.cfg View File

@ -3,8 +3,7 @@
#!substdef "!KZQ_COUNT_ALL_SUBSCRIBERS!select a.event, count(distinct watcher_uri) count_unique, count(*) count from event_list a left outer join active_watchers b on a.event = b.event group by a.event!g"
#!substdef "!KZQ_COUNT_PRESENTITIES!select event, (select count(*) from presentity b where username = \"\$(var(payload){kz.json,From}{uri.user})\" and domain = \"\$(var(payload){kz.json,From}{uri.domain})\" and b.event = a.event) count from event_list a!g"
#!substdef "!KZQ_COUNT_SUBSCRIBERS!select event, (select count(*) from active_watchers b where presentity_uri = \"\$var(presentity)\" and b.event = a.event) count from event_list a union all select \"self\", count(distinct callid) from presentities where presentity_uri = \"\$var(presentity)\" and callid <> \"\$var(callid)\" and state in('early', 'confirmed', 'onthephone', 'busy')!g"
#!substdef "!KZQ_FETCH_PRESENCE!select * from presentities where presentity_uri = \"\$var(presentity)\" and event = \"presence\"!g"
#!substdef "!KZQ_COUNT_SUBSCRIBERS!select event, (select count(*) from active_watchers b where presentity_uri = \"\$var(presentity)\" and b.event = a.event) count from event_list a union all select \"self\", count(distinct callid) from presentities where presentity_uri = \"\$var(presentity)\" and callid <> \"\$var(callid)\" and state in('early', 'confirmed', 'onthephone', 'busy', 'ringing')!g"
#!substdef "!KZQ_EVENT_PRESENCE_RESET_DELETE!delete from presentity where domain=\"\$(kzE{kz.json,Realm})\" and username = \"\$(kzE{kz.json,Username})\"!g"
#!substdef "!KZQ_HANDLE_NEW_SUBSCRIBE_DELETE1!delete from active_watchers where callid = \"\$ci\"!g"
@ -17,12 +16,12 @@
#!substdef "!KZQ_REPLACE_WATCHERS_LOG!REPLACE INTO active_watchers_log (presentity_uri, watcher_username, watcher_domain, event, callid, to_user, to_domain, user_agent, time, result, sent_msg, received_msg) VALUES (\"\$subs(uri)\", \"\$subs(watcher_username)\", \"\$subs(watcher_domain)\", \"\$subs(event)\",\"\$subs(callid)\",\"\$subs(to_user)\",\"\$subs(to_domain)\", '\$(subs(user_agent){s.escape.common}{s.replace,\\\',''}{s.replace,\$\$,})', \$TS, \$notify_reply(\$rs), '\$(mb{s.escape.common}{s.replace,\\\',''}{s.replace,\$\$,})', '\$(notify_reply(\$mb){s.escape.common}{s.replace,\\\',''}{s.replace,\$\$,})')!g"
# # #!substdef "!KZQ_RESET_PUBLISHER_UPDATE!update active_watchers set expires = \$TS where id in (select b.id from presentity a inner join active_watchers b on a.username = b.to_user and a.domain = b.to_domain and a.event = b.event where a.sender = \"\$var(MediaUrl)\")!g"
#!substdef "!KZQ_RESET_PUBLISHER_UPDATE!INSERT INTO tmp_probe select distinct a.event, a.presentity_uri, 0 from presentities a inner join active_watchers b on a.presentity_uri = b.presentity_uri and a.event = b.event where sender = \"\$var(MediaUrl)\" and state in('early', 'confirmed', 'onthephone', 'busy')!g"
#!substdef "!KZQ_RESET_PUBLISHER_UPDATE!INSERT INTO tmp_probe select distinct a.event, a.presentity_uri, 0 from presentities a inner join active_watchers b on a.presentity_uri = b.presentity_uri and a.event = b.event where sender = \"\$var(MediaUrl)\" and state in('early', 'confirmed', 'onthephone', 'busy', 'ringing')!g"
#!substdef "!KZQ_PRESENCE_RESET!delete from presentity where sender = \"\$var(MediaUrl)\"!g"
# # #!substdef "!KZQ_RESET_ACCOUNT_UPDATE!update active_watchers set expires = \$TS where watcher_domain=\"\$(kzE{kz.json,Realm})\"!g"
#!substdef "!KZQ_RESET_ACCOUNT_UPDATE!INSERT INTO tmp_probe select distinct a.event, a.presentity_uri, 0 from presentities a inner join active_watchers b on a.presentity_uri = b.presentity_uri and a.event = b.event where domain=\"\$(kzE{kz.json,Realm})\" and state in('early', 'confirmed', 'onthephone', 'busy')!g"
#!substdef "!KZQ_RESET_ACCOUNT_UPDATE!INSERT INTO tmp_probe select distinct a.event, a.presentity_uri, 0 from presentities a inner join active_watchers b on a.presentity_uri = b.presentity_uri and a.event = b.event where domain=\"\$(kzE{kz.json,Realm})\" and state in('early', 'confirmed', 'onthephone', 'busy', 'ringing')!g"
#!substdef "!KZQ_RESET_ACCOUNT_RESET!delete from presentity where domain=\"\$(kzE{kz.json,Realm})\"!g"
#!substdef "!KZQ_RESET_PUBLISHER_ZONE_UPDATE!INSERT INTO tmp_probe select distinct a.event, a.presentity_uri, 0 from presentities a inner join wdispatcher c on a.sender = c.destination inner join active_watchers b on a.presentity_uri = b.presentity_uri and a.event = b.event where zone = \"\$var(Zone)\" and state in('early', 'confirmed', 'onthephone', 'busy')!g"
#!substdef "!KZQ_RESET_PUBLISHER_ZONE_UPDATE!INSERT INTO tmp_probe select distinct a.event, a.presentity_uri, 0 from presentities a inner join wdispatcher c on a.sender = c.destination inner join active_watchers b on a.presentity_uri = b.presentity_uri and a.event = b.event where zone = \"\$var(Zone)\" and state in('early', 'confirmed', 'onthephone', 'busy', 'ringing')!g"
#!substdef "!KZQ_PRESENCE_ZONE_RESET!delete from presentity where id in(select a.id from presentities a join wdispatcher c on a.sender = c.destination where zone = \"\$var(Zone)\")!g"

+ 14
- 40
kamailio/presence-role.cfg View File

@ -355,21 +355,6 @@ route[COUNT_SUBSCRIBERS]
xavp_params_explode($var(p), "watchers");
}
route[PRESENCE_STATE]
{
$var(state) = "";
if($(var(payload){kz.json,State}) == "terminated") {
$var(state) = "available";
} else if($(var(payload){kz.json,State}) == "early") {
$var(state) = "busy";
} else if($(var(payload){kz.json,State}) == "confirmed") {
$var(state) = "onthephone";
}
$var(Query) = $_s(KZQ_FETCH_PRESENCE);
sql_xquery("cb", "$var(Query)", "presence");
}
event_route[kazoo:consumer-event-presence-dialog-update]
{
$var(kz_presence_log_level) = $(sel(cfg_get.kazoo.presence_no_targets_log_level){s.int});
@ -498,36 +483,25 @@ route[PRESENCE_UPDATE]
}
if($xavp(watchers=>presence) > 0) {
route(PRESENCE_STATE);
xlog("L_DEBUG", "presence state => $(var(payload){kz.json,Call-ID})|log|$xavp(presence=>callid) , $var(callid), $xavp(presence=>state), $var(state)\n");
if($xavp(presence=>callid) == $var(callid)
|| $var(state) == "onthephone"
|| ($var(state) == "busy" && $xavp(presence=>state) != "onthephone")
) {
$var(kz_presence_log_level) = $(sel(cfg_get.kazoo.presence_with_targets_log_level){s.int});
$var(kz_presence_log_level) = $(sel(cfg_get.kazoo.presence_with_targets_log_level){s.int});
if($(var(payload){kz.json,State}) == "terminated") {
xlog("L_DEBUG", "$(var(payload){kz.json,Call-ID})|log|publishing $var(presentity) presence update for terminated dialog\n");
} else {
xlog("L_DEBUG", "$(var(payload){kz.json,Call-ID})|log|publishing $var(presentity) presence update for $xavp(watchers=>presence) watchers\n");
if(kazoo_pua_publish_presence($var(JObj)) == 1) {
pres_refresh_watchers("$var(presentity)", "presence", 1);
} else {
xlog("L_ERR", "$(var(payload){kz.json,Call-ID})|log|error publishing $var(presentity) presence update\n");
};
}
if(kazoo_pua_publish_presence($var(JObj)) == 1) {
pres_refresh_watchers("$var(presentity)", "presence", 1);
} else {
xlog("L_ERR", "$(var(payload){kz.json,Call-ID})|log|error publishing $var(presentity) presence update\n");
};
} else {
#!ifdef PRESENCE_TRACK_ALL_PKG_PRESENCE
if($(kzE{kz.json,Event-Package}) == "presence") {
route(PRESENCE_STATE);
xlog("L_DEBUG", "presence state => $(var(payload){kz.json,Call-ID})|log|$xavp(presence=>callid) , $var(callid), $xavp(presence=>state), $var(state)\n");
if($xavp(presence=>callid) == $var(callid)
|| $var(state) == "onthephone"
|| ($var(state) == "busy" && $xavp(presence=>state) != "onthephone")
) {
$var(kz_presence_log_level) = $(sel(cfg_get.kazoo.presence_with_targets_log_level){s.int});
xlog("L_DEBUG", "$(var(payload){kz.json,Call-ID})|log|saving $var(presentity) from presence update => $var(payload)\n");
if(kazoo_pua_publish_presence($var(JObj)) != 1) {
xlog("L_ERR", "$(var(payload){kz.json,Call-ID})|log|error publishing $var(presentity) presence update => $var(payload)\n");
}
}
$var(kz_presence_log_level) = $(sel(cfg_get.kazoo.presence_with_targets_log_level){s.int});
xlog("L_DEBUG", "$(var(payload){kz.json,Call-ID})|log|saving $var(presentity) from presence update => $var(payload)\n");
if(kazoo_pua_publish_presence($var(JObj)) != 1) {
xlog("L_ERR", "$(var(payload){kz.json,Call-ID})|log|error publishing $var(presentity) presence update => $var(payload)\n");
}
}
#!else
xlog("L_DEBUG", "$(var(payload){kz.json,Call-ID})|log|skip presence update for $var(presentity)\n");


Loading…
Cancel
Save