|
|
######## 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\n");
|
|
|
$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)]\n");
|
|
|
$var(Expires) = $xavp(ra=>expires) - $var(Now);
|
|
|
xlog("L_INFO", "EXPIRES $var(Expires) , $xavp(ra=>expires) , $var(Now)\n");
|
|
|
$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
|