Add. Support multiple events. (#1736)
Now subscriber stops and remove pid files when FS shutdown. So if you use Status->Services you will see correct status.
This commit is contained in:
parent
e6567d6d8d
commit
3d1f5b6866
|
|
@ -89,7 +89,7 @@ log.notice("start");
|
|||
|
||||
local timer = IntervalTimer.new(sleep):start()
|
||||
|
||||
for event in ievents("MESSAGE_QUERY", 1, timer:rest()) do
|
||||
for event in ievents({"MESSAGE_QUERY", "SHUTDOWN"}, 1, timer:rest()) do
|
||||
if (not event) or (timer:rest() < 1000) then
|
||||
if not file.exists(pid_file) then break end
|
||||
local stored = file.read(pid_file)
|
||||
|
|
@ -99,23 +99,33 @@ for event in ievents("MESSAGE_QUERY", 1, timer:rest()) do
|
|||
|
||||
if event then
|
||||
-- log.notice("event:" .. event:serialize("xml"));
|
||||
local account_header = event:getHeader('Message-Account')
|
||||
if account_header then
|
||||
local proto, account = split_first(account_header, ':', true)
|
||||
local event_name = event:getHeader('Event-Name')
|
||||
if event_name == 'MESSAGE_QUERY' then
|
||||
local account_header = event:getHeader('Message-Account')
|
||||
if account_header then
|
||||
local proto, account = split_first(account_header, ':', true)
|
||||
|
||||
if (not account) or (proto ~= 'sip' and proto ~= 'sips') then
|
||||
log.warningf("invalid format for voicemail id: %s", account_header)
|
||||
else
|
||||
local new_messages, saved_messages = vm_message_count(account)
|
||||
if not new_messages then
|
||||
log.warningf('can not find voicemail: %s', account)
|
||||
if (not account) or (proto ~= 'sip' and proto ~= 'sips') then
|
||||
log.warningf("invalid format for voicemail id: %s", account_header)
|
||||
else
|
||||
log.noticef('voicemail %s has %s/%s messages', account, new_messages, saved_messages)
|
||||
mwi_notify(account, new_messages, saved_messages)
|
||||
local new_messages, saved_messages = vm_message_count(account)
|
||||
if not new_messages then
|
||||
log.warningf('can not find voicemail: %s', account)
|
||||
else
|
||||
log.noticef('voicemail %s has %s/%s messages', account, new_messages, saved_messages)
|
||||
mwi_notify(account, new_messages, saved_messages)
|
||||
end
|
||||
end
|
||||
end
|
||||
elseif event_name == 'SHUTDOWN' then
|
||||
log.notice("shutdown")
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if file.read(pid_file) == pid then
|
||||
file.remove(pid_file)
|
||||
end
|
||||
|
||||
log.notice("stop")
|
||||
|
|
|
|||
|
|
@ -33,11 +33,11 @@ local pid = api:execute("create_uuid") or tostring(api:getTime())
|
|||
|
||||
file.write(pid_file, pid)
|
||||
|
||||
log.notice("start call_flow_subscribe");
|
||||
log.notice("start");
|
||||
|
||||
local timer = IntervalTimer.new(sleep):start()
|
||||
|
||||
for event in ievents("PRESENCE_PROBE", 1, timer:rest()) do
|
||||
for event in ievents({"PRESENCE_PROBE", "SHUTDOWN"}, 1, timer:rest()) do
|
||||
if (not event) or (timer:rest() < 1000) then
|
||||
if not file.exists(pid_file) then break end
|
||||
local stored = file.read(pid_file)
|
||||
|
|
@ -47,24 +47,34 @@ for event in ievents("PRESENCE_PROBE", 1, timer:rest()) do
|
|||
|
||||
if event then
|
||||
-- log.notice("event:" .. event:serialize("xml"));
|
||||
if event:getHeader('proto') == 'flow' and
|
||||
event:getHeader('Event-Calling-Function') == 'sofia_presence_handle_sip_i_subscribe'
|
||||
then
|
||||
local from, to = event:getHeader('from'), event:getHeader('to')
|
||||
local expires = tonumber(event:getHeader('expires'))
|
||||
if expires and expires > 0 then
|
||||
local call_flow_uuid, call_flow_status = find_call_flow(to)
|
||||
if call_flow_uuid then
|
||||
log.debugf("Find call flow: %s", to)
|
||||
presence_in.turn_lamp(call_flow_status == "false", to, call_flow_uuid);
|
||||
local event_name = event:getHeader('Event-Name')
|
||||
if event_name == 'PRESENCE_PROBE' then
|
||||
if event:getHeader('proto') == 'flow' and
|
||||
event:getHeader('Event-Calling-Function') == 'sofia_presence_handle_sip_i_subscribe'
|
||||
then
|
||||
local from, to = event:getHeader('from'), event:getHeader('to')
|
||||
local expires = tonumber(event:getHeader('expires'))
|
||||
if expires and expires > 0 then
|
||||
local call_flow_uuid, call_flow_status = find_call_flow(to)
|
||||
if call_flow_uuid then
|
||||
log.debugf("Find call flow: %s", to)
|
||||
presence_in.turn_lamp(call_flow_status == "false", to, call_flow_uuid);
|
||||
else
|
||||
log.warningf("Can not find call flow: %s", to)
|
||||
end
|
||||
else
|
||||
log.warningf("Can not find call flow: %s", to)
|
||||
log.noticef("%s UNSUBSCRIBE from %s", from, to)
|
||||
end
|
||||
else
|
||||
log.noticef("%s UNSUBSCRIBE from %s", from, to)
|
||||
end
|
||||
elseif event_name == 'SHUTDOWN' then
|
||||
log.notice("shutdown")
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
log.notice("stop call_flow_subscribe")
|
||||
if file.read(pid_file) == pid then
|
||||
file.remove(pid_file)
|
||||
end
|
||||
|
||||
log.notice("stop")
|
||||
|
|
|
|||
|
|
@ -1,10 +1,23 @@
|
|||
local ievents = function(events, ...)
|
||||
if type(events) == 'string' then
|
||||
events = freeswitch.EventConsumer(events)
|
||||
elseif type(events) == 'table' then
|
||||
local array = events
|
||||
events = freeswitch.EventConsumer()
|
||||
for _, event in ipairs(array) do
|
||||
local base, sub
|
||||
if type(event) == 'table' then
|
||||
base, sub = event[1], event[2]
|
||||
else
|
||||
base = event
|
||||
end
|
||||
if not sub then events:bind(base)
|
||||
else events:bind(base, sub) end
|
||||
end
|
||||
end
|
||||
|
||||
local block, timeout = ...
|
||||
if timeout == 0 then block, timeout = 0, 0 end
|
||||
if timeout and (timeout == 0) then block, timeout = 0, 0 end
|
||||
timeout = timeout or 0
|
||||
|
||||
return function()
|
||||
|
|
|
|||
Loading…
Reference in New Issue