Sponsor: VoiceMeUp - Corporate & Wholesale VoIP Services

VoIP Mailing List Archives
Mailing list archives for the VoIP community
 SearchSearch 

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


 
Post new topic   Reply to topic    VoIP Mailing List Archives Forum Index -> freeSWITCH Users
View previous topic :: View next topic  
Author Message
stevecrozz at gmail.com
Guest





PostPosted: Wed Jan 21, 2009 2:06 am    Post subject: [Freeswitch-users] firing events from javascript - working e Reply with quote

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@lists.freeswitch.org
http://lists.freeswitch.org/mailman/listinfo/freeswitch-users
UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-users
http://www.freeswitch.org
Back to top
msc at freeswitch.org
Guest





PostPosted: Wed Jan 21, 2009 9:05 am    Post subject: [Freeswitch-users] firing events from javascript - working e Reply with quote

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@gmail.com> wrote:
Quote:
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@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
Back to top
stevecrozz at gmail.com
Guest





PostPosted: Wed Jan 21, 2009 12:01 pm    Post subject: [Freeswitch-users] firing events from javascript - working e Reply with quote

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@freeswitch.org> wrote:
Quote:
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@gmail.com> wrote:
Quote:
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@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
Back to top
msc at freeswitch.org
Guest





PostPosted: Wed Jan 21, 2009 3:12 pm    Post subject: [Freeswitch-users] firing events from javascript - working e Reply with quote

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. Smile
-MC

On Wed, Jan 21, 2009 at 8:53 AM, Stephen Crosby <stevecrozz@gmail.com> wrote:
Quote:
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@freeswitch.org> wrote:
Quote:
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@gmail.com> wrote:
Quote:
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@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


_______________________________________________
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
Back to top
stevecrozz at gmail.com
Guest





PostPosted: Wed Jan 21, 2009 4:50 pm    Post subject: [Freeswitch-users] firing events from javascript - working e Reply with quote

Sure, I'll give it a try when I get home.

On Wed, Jan 21, 2009 at 1:43 PM, Michael Collins <msc@freeswitch.org> wrote:
Quote:
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@freeswitch.org> wrote:
Quote:
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. Smile
-MC

On Wed, Jan 21, 2009 at 8:53 AM, Stephen Crosby <stevecrozz@gmail.com> wrote:
Quote:
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@freeswitch.org> wrote:
Quote:
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@gmail.com> wrote:
Quote:
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@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



_______________________________________________
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
Back to top
msc at freeswitch.org
Guest





PostPosted: Wed Jan 21, 2009 4:51 pm    Post subject: [Freeswitch-users] firing events from javascript - working e Reply with quote

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@freeswitch.org> wrote:
Quote:
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. Smile
-MC

On Wed, Jan 21, 2009 at 8:53 AM, Stephen Crosby <stevecrozz@gmail.com> wrote:
Quote:
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@freeswitch.org> wrote:
Quote:
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@gmail.com> wrote:
Quote:
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@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



_______________________________________________
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
Back to top
msc at freeswitch.org
Guest





PostPosted: Wed Jan 21, 2009 5:03 pm    Post subject: [Freeswitch-users] firing events from javascript - working e Reply with quote

RESOLVED!
Stephen, when using event sub-classes you need to specify the subclass
when subscribing to listen to the events. I added a small entry to the
wiki page that I hope makes it clear:
http://wiki.freeswitch.org/wiki/Javascript_Event#Subscribing_To_Custom_Events

Let me know if you have any more questions.
-MC

P.S. - I will follow up with Lua and Perl and make sure that the wiki
is clear on how to subscribe to events. it looks like the default for
Lua is not to have an event subclass but the default for JavaScript
does have an event subclass... Smile

On Wed, Jan 21, 2009 at 1:49 PM, Stephen Crosby <stevecrozz@gmail.com> wrote:
Quote:
Sure, I'll give it a try when I get home.

On Wed, Jan 21, 2009 at 1:43 PM, Michael Collins <msc@freeswitch.org> wrote:
Quote:
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@freeswitch.org> wrote:
Quote:
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. Smile
-MC

On Wed, Jan 21, 2009 at 8:53 AM, Stephen Crosby <stevecrozz@gmail.com> wrote:
Quote:
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@freeswitch.org> wrote:
Quote:
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@gmail.com> wrote:
Quote:
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@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



_______________________________________________
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
Back to top
anthony.minessale at g...
Guest





PostPosted: Wed Jan 21, 2009 5:17 pm    Post subject: [Freeswitch-users] firing events from javascript - working e Reply with quote

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@freeswitch.org (msc@freeswitch.org)> wrote:
Quote:
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@freeswitch.org (msc@freeswitch.org)> wrote:
Quote:
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. Smile
-MC

On Wed, Jan 21, 2009 at 8:53 AM, Stephen Crosby <stevecrozz@gmail.com (stevecrozz@gmail.com)> wrote:
Quote:
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@freeswitch.org (msc@freeswitch.org)> wrote:
Quote:
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@gmail.com (stevecrozz@gmail.com)> wrote:
Quote:
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@lists.freeswitch.org (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 (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 (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 (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 ([email]MSN%3Aanthony_minessale@hotmail.com[/email])
GTALK/JABBER/PAYPAL:anthony.minessale@gmail.com ([email]PAYPAL%3Aanthony.minessale@gmail.com[/email])
IRC: irc.freenode.net #freeswitch

FreeSWITCH Developer Conference
sip:888@conference.freeswitch.org ([email]sip%3A888@conference.freeswitch.org[/email])
iax:guest@conference.freeswitch.org/888
googletalk:conf+888@conference.freeswitch.org ([email]googletalk%3Aconf%2B888@conference.freeswitch.org[/email])
pstn:213-799-1400
Back to top
msc at freeswitch.org
Guest





PostPosted: Wed Jan 21, 2009 5:24 pm    Post subject: [Freeswitch-users] firing events from javascript - working e Reply with quote

Anthm,
I will add the substance of this to the wiki.


-MC

Sent from my iPhone

On Jan 21, 2009, at 2:09 PM, Anthony Minessale <anthony.minessale@gmail.com (anthony.minessale@gmail.com)> wrote:



Quote:

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 <[url=mailto:msc@freeswitch.org]msc@freeswitch.org (msc@freeswitch.org)[/url]> wrote:
Quote:
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 <[url=mailto:msc@freeswitch.org]msc@freeswitch.org (msc@freeswitch.org)[/url]> wrote:
Quote:
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. Smile
-MC

On Wed, Jan 21, 2009 at 8:53 AM, Stephen Crosby <[url=mailto:stevecrozz@gmail.com]stevecrozz@gmail.com (stevecrozz@gmail.com)[/url]> wrote:
Quote:
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 <[url=mailto:msc@freeswitch.org]msc@freeswitch.org (msc@freeswitch.org)[/url]> wrote:
Quote:
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 <[url=mailto:stevecrozz@gmail.com]stevecrozz@gmail.com (stevecrozz@gmail.com)[/url]> wrote:
Quote:
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
[url=mailto:Freeswitch-users@lists.freeswitch.org]Freeswitch-users@lists.freeswitch.org (Freeswitch-users@lists.freeswitch.org)[/url]
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
[url=mailto:Freeswitch-users@lists.freeswitch.org]Freeswitch-users@lists.freeswitch.org (Freeswitch-users@lists.freeswitch.org)[/url]
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
[url=mailto:Freeswitch-users@lists.freeswitch.org]Freeswitch-users@lists.freeswitch.org (Freeswitch-users@lists.freeswitch.org)[/url]
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
[url=mailto:Freeswitch-users@lists.freeswitch.org]Freeswitch-users@lists.freeswitch.org (Freeswitch-users@lists.freeswitch.org)[/url]
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:[url=mailto:anthony_minessale@hotmail.com]anthony_minessale@hotmail.com ([email]MSN%3Aanthony_minessale@hotmail.com[/email])[/url]
GTALK/JABBER/PAYPAL:[url=mailto:anthony.minessale@gmail.com]anthony.minessale@gmail.com ([email]PAYPAL%3Aanthony.minessale@gmail.com[/email])[/url]
IRC: irc.freenode.net #freeswitch

FreeSWITCH Developer Conference
sip:[url=mailto:888@conference.freeswitch.org]888@conference.freeswitch.org ([email]sip%3A888@conference.freeswitch.org[/email])[/url]
guest@conference.freeswitch.org (guest@conference.freeswitch.org)/888
googletalk:[url=mailto:conf+888@conference.freeswitch.org]conf+888@conference.freeswitch.org ([email]googletalk%3Aconf%2B888@conference.freeswitch.org[/email])[/url]
pstn:213-799-1400

_______________________________________________
Freeswitch-users mailing list
Freeswitch-users@lists.freeswitch.org (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

Back to top
Display posts from previous:   
Post new topic   Reply to topic    VoIP Mailing List Archives Forum Index -> freeSWITCH Users All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group

VoiceMeUp - Corporate & Wholesale VoIP Services