Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
con = freeswitch.EventConsumer("<event_name>"[,"<subclass type>"]);

-- pop() returns an event or nil if no events
con:pop()

-- pop(1) blocks until there is an event
con:pop(1)

-- pop(1,500) blocks for max half a second until there is an event
con:pop(1,500)

 

Usage (multiple specific event subscriptions):

Code Block
con = freeswitch.EventConsumer();
con:bind("RELOADXML");
con:bind("SHUTDOWN");
con:bind("CUSTOM", "multicast::event");
 
-- pop() returns an event or nil if no events
con:pop()

-- pop(1) blocks until there is an event
con:pop(1)

-- pop(1,500) blocks for max half a second until there is an event
con:pop(1,500)

 

Examples:

Code Block
con = freeswitch.EventConsumer("all");
session = freeswitch.Session("sofia/default/dest@host.com");
while session:ready() do
    session:execute("sleep", "1000");
    for e in (function() return con:pop() end) do
        print("event\n" .. e:serialize("xml"));
    end
end
-- or
while session:ready() do
    for e in (function() return con:pop(1,1000) end) do
        print("event\n" .. e:serialize("xml"))
    end
end
-- You may subscribe to specific events if you want to, and even subclasses
con = freeswitch.EventConsumer("CUSTOM");
con = freeswitch.EventConsumer("CUSTOM","conference::maintenance");
-- wait for a specific event but continue after 500 ms
function poll()
    -- create event and listener
    local event = freeswitch.Event("CUSTOM", "ping::running?")
    local con = freeswitch.EventConsumer("CUSTOM", "ping::running!")
    -- add text ad libitum
    event:addHeader("hi", "there")
    -- fire event
    event:fire()
    -- and wait for reply but not very long
    if con:pop(1, 500) then
        print("reply received")
        return true
    end
    print("no reply")
    return false
end

...