Global object runtime provides information about the current FreeSWITCH instance and mod_quickjs version.
| 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. | |
Global object script provides information about the currently running JavaScript script.
| 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. | |
| Public Member Functions | |
| boolean | isInterrupted() |
| Checks whether the script has been interrupted (e.g., via CLI or shutdown). Returns true if interrupted. | |
These functions are available globally in the JavaScript execution context without importing any module.
| 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. | |
| void console_log(message) |
Outputs a message to the FreeSWITCH console log. Useful for debugging scripts.
Parameters:
| message | string | Message 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:
| milliseconds | number | Time 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:
| uuid1 | string | UUID of the first session |
| uuid2 | string | UUID 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:
| command | string | Shell 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:
| code | number | Exit 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:
| text | string | Input text to hash |
Returns: string
Example:
var hash = md5('password123');
| string crc32(text) |
Calculates and returns the CRC32 checksum of the input string.
Parameters:
| text | string | Input 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:
| path | string | Full 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:
| path | string | Full 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:
| path | string | Path 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:
| path | string | Path 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:
| format | string | Optional 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:
| format | string | Optional 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:
| cmd | string | FreeSWITCH API command name |
| arg | string | Command 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:
| name | string | Variable name |
| value | string | Variable value |
Example:
setGlobalVariable('my_var', 'hello');
| string getGlobalVariable(name) |
Returns the current value of a global FreeSWITCH variable.
Parameters:
| name | string | Variable 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:
| type | string | Directory 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:
| jsonObj | object | JSON object with chat message properties |
Returns: boolean
Example:
chatSend({proto: 'sip', from: '1000', to: '2000', body: 'Hello!'});