You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

42 lines
2.0 KiB

######## Presence sync server module ########
####### SQL OPS module ##########
#!ifndef SQLOPS-LOADED
loadmodule "sqlops.so"
modparam("sqlops","sqlcon", "cb=>KAZOO_DB_URL")
#!trydef SQLOPS-LOADED
#!endif
event_route[kazoo:consumer-event-presence-sync]
{
xlog("L_INFO", "received SYNC $kzE");
$var(Queue) = $(kzE{kz.json,Server-ID});
$var(Now) = $TS;
######## SEND BACK START ########
$var(amqp_payload_request) = '{"Event-Category" : "presence", "Event-Name" : "sync", "Action" : "Start" }';
kazoo_publish("targeted", "$var(Queue)", $var(amqp_payload_request));
if (sql_xquery("cb", "select * from active_watchers where expires > $var(Now)", "ra") == 1)
{
while($xavp(ra) != $null)
{
$var(runloop) = 1;
while($xavp(ra) != $null && $var(runloop) < MAX_WHILE_LOOPS ) {
xlog("L_INFO", "[id, presentity, watcher] = [$xavp(ra=>id), $xavp(ra=>presentity_uri), $xavp(ra=>watcher_username)]");
$var(Expires) = $xavp(ra=>expires) - $var(Now);
xlog("L_INFO", "EXPIRES $var(Expires) , $xavp(ra=>expires) , $var(Now)");
$var(amqp_payload_request) = '{"Event-Category" : "presence", "Event-Name" : "subscription", "Event-Package" : "$xavp(ra=>event)", "Expires" : $var(Expires), "Server-ID" : "BLF-MY_HOSTNAME" , "Contact" : "$xavp(ra=>contact)", "Call-ID" : "$xavp(ra=>callid)", "From" : "sip:$xavp(ra=>watcher_username)@$xavp(ra=>watcher_domain)", "User" : "$xavp(ra=>presentity_uri)" }"';
kazoo_publish("targeted", "$var(Queue)", $var(amqp_payload_request));
pv_unset("$xavp(ra)");
$var(runloop) = $var(runloop) + 1;
}
}
}
######## SEND BACK END ########
$var(amqp_payload_request) = '{"Event-Category" : "presence", "Event-Name" : "sync", "Action" : "End" }';
kazoo_publish("targeted", "$var(Queue)", $var(amqp_payload_request));
}
# vim: tabstop=4 softtabstop=4 shiftwidth=4 expandtab