Javascript Event

From FreeSWITCH Wiki

Jump to: navigation, search

Contents

Invoking Event Object

   // Define callback function
   function on_event(session, type, event_obj, user_data) {
           if (type == "event") {
                   console_log("notice", "Event: " + event_obj.serialize() + "\n"); 
           }
   }
   // Start tone detection and play silent file to wait for event
   session.execute("tone_detect", "voicemail_beep 1400 r");    
   session.streamFile("/usr/local/freeswitch/sounds/silence.wav", on_event);
   session.execute("stop_tone_detect");

Methods


Example of creating Event object and then fire it

    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();

Result

    Content-Length: 608
    Content-Type: text/event-plain
    
    Event-Subclass: message
    Event-Name: CUSTOM
    Core-UUID: 95e16640-7ddf-11dd-adfa-133c220a79a4
    FreeSWITCH-Hostname: johny-ubuntu
    FreeSWITCH-IPv4: 192.168.150.134
    FreeSWITCH-IPv6: 127.0.0.1
    Event-Date-Local: 2008-09-25%2010%3A38%3A42
    Event-Date-GMT: Thu,%2025%20Sep%202008%2014%3A38%3A42%20GMT
    Event-Date-timestamp: 1222353522769992
    Event-Calling-File: mod_spidermonkey.c
    Event-Calling-Function: event_fire
    Event-Calling-Line-Number: 673
    Event-Subclass: message
    Event-Subclass-Owner: src/switch_event.c
    Content-Length: 90
         
    Hello, welcome to the FreeSWITCH demo application please enter some text into the chat box
Personal tools
Community