mod_quickjs: Global Objects & Functions Reference
Global API

Index

runtime Object
script Object
Global Functions

runtime Object

Global object runtime provides information about the current FreeSWITCH instance and mod_quickjs version.

Properties

Read-Only Properties
string version
 Version string of mod_quickjs module.
string switchId
 Unique UUID identifier of the FreeSWITCH core instance.
string switchName
 Name of the FreeSWITCH instance (switchname).
string switchVersion
 Full version string of FreeSWITCH.
string hostname
 Hostname of the server where FreeSWITCH is running.

script Object

Global object script provides information about the currently running JavaScript script.

Properties

Read-Only Properties
string id
 Unique identifier of the script.
string name
 Name of the script file.
string path
 Full filesystem path to the script file.

Methods

Public Member Functions
boolean isInterrupted()
 Checks whether the script has been interrupted (e.g., via CLI or shutdown). Returns true if interrupted.

Global Functions

These functions are available globally in the JavaScript execution context without importing any module.

Functions

Public Functions
void console_log(message)
 Outputs a message to the FreeSWITCH console log. Alias: consoleLog().
void consoleLog(message)
 Alias for console_log(). Outputs a message to the FreeSWITCH console log.
void msleep(milliseconds)
 Suspends script execution for the specified number of milliseconds.
boolean bridge(uuid1, uuid2)
 Bridges two active sessions (calls) together by their UUIDs. Returns true on success.
string system(command)
 Executes a system shell command and returns its output.
void exit(code)
 Terminates the current script execution with the specified exit code.
string md5(text)
 Calculates and returns the MD5 hash of the input string.
string crc32(text)
 Calculates and returns the CRC32 hash of the input string.
boolean unlink(path)
 Deletes a file at the specified path. Returns true on success.
boolean mkdir(path)
 Creates a directory at the specified path. Returns true on success.
boolean dirExists(path)
 Checks whether a directory exists at the specified path.
boolean fileExists(path)
 Checks whether a file exists at the specified path.
string|number epochTime([format])
 Returns the current Unix epoch time. Optional format string parameter.
string|number microTime([format])
 Returns the current time with microsecond precision.
string apiExecute(cmd, arg)
 Executes a FreeSWITCH API command with arguments and returns the result.
void setGlobalVariable(name, value)
 Sets a global FreeSWITCH variable accessible across all channels.
string getGlobalVariable(name)
 Returns the value of a global FreeSWITCH variable.
string getPath(type)
 Returns the filesystem path for the specified FreeSWITCH directory type (e.g., 'base_dir', 'recordings_dir').
string getUUID()
 Generates and returns a new unique UUID string.
boolean chatSend(jsonObj)
 Sends a chat message using a JSON object with chat properties. Returns true on success.

Detailed Documentation

void console_log(message)

Outputs a message to the FreeSWITCH console log. Useful for debugging scripts.

Parameters:

messagestringMessage text to output

Example:

console_log('Hello from JavaScript!');
void msleep(milliseconds)

Suspends script execution for the specified number of milliseconds. Useful for implementing delays or polling loops.

Parameters:

millisecondsnumberTime to sleep in milliseconds

Example:

msleep(1000); // sleep 1 second
boolean bridge(uuid1, uuid2)

Bridges two active sessions (calls) together. This connects the media streams of both calls.

Parameters:

uuid1stringUUID of the first session
uuid2stringUUID of the second session

Returns: boolean

Example:

var success = bridge(uuid1, uuid2);
string system(command)

Executes a system shell command and returns its standard output as a string.

Parameters:

commandstringShell command to execute

Returns: string

Example:

var result = system('ls -la /tmp');
void exit(code)

Immediately terminates the current JavaScript script execution with the specified exit code.

Parameters:

codenumberExit code (0 = success)

Example:

exit(0); // exit successfully
string md5(text)

Calculates and returns the MD5 hash of the input string as a hexadecimal string.

Parameters:

textstringInput text to hash

Returns: string

Example:

var hash = md5('password123');
string crc32(text)

Calculates and returns the CRC32 checksum of the input string.

Parameters:

textstringInput text to hash

Returns: string

Example:

var checksum = crc32('data');
boolean unlink(path)

Deletes a file at the specified filesystem path. Returns true if the file was successfully deleted.

Parameters:

pathstringFull path to the file

Returns: boolean

Example:

unlink('/tmp/old_recording.wav');
boolean mkdir(path)

Creates a new directory at the specified path. Returns true on success.

Parameters:

pathstringFull path to the directory

Returns: boolean

Example:

mkdir('/tmp/my_new_dir');
boolean dirExists(path)

Checks whether a directory exists at the specified path. Returns true if it exists.

Parameters:

pathstringPath to check

Returns: boolean

Example:

if (dirExists('/tmp/mydir')) { /* ... */ }
boolean fileExists(path)

Checks whether a file exists at the specified path. Returns true if it exists.

Parameters:

pathstringPath to check

Returns: boolean

Example:

if (fileExists('/tmp/file.txt')) { /* ... */ }
string|number epochTime([format])

Returns the current Unix epoch time. If a format string is provided, returns formatted time string; otherwise returns numeric timestamp.

Parameters:

formatstringOptional time format string

Returns: string|number

Example:

var ts = epochTime();
var fmt = epochTime('%Y-%m-%d %H:%M:%S');
string|number microTime([format])

Returns the current time with microsecond precision.

Parameters:

formatstringOptional time format string

Returns: string|number

Example:

var precise = microTime();
string apiExecute(cmd, arg)

Executes a FreeSWITCH API command with the specified arguments and returns the result as a string.

Parameters:

cmdstringFreeSWITCH API command name
argstringCommand arguments

Returns: string

Example:

var status = apiExecute('status', '');
void setGlobalVariable(name, value)

Sets a global FreeSWITCH variable that is accessible across all channels and scripts.

Parameters:

namestringVariable name
valuestringVariable value

Example:

setGlobalVariable('my_var', 'hello');
string getGlobalVariable(name)

Returns the current value of a global FreeSWITCH variable.

Parameters:

namestringVariable name

Returns: string

Example:

var val = getGlobalVariable('my_var');
string getPath(type)

Returns the filesystem path for the specified FreeSWITCH directory. Common types: 'base_dir', 'conf_dir', 'log_dir', 'db_dir', 'recordings_dir', 'sounds_dir'.

Parameters:

typestringDirectory type identifier

Returns: string

Example:

var recDir = getPath('recordings_dir');
string getUUID()

Generates and returns a new globally unique identifier (UUID) string.

Returns: string

Example:

var newId = getUUID();
boolean chatSend(jsonObj)

Sends a chat message. The JSON object should contain properties like 'proto', 'from', 'to', 'body', etc.

Parameters:

jsonObjobjectJSON object with chat message properties

Returns: boolean

Example:

chatSend({proto: 'sip', from: '1000', to: '2000', body: 'Hello!'});