freeswitch.EventConsumer, can be utilized event-based
I've been playing around with using freeswitch.EventConsumer in a lua process that starts-up when FS boots, and stays in the background. I've setup the example on the wiki, but the example uses session:execute("sleep",1000), and essentially loops every second until an event is fired. I'm wondering if there is a more event-driven way to accomplish this? I tried asking for help in #lua, but they said the project (FS) needed to implement event-driven programming for this to work. To me, it seems sort of silly to implement freeswitch.EventConsumer without a way for it to be executed event-wise Is using lua ESL the only option? There isn't any lua example scripts in libs/esl/lua to demonstrate how to handle events. if mod_lua can't handle events, can the mod_javascript utilize it? Thanks. --matt
Sort of silly?, I am not sure what you are talking about. I t's called *event*Consumer right? what do you mean by event based? There is no need to create a session? con = freeswitch.EventConsumer("all"); now you have a consumer obj every time you call con:pop() with no arg you will either get an event or nil when there are no events to consume. every time you call con:pop(1) the consumer object will block until there is an event. So you use the first way in conjunction with some other lock to do async or the 2nd way you do a dedicated blocking loop. I don't know what you said in #lua but, umm duhhhh I think we have an event driven programming under control..... We have a dedicated eventing engine in the core with scaling backend dispatcher threads that can handle hundereds of thousand of events at a time. There is also Event Socket (the word *event* again) that can connect to tcp and listen for *events* you can also write your code in C with the trivial module API that allows you to bind to an event internally and pretty much do whatever you want. 2009/3/27 Matthew Fong <mattdfong@gmail.com>
I've been playing around with using freeswitch.EventConsumer in a lua process that starts-up when FS boots, and stays in the background. I've setup the example on the wiki, but the example uses session:execute("sleep",1000), and essentially loops every second until an event is fired. I'm wondering if there is a more event-driven way to accomplish this? I tried asking for help in #lua, but they said the project (FS) needed to implement event-driven programming for this to work. To me, it seems sort of silly to implement freeswitch.EventConsumer without a way for it to be executed event-wise
Is using lua ESL the only option? There isn't any lua example scripts in libs/esl/lua to demonstrate how to handle events.
if mod_lua can't handle events, can the mod_javascript utilize it? Thanks.
--matt
_______________________________________________ Freeswitch-users mailing list Freeswitch-users@lists.freeswitch.org http://lists.freeswitch.org/mailman/listinfo/freeswitch-users UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-users http://www.freeswitch.org
-- Anthony Minessale II FreeSWITCH http://www.freeswitch.org/ ClueCon http://www.cluecon.com/ AIM: anthm MSN:anthony_minessale@hotmail.com <MSN%3Aanthony_minessale@hotmail.com> GTALK/JABBER/PAYPAL:anthony.minessale@gmail.com<PAYPAL%3Aanthony.minessale@gmail.com> IRC: irc.freenode.net #freeswitch FreeSWITCH Developer Conference sip:888@conference.freeswitch.org <sip%3A888@conference.freeswitch.org> iax:guest@conference.freeswitch.org/888 googletalk:conf+888@conference.freeswitch.org<googletalk%3Aconf%2B888@conference.freeswitch.org> pstn:213-799-1400
con = freeswitch.EventConsumer("all");
now you have a consumer obj
every time you call con:pop() with no arg you will either get an event or nil when there are no events to consume. every time you call con:pop(1) the consumer object will block until there is an event.
So you use the first way in conjunction with some other lock to do async or the 2nd way you do a dedicated blocking loop.
FYI, I added this information to the wiki page for freeswitch.EventConsumer. -MC
Got a few more questions about running LUA scripts, please forgive me, I'm an absolute newbie with LUA. If I want to subscribe to a custom event, and I use con = freeswitch.EventConsumer("CUSTOM my::event"); I get an error. Is this because I must subscribe to the CUSTOM (only) event, and then filter out the events using the Event-Subclass myself? Or am I missing something in the syntax of the subscribe? Also, if I do not have a freeswitch.Session, what is the best way to have my LUA script sleep? I want a functionality, where a statement inside my LUA script gets iterated every 30 seconds. My program does not use a session, so I cannot use session:execute("sleep","1000"), as suggested in the wiki. I tried api::sleep(30000) and a few other combinations with execute but no luck :(. Thanks. --matt On Sat, Mar 28, 2009 at 12:43 AM, Michael Collins <msc@freeswitch.org>wrote:
con = freeswitch.EventConsumer("all");
now you have a consumer obj
every time you call con:pop() with no arg you will either get an event or nil when there are no events to consume. every time you call con:pop(1) the consumer object will block until there is an event.
So you use the first way in conjunction with some other lock to do async or the 2nd way you do a dedicated blocking loop.
FYI, I added this information to the wiki page for freeswitch.EventConsumer. -MC
_______________________________________________ Freeswitch-users mailing list Freeswitch-users@lists.freeswitch.org http://lists.freeswitch.org/mailman/listinfo/freeswitch-users UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-users http://www.freeswitch.org
as replied earlier, if your doing nothing but consuming events, you can just block instead of sleep: con:pop(1) there is also a msleep function that you can call the same way you do console_log, it takes milli seconds as its arg. Note this should NOT be used when you have a script running as a session, only when you are running an api script. Mike On Mar 31, 2009, at 11:15 AM, Matthew Fong wrote:
Got a few more questions about running LUA scripts, please forgive me, I'm an absolute newbie with LUA.
If I want to subscribe to a custom event, and I use
con = freeswitch.EventConsumer("CUSTOM my::event");
I get an error. Is this because I must subscribe to the CUSTOM (only) event, and then filter out the events using the Event- Subclass myself? Or am I missing something in the syntax of the subscribe?
Also, if I do not have a freeswitch.Session, what is the best way to have my LUA script sleep? I want a functionality, where a statement inside my LUA script gets iterated every 30 seconds. My program does not use a session, so I cannot use session:execute("sleep","1000"), as suggested in the wiki. I tried api::sleep(30000) and a few other combinations with execute but no luck :(.
Thanks. --matt
On Sat, Mar 28, 2009 at 12:43 AM, Michael Collins <msc@freeswitch.org> wrote:
con = freeswitch.EventConsumer("all");
now you have a consumer obj
every time you call con:pop() with no arg you will either get an event or nil when there are no events to consume. every time you call con:pop(1) the consumer object will block until there is an event.
So you use the first way in conjunction with some other lock to do async or the 2nd way you do a dedicated blocking loop.
FYI, I added this information to the wiki page for freeswitch.EventConsumer. -MC
_______________________________________________ Freeswitch-users mailing list Freeswitch-users@lists.freeswitch.org http://lists.freeswitch.org/mailman/listinfo/freeswitch-users UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-users http://www.freeswitch.org
_______________________________________________ Freeswitch-users mailing list Freeswitch-users@lists.freeswitch.org http://lists.freeswitch.org/mailman/listinfo/freeswitch-users UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-users http://www.freeswitch.org
I know before I asked about blocking for an event, and maybe I should have created a new topic.. but now I want to actually sleep (rather than block) for a set time frame...this app will not be consuming events. can I get an example of how to use msleep in a lua script? This lua script will be running in the background, and not part of a session or event consumer. Thanks. --matt 2009/3/31 Michael Jerris <mike@jerris.com>
as replied earlier, if your doing nothing but consuming events, you can just block instead of sleep: con:pop(1)
there is also a msleep function that you can call the same way you do console_log, it takes milli seconds as its arg. Note this should NOT be used when you have a script running as a session, only when you are running an api script.
Mike
On Mar 31, 2009, at 11:15 AM, Matthew Fong wrote:
Got a few more questions about running LUA scripts, please forgive me, I'm an absolute newbie with LUA. If I want to subscribe to a custom event, and I use
con = freeswitch.EventConsumer("CUSTOM my::event");
I get an error. Is this because I must subscribe to the CUSTOM (only) event, and then filter out the events using the Event-Subclass myself? Or am I missing something in the syntax of the subscribe?
Also, if I do not have a freeswitch.Session, what is the best way to have my LUA script sleep? I want a functionality, where a statement inside my LUA script gets iterated every 30 seconds. My program does not use a session, so I cannot use session:execute("sleep","1000"), as suggested in the wiki. I tried api::sleep(30000) and a few other combinations with execute but no luck :(.
Thanks. --matt
On Sat, Mar 28, 2009 at 12:43 AM, Michael Collins <msc@freeswitch.org>wrote:
con = freeswitch.EventConsumer("all");
now you have a consumer obj
every time you call con:pop() with no arg you will either get an event or nil when there are no events to consume. every time you call con:pop(1) the consumer object will block until there is an event.
So you use the first way in conjunction with some other lock to do async or the 2nd way you do a dedicated blocking loop.
FYI, I added this information to the wiki page for freeswitch.EventConsumer. -MC
_______________________________________________ Freeswitch-users mailing list Freeswitch-users@lists.freeswitch.org http://lists.freeswitch.org/mailman/listinfo/freeswitch-users UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-users http://www.freeswitch.org
_______________________________________________ Freeswitch-users mailing list Freeswitch-users@lists.freeswitch.org http://lists.freeswitch.org/mailman/listinfo/freeswitch-users UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-users http://www.freeswitch.org
_______________________________________________ Freeswitch-users mailing list Freeswitch-users@lists.freeswitch.org http://lists.freeswitch.org/mailman/listinfo/freeswitch-users UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-users http://www.freeswitch.org
http://wiki.freeswitch.org/wiki/Lua#freeswitch.consoleLog On Mar 31, 2009, at 11:50 AM, Matthew Fong wrote:
I know before I asked about blocking for an event, and maybe I should have created a new topic..
but now I want to actually sleep (rather than block) for a set time frame...this app will not be consuming events.
can I get an example of how to use msleep in a lua script? This lua script will be running in the background, and not part of a session or event consumer. Thanks.
--matt
2009/3/31 Michael Jerris <mike@jerris.com> as replied earlier, if your doing nothing but consuming events, you can just block instead of sleep:
con:pop(1)
there is also a msleep function that you can call the same way you do console_log, it takes milli seconds as its arg. Note this should NOT be used when you have a script running as a session, only when you are running an api script.
Mike
On Mar 31, 2009, at 11:15 AM, Matthew Fong wrote:
Lua has no sleep or pause ... if you read thru the lua wiki they show you various ways to accomplish that. On Mar 31, 2009, at 10:50 AM, Matthew Fong wrote:
I know before I asked about blocking for an event, and maybe I should have created a new topic..
but now I want to actually sleep (rather than block) for a set time frame...this app will not be consuming events.
can I get an example of how to use msleep in a lua script? This lua script will be running in the background, and not part of a session or event consumer. Thanks.
--ma
Brian West brian@freeswitch.org -- Meet us a ClueCon! http://www.cluecon.com
Thanks, the freeswitch.msleep(5000) works! Any comment about the first Q... con = freeswitch.EventConsumer("CUSTOM my::event"); I get an error. Is this because I must subscribe to the CUSTOM (only) event, and then filter out the events using the Event-Subclass myself? Or am I missing something in the syntax of the subscribe? Thanks Michael for your help... --matt 2009/3/31 Brian West <brian@freeswitch.org>
Lua has no sleep or pause ... if you read thru the lua wiki they show you various ways to accomplish that. On Mar 31, 2009, at 10:50 AM, Matthew Fong wrote:
I know before I asked about blocking for an event, and maybe I should have created a new topic.. but now I want to actually sleep (rather than block) for a set time frame...this app will not be consuming events.
can I get an example of how to use msleep in a lua script? This lua script will be running in the background, and not part of a session or event consumer. Thanks.
--ma
Brian West brian@freeswitch.org
-- Meet us a ClueCon! http://www.cluecon.com
_______________________________________________ Freeswitch-users mailing list Freeswitch-users@lists.freeswitch.org http://lists.freeswitch.org/mailman/listinfo/freeswitch-users UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-users http://www.freeswitch.org
http://www.freeswitch.org/docs/class_event_consumer.html#a0 It takes 2 args, not one to specify the subclass Mike On Mar 31, 2009, at 12:11 PM, Matthew Fong wrote:
Thanks, the freeswitch.msleep(5000) works!
Any comment about the first Q...
con = freeswitch.EventConsumer("CUSTOM my::event");
I get an error. Is this because I must subscribe to the CUSTOM (only) event, and then filter out the events using the Event- Subclass myself? Or am I missing something in the syntax of the subscribe?
Thanks Michael for your help...
FYI, I've documented the msleep method here: http://wiki.freeswitch.org/wiki/Mod_lua#freeswitch.msleep I will work on better and more organized API documentation. If anyone out there has time/energy/knowledge of the scripting APIs and is willing to help out please email me off list. -MC 2009/3/31 Brian West <brian@freeswitch.org>
Lua has no sleep or pause ... if you read thru the lua wiki they show you various ways to accomplish that. On Mar 31, 2009, at 10:50 AM, Matthew Fong wrote:
I know before I asked about blocking for an event, and maybe I should have created a new topic.. but now I want to actually sleep (rather than block) for a set time frame...this app will not be consuming events.
can I get an example of how to use msleep in a lua script? This lua script will be running in the background, and not part of a session or event consumer. Thanks.
--ma
Brian West brian@freeswitch.org
-- Meet us a ClueCon! http://www.cluecon.com
_______________________________________________ Freeswitch-users mailing list Freeswitch-users@lists.freeswitch.org http://lists.freeswitch.org/mailman/listinfo/freeswitch-users UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-users http://www.freeswitch.org
participants (5)
-
Anthony Minessale
-
Brian West
-
Matthew Fong
-
Michael Collins
-
Michael Jerris