Skip to main content

mod_v8

About

See the main JavaScript page to learn how to use JavaScript with FreeSWITCH.

From commit b76233266931ca0b53f3bcc589277b972d714216 (January 14'th 2014) in git master, FreeSWITCH has support for the Google V8 JavaScript (ECMAScript) engine. It supports all the standard JavaScript language elements, for example 'for' and 'while' loops, regexps, etc. In addition there are things that are specific to FreeSWITCH which are listed below. You need to have mod_v8 compiled and installed to take advantage of these functions. Each of those sections are documented below.

Build/Install

mod_v8 is built and installed by default as of revision b76233266931ca0b53f3bcc589277b972d714216.

If for some reason it's not, do the following:

  • Uncomment languages/mod_v8 in modules.conf in your src directory (make it always build and install mod_v8)
  • Run 'make mod_v8-install' to make and install just the v8 module
  • Edit conf/autoload_configs/modules.conf.xml in your FreeSWITCH™ install directory to load mod_v8
  • In fs_cli, run "load mod_v8"

For database support, the system must be configured to use ODBC. If it is, the built-in class for ODBC will automatically be built.

A difference between the old mod_spidermonkey and mod_v8 is that the basic extra modules (ODBC, CoreDB, Socket, etc.) are now compiled directly into mod_v8.

Execution of a script

There are two methods for script execution, via an API call jsrun and via an application javascript. When you use the API a default Session object is not created, as there is no call to associate it with. By default, scripts will be loaded from the {FS_ROOT}/scripts directory, you may override this by placing a / as the first character in Unix-like systems or a x:\ in Windows systems as the script name.

Application

From the Dialplan, you simply call it as an application similar to:

<action application="javascript" data="/path/to/some/script.js"/>

If you need to pass arguments into to the javascript application, they can be passed in as a single string to the variable "argv" by doing the following:

<action application="javascript" data="/path/to/some/script.js $1"/>

API

At the FreeSWITCH™ console, or some other application/interface execute the jsrun call with the script name as its argument.

jsrun /path/to/some/script.js

Examples

  • Javascript clam
  • Other Javascript Examples exist (search confluence) and include database connectivity and grabbing external content via CURL.

Function Reference

Other Points Of Interest

Logging

Logs a message to the console logger.

Synopsis

console_log(message) console_log(level, message)

  • You most likely want to add a \n to the end of your message, other than that its just a text string.
  • In the single-argument form, the level defaults to "debug"
  • Levels: "DEBUG", "INFO", "NOTICE", "WARNING", "ERR", "CRIT", "ALERT".

Example

console_log("Hello there\n"); console_log("WARNING", "Ho!\n");

FAQ

See Also