Category:Javascript

From FreeSWITCH Wiki
(Redirected from Mod spidermonkey)
Jump to: navigation, search

FreeSWITCH uses the Mozilla SpiderMonkey 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_spidermonkey compiled and installed to take advantage of these functions. Each of those sections are documented below.

NOTE: From commit b76233266931ca0b53f3bcc589277b972d714216 (January 14'th 2014) in git master, FreeSWITCH has support for the Google V8 JavaScript (ECMAScript) engine. This is provided from the module mod_v8. In current git master mod_v8 is the default JavaScript engine. mod_v8 is a drop-in replacement for mod_spidermonkey, so the old scripts should work as before. There are two differences though, the SpiderMonkey engine has support for built in classes XML and File, these classes are not available in the V8 engine. mod_v8 provides a different XML interface, you can read more about it here: Javascript XML, it's also prepared to publish similar functions as the File class, but this is still work in progress.


Contents

Build/Install

mod_spidermonkey is now built and installed by default as of Rev 5787 (1.0.beta2 tag and beyond)

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

  • 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

For database support you will need an additional module compiled and installed. See the mod_spidermonkey_odbc page for installation instructions.

Informational Tip

Note: if you are using Fedora and you have errors like /lib/libnssutil3.so: undefined symbol: PR_GetEnv, you will need to configure FreeSWITCH using the --without-libcurl switch. Download_&_Installation_Guide#Fedora


 


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

Function Reference

SpiderMonkey Specific Objects

  • File - File IO methods (Spidermonkey object)

Other Points Of Interest

FAQ

See Also

Pages in This Category

Subcategories

This category has only the following subcategory.

Pages in category "Javascript"

The following 146 pages are in this category, out of 146 total.

A

C

D

E

F

G

J

J cont.

M

M cont.

O

R

S

T