[Freeswitch-users] firing events from javascript - working example needed

Anthony Minessale anthony.minessale at gmail.com
Wed Jan 21 14:09:52 PST 2009


lua:

local event = freeswitch.Event("custom");

js:
e = new Event("custom", "message");


in js you specify a subclass which means you would need to subscribe to it
events plain custom message

really just
events plain custom is not a good idea because all the real events have a
subclass
once the custom keyword is seen in the event command each name after that is
assumed
to be a custom event name.

For subclass we use the naming convention mod::event_name
so a better test would be:

e = new Event("custom", "my_js::test");

there is no point to specify a subclass unless the event type is custom.


e = new Event("message");

would be a better example because you can easily subscribe to the "message"
event.





On Wed, Jan 21, 2009 at 3:43 PM, Michael Collins <msc at freeswitch.org> wrote:

> Stephen,
>
> I've been able to duplicate this behavior on my Mac with r11333. It
> seems to work with Lua but not with Javascript. I am going to discuss
> it with the devs and possibly open a jira issue. In the meantime would
> you be willing to try it with Lua, even just for testing? This worked
> for me:
> <lua script>
> -- Test sending custom events in Lua
> local event = freeswitch.Event("custom");
> event:addHeader("Sample Custom Event", "no");
> event:fire();
> </lua script>
> I saved the above as /usr/local/freeswitch/scripts/event1.lua
>
> I then opened two terminal windows, one to freeswitch CLI and the
> other a telnet into the event socket
> On the event socket I logged in and listened for custom events:
>  telnet localhost 8021 <enter>
>  auth ClueCon <enter><enter>
>  events plain custom <enter><enter>
>
> On FS CLI I typed:
>  lua event1.lua <press enter>
>
> On the event socket I immediately see this:
> Sample Custom Event: no
> Event-Name: CUSTOM
> Core-UUID: 2c04a36e-5a23-4b14-b0a5-34fe9fd9f1bc
> FreeSWITCH-Hostname: michael-collinss-macbook-pro.local
> FreeSWITCH-IPv4: 192.168.1.5
> FreeSWITCH-IPv6: %3A%3A1
> Event-Date-Local: 2009-01-21%2013%3A14%3A35
> Event-Date-GMT: Wed,%2021%20Jan%202009%2021%3A14%3A35%20GMT
> Event-Date-Timestamp: 1232572475813346
> Event-Calling-File: switch_cpp.cpp
> Event-Calling-Function: fire
> Event-Calling-Line-Number: 295
>
> However, when I do the same kind of thing with js it doesn't work:
> <js script>
> // Sample event sent from JavaScript
> console_log("INFO","Starting event1.js sample event sender...\n");
>   var msg = "Hello, welcome to the FreeSWITCH demo application
> please enter some text into the chat box";
>   e = new Event("custom", "message");
>   e.addBody(msg);
>   e.fire();
> </js script>
>
> I saved the above as /usr/local/freeswitch/scripts/event1.js
> I run it from the FS CLI:
>  jsrun event1.js <enter>
> And I see my console message pop up but I don't see anything on the event
> socket
> However, if I do this at the event socket:
>  events plain all <enter><enter>
>
> And then do jsrun event1.js from FS CLI then I do see my event on the
> event socket like this:
> Content-Length: 559
> Content-Type: text/event-plain
>
> Event-Subclass: message
> Event-Name: CUSTOM
> Core-UUID: 2c04a36e-5a23-4b14-b0a5-34fe9fd9f1bc
> FreeSWITCH-Hostname: michael-collinss-macbook-pro.local
> FreeSWITCH-IPv4: 192.168.1.5
> FreeSWITCH-IPv6: %3A%3A1
> Event-Date-Local: 2009-01-21%2013%3A07%3A48
> Event-Date-GMT: Wed,%2021%20Jan%202009%2021%3A07%3A48%20GMT
> Event-Date-Timestamp: 1232572068370864
> Event-Calling-File: mod_spidermonkey.c
> Event-Calling-Function: event_fire
> Event-Calling-Line-Number: 671
> Content-Length: 90
>
> Hello, welcome to the FreeSWITCH demo application please enter some
> text into the chat box
>
> So, there's definitely something going on, we just need to find out
> what for sure. I'll be in touch.
> -MC (mercutioviz)
>
> On Wed, Jan 21, 2009 at 12:00 PM, Michael Collins <msc at freeswitch.org>
> wrote:
> > thanks we'll have a look. Also, please use pastebin.freeswitch.org in
> > the future because it makes it easier for us to find things. :)
> > -MC
> >
> > On Wed, Jan 21, 2009 at 8:53 AM, Stephen Crosby <stevecrozz at gmail.com>
> wrote:
> >> Today I was able to see the event on the listener by subscribing to
> >> all events. But I'd like to only subscribe to a subset if possible. I
> >> thought that it would pop up when subscribing to CUSTOM events. I've
> >> put it all together very neatly here:
> >> http://pastebin.com/m6f8f7b43
> >>
> >> --Stephen
> >>
> >> On Wed, Jan 21, 2009 at 6:03 AM, Michael Collins <msc at freeswitch.org>
> wrote:
> >>> can you create a pastebin with the two scripts in question? We'll take
> >>> a look and see if we can figure out what's going on.
> >>> Thanks,
> >>> MC
> >>>
> >>> On Tue, Jan 20, 2009 at 11:04 PM, Stephen Crosby <stevecrozz at gmail.com>
> wrote:
> >>>> I noticed the wiki has an example of sending a custom event from
> >>>> javascript: http://wiki.freeswitch.org/wiki/Javascript_Event , but I
> >>>> can't make it work. It doesn't fail or cause an error. But I never see
> >>>> an event on my listener script. Can someone confirm that this example
> >>>> does in fact work? or provide me with one that does?
> >>>>
> >>>> --Stephen
> >>>>
> >>>> _______________________________________________
> >>>> Freeswitch-users mailing list
> >>>> Freeswitch-users at 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 at 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 at 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 at 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 at hotmail.com <MSN%3Aanthony_minessale at hotmail.com>
GTALK/JABBER/PAYPAL:anthony.minessale at gmail.com<PAYPAL%3Aanthony.minessale at gmail.com>
IRC: irc.freenode.net #freeswitch

FreeSWITCH Developer Conference
sip:888 at conference.freeswitch.org <sip%3A888 at conference.freeswitch.org>
iax:guest at conference.freeswitch.org/888
googletalk:conf+888 at conference.freeswitch.org<googletalk%3Aconf%2B888 at conference.freeswitch.org>
pstn:213-799-1400
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.freeswitch.org/pipermail/freeswitch-users/attachments/20090121/268354f4/attachment-0002.html 


More information about the FreeSWITCH-users mailing list