Javascript
From FreeSWITCH Wiki
Freeswitch uses the Mozilla SpiderMonkey Javascript (ECMA Script) 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_spidermonkey compiled and installed to take advantage of these functions. Each of those sections are documented below.
Contents |
Build/Install
mod_spidermonkey is not built or installed by default.
- Uncomment languages/mod_spidermonkey in modules.conf in your src directory (make it always build and install spidermonkey)
- Run 'make mod_spidermonkey-install' to make and install just the spidermonkey module
- Edit conf/autoload_configs/modules.conf.xml in your FreeSWITCH™ install directory to load mod_spidermonkey
- Restart freeswitch
Compiling mod_spidermonkey_odbc
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 {FSROOT}/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
Quick start
Spidermonkey Specific Objects
- File - File IO methods (Spidermonkey object)
Other Points Of Interest
- Run - Use CURL from within your Spidermonkey script
- Javascript_Event
- Javascript_XML
