mod_quickjs (v1.8.1): Classes Reference
Classes

Class List

Session
Codec
FileHandle
Event
File
Socket
CoreDB
EventHandler
XML
Curl
DBH
JsonRpc
Chat

Session Class Reference

Properties

Public Attributes
getter/setter name
getter/setter uuid
getter/setter state
getter/setter cause
getter/setter causecode
getter/setter dialplan
getter/setter destination
getter/setter callerIdName
getter/setter callerIdNumber
getter/setter readCodecName
getter/setter writeCodecName
getter/setter samplerate
getter/setter channels
getter/setter ptime
getter/setter isReady
getter/setter isAnswered
getter/setter isMediaReady
getter/setter encodedFrameSize
getter/setter decodedFrameSize
getter/setter ttsEngine
getter/setter asrEngine
getter/setter language
getter/setter bgStreams
getter/setter autoHangup

Methods

Public Member Functions
JSValue setHangupHook(callback)
 Sets a callback function to be executed when the call is hung up (hangup hook).
JSValue speak(text, [ttsParams, eventsHandler, handlerData])
 Converts text to speech (TTS) and plays it into the session.
JSValue speakEx(engine, language, text, [ttsParams, eventsHandler, handlerData])
 Converts text to speech (TTS) and plays it into the session, explicitly specifying the engine and language.
JSValue playback(fileName, [skipSmps, eventsHandler, handlerData])
 Plays an audio file into the session (foreground playback).
JSValue fgPlaybackCtl(pause|resume|speed|volume, [+|-|n])
 Controls foreground playback (pause, speed, volume).
JSValue playbackStop()
 Stops file playback.
JSValue bgPlaybackStart(fileName)
 Starts background playback of a file.
JSValue bgPlaybackStop()
 Stops background playback of a file.
JSValue bgPlaybackCtl(pause|resume|speed|volume, [+|-|n])
 Controls background playback (pause, speed, volume).
JSValue playAndDetectSpeech(fileToPlay, [timeout, asrParams, eventsHandler, handlerData])
 Performs speech recognition (ASR) while playing a file or waiting.
JSValue sayAndDetectSpeech(textToSpeech, [timeout, asrParams, eventsHandler, handlerData])
 Performs speech recognition (ASR) while speaking text (TTS).
JSValue detectSpeech([timeout, asrParams, eventsHandler, handlerData])
 Performs speech recognition (ASR) in listen/wait mode (without playback).
JSValue detectSpeechEx(asrEngine, [timeout, asrParams, eventsHandler, handlerData])
 Performs speech recognition (ASR) with an explicitly specified recognition engine.
JSValue recordFile(fileName, [limitSec, threshold, silenceHits, eventsHandler, handlerData])
 Records audio from the session into a file.
JSValue collectInput(dtmfCallback, [udata, absTimeout, digitTimeout])
 Collects DTMF digits from the user and invokes a callback on each digit press.
JSValue flushEvents()
 Clears the session event queue.
JSValue flushDigits()
 Clears the DTMF digit buffer.
JSValue setVariable(name, value)
 Sets a channel variable.
JSValue getVariable(name)
 Returns the value of a channel variable.
JSValue setChanFlag(name, true|false)
 Controls channel flags (e.g., CF_BREAK, CF_AUDIO_PAUSE_READ).
JSValue getChanFlag(name)
 Checks the state of a channel flag.
JSValue getDigits(digits, [terminators, timeout, digitTimeout, absTimeout])
 Collects a specified number of DTMF digits from the user.
JSValue answer()
 Answers the incoming call (200 OK).
JSValue preAnswer()
 Answers the call with early media (183 Session Progress).
JSValue getEvent()
 Retrieves an event from the session queue.
JSValue putEvent(jsEvent)
 Injects an event into the session.
JSValue hangup([cause])
 Hangs up the call with the specified cause (or NORMAL_CLEARING by default).
JSValue execute(appName, [appArg])
 Executes a FreeSWITCH dialplan application.
JSValue sleep(msec, [callback])
 Suspends script execution for the specified time (in milliseconds).
JSValue genTones(toneScript, [callback])
 Generates DTMF or audio tones into the session.
JSValue getReadCodec()
 Returns the codec object used for reading (receiving).
JSValue getWriteCodec()
 Returns the codec object used for writing (transmitting).
JSValue frameRead(buffer)
 Reads a raw audio frame from the session into the provided ArrayBuffer.
JSValue writeFrame(buffer, len, [codec])
 Writes a raw audio frame from an ArrayBuffer into the session.
JSValue generateXmlCdr()
 Generates and returns an XML CDR (Call Detail Record) as a string.
JSValue playAndGetDigits(min_digits, max_digits, max_tries, timeout, terminators, audio_file, bad_audio_file, [digits_regex, var_name, digit_timeout, transfer_on_failure])
 Plays a file and collects DTMF digits from the user with regex validation.
JSValue sayPhrase(phraseName, [phraseData, phraseLang, eventsHandler, handlerData])
 Plays a predefined phrase (phrase macro) from the XML configuration.

Codec Class Reference

Properties

Public Attributes
getter/setter isReady
getter/setter name
getter/setter ptime
getter/setter channels
getter/setter samplerate
getter/setter canEncode
getter/setter canDecode

Methods

Public Member Functions
JSValue encode(decodedBuffer, encodedBuffer, decodedLen, encodedLen, flag)
 Encodes raw audio data (PCM) into the codec format.
JSValue decode(encodedBuffer, decodedBuffer, encodedLen, decodedLen, flag)
 Decodes codec data into raw audio data (PCM).

FileHandle Class Reference

Properties

Public Attributes
getter/setter speed
getter/setter volume
getter/setter channels
getter/setter samplerate

Methods

Public Member Functions
JSValue pause()
 Pauses file playback/recording.
JSValue truncate()
 Truncates the file to the current position.
JSValue restart()
 Restarts file playback/recording from the beginning.
JSValue seek(samples)
 Moves the read/write position in the file by the specified number of samples.
JSValue read(buffer)
 Reads data from the open file into the buffer.
JSValue write(buffer)
 Writes data from the buffer into the open file.
JSValue close()
 Closes the file handle.
JSValue stop()
 Stops the file operation.

Event Class Reference

Properties

Public Attributes
getter/setter isReady

Methods

Public Member Functions
JSValue addHeader(name, value)
 Adds a header to the event.
JSValue getHeader(name)
 Returns the value of the event header.
JSValue addBody(text)
 Adds text to the event body.
JSValue getBody()
 Returns the event body.
JSValue getType()
 Returns the event type (e.g., CUSTOM, CHANNEL_ANSWER).
JSValue serialize([format])
 Serializes the event into a string (usually in plain or xml format).
JSValue fire()
 Fires (dispatches) the event into the FreeSWITCH Event System.
JSValue destroy()
 Releases the resources occupied by the event.

File Class Reference

Properties

Public Attributes
getter/setter path
getter/setter name
getter/setter size
getter/setter position
getter/setter canRead
getter/setter canWrite
getter/setter isOpen
getter/setter isFile
getter/setter isDirectory
getter/setter creationTime
getter/setter lastModified

Methods

Public Member Functions
JSValue exists()
 Checks if the file or directory exists.
JSValue mktemp()
 Creates a temporary file.
JSValue open(flags)
 Opens the file with the specified flags (e.g., r, w, a).
JSValue close()
 Closes the file.
JSValue read(buffer, len)
 Reads the specified number of bytes from the file into the buffer.
JSValue write(buffer, len)
 Writes data from the buffer into the file.
JSValue writeString(str)
 Writes a string to the file.
JSValue readString(len)
 Reads a string from the file.
JSValue seek(pos)
 Moves the file position pointer.
JSValue remove()
 Deletes the file.
JSValue rename(toPath)
 Renaming or moving the file.
JSValue copy(toPath)
 Copies the file.
JSValue mkdir()
 Creates a directory.
JSValue list()
 Returns a list of files in the directory.

Socket Class Reference

Properties

Public Attributes
getter/setter type
getter/setter nonblock
getter/setter timeout
getter/setter ttl

Methods

Public Member Functions
JSValue connect(hostName, port)
 Connects to a TCP/UDP socket.
JSValue close()
 Closes the socket.
JSValue write(buffer, len)
 Sends binary data to the socket.
JSValue read(buf, len)
 Reads binary data from the socket.
JSValue writeString(str)
 Sends a string to the socket.
JSValue readString()
 Reads a string from the socket.

CoreDB Class Reference

Properties

Public Attributes
getter/setter path

Methods

Public Member Functions
JSValue exec(sql)
 Executes an SQL query against the SQLite database.
JSValue next()
 Moves to the next row of the query result.
JSValue step()
 Executes a step for a prepared statement.
JSValue fetch()
 Fetches the current row of the query result as an object.
JSValue prepare(sql, params)
 Prepares an SQL query (prepared statement).
JSValue bindText(index, value)
 Binds a string value to a query parameter.
JSValue bindInt(index, value)
 Binds an integer value to a query parameter.
JSValue tableExists(tableName)
 Checks if a table exists in the database.

EventHandler Class Reference

Properties

Public Attributes
getter/setter isReady

Methods

Public Member Functions
JSValue subscribe(events)
 Subscribes to receive the specified FreeSWITCH events.
JSValue unsubscribe(events)
 Unsubscribes from the specified events.
JSValue addFilter(header, value)
 Adds a filter for received events.
JSValue delFilter(header)
 Removes an event filter.
JSValue getEvent([timeout])
 Gets the next event from the queue (blocks or waits for timeout).
JSValue sendEvent(jsEvent)
 Sends an event to the Event System.

XML Class Reference

Properties

Public Attributes
getter/setter name
getter/setter data
getter/setter error

Methods

Public Member Functions
JSValue addChild(name)
 Adds a child XML node.
JSValue getChild(name)
 Returns the first child XML node with the specified name.
JSValue getAttribute(name)
 Returns the value of an XML node attribute.
JSValue setAttribute(name, value)
 Sets the value of an XML node attribute.
JSValue remove()
 Removes the current XML node from the tree.
JSValue copy()
 Creates a copy of the current XML node.
JSValue next()
 Moves to the next sibling XML node.
JSValue serialize()
 Serializes the XML tree into a string.

Curl Class Reference

Properties

Public Attributes
getter/setter url
getter/setter method
getter/setter requestTimeout
getter/setter connectTimeout
getter/setter authType
getter/setter userAgent
getter/setter credentials
getter/setter contentType
getter/setter sslVerfyPeer
getter/setter sslVerfyHost
getter/setter sslCAcert
getter/setter proxy
getter/setter proxyCredentials
getter/setter proxyCAcert

Methods

Public Member Functions
JSValue perform([body])
 Performs a synchronous HTTP request and returns the result.
JSValue performBg([body])
 Starts an asynchronous (background) HTTP request.
JSValue getResult()
 Returns the result of a completed background HTTP request.

DBH Class Reference

Properties

Public Attributes
getter/setter dsn
getter/setter error
getter/setter isConnected

Methods

Public Member Functions
JSValue loadExtension(name)
 Loads a database extension (e.g., for SQLite).
JSValue testReactive(testSql, dropSql, reactiveSql)
 Checks the DB structure and executes reactive SQL queries to create/update tables.
JSValue affectedRows()
 Returns the number of rows affected by the last SQL query.
JSValue clearError()
 Clears the flag and text of the last DB error.
JSValue execQuery(query, [callback, callbackData])
 Executes an SQL query (SELECT) and passes each result row to a callback function.

JsonRpc Class Reference

Properties

Public Attributes
getter/setter url
getter/setter requestId
getter/setter requestTimeout
getter/setter connectTimeout
getter/setter credentials
getter/setter proxy
getter/setter proxyCredentials
getter/setter enableExceptions

Methods

Public Member Functions
JSValue perform(method, [params])
 Performs a JSON-RPC call to a remote method and returns the result.
JSValue isError()
 Checks for an error in the last JSON-RPC response.

Chat Class Reference

Methods

Public Member Functions
JSValue getMessage(allProps true|false)
 Gets an incoming chat message from the queue.
JSValue sendEx(protocol, messageProps)
 Sends a chat message using a properties object (extended version).
JSValue send(protocol, from, to, message)
 Sends a text chat message to the specified recipient via the given protocol.