This object creates a listener/consumer for a certain kind of event in FreeSWITCH Event System:
-- You may subscribe to specific events if you want to, and even subclasses -- con1 = freeswitch.EventConsumer("CUSTOM") -- or -- con2 = freeswitch.EventConsumer("CUSTOM","conference::maintenance") --listen for an event specific subclass con3 = freeswitch.EventConsumer("CUSTOM", "ping::running") -- create an event in that specific subclass event = freeswitch.Event("CUSTOM", "ping::running") event:addHeader("hi", "there") -- fire the event event:fire() -- look in the listened events stack for events to "pop" out, block there for max 20 seconds received_event = con3:pop(1, 20000) if(received_event) then stream:write("event received ") stream:write(received_event:serialize("text")) else stream:write("no event ") end
Let's look at events in action: edit the /usr/local/freeswitch/scripts/test8.lua file:
You execute this script issuing lua test8.lua from the FreeSWITCH console. Note that the binding messages are printed on console after the output of stream:write(), that is, after our script has exited.
It would be interesting to split the script into two, one that listens and one that sends, and execute them using two different console instances on the same FreeSWITCH server.