VoxEngine
Functions
addEventListener
Adds a handler for the specified AppEvents event. Use only functions as handlers; anything except a function leads to the error and scenario termination when a handler is called.
Parameters
allowWebSocketConnections
Allows accepting incoming connections to ensure WebSocket bidirectional exchange.
callConference
Makes a call to a conference via Conference module. If there is no such conference, it is created in the first method’s call. The method is designed to be called in a simple incoming scenario, then it can trigger another special scenario which contains logic of the conference. The method can trigger the Failed event in 60 sec, see the session limits for details.
Parameters
callPSTN
Starts an outgoing call to the specified phone number. Calls that are more expensive than 20 cents per minute and calls to Africa are blocked by default for security reasons.
The method can trigger the CallEvents.Failed event in 60 sec, see the session limits for details.
Parameters
callSIP
Starts an outgoing call to the external SIP system or to another user of the same application. Supported codecs are: G.722, G.711 (u-law and a-law), Opus(https://opus-codec.org/), ILBC(https://webrtc.org/license/ilbc-freeware/), H.264, VP8(https://tools.ietf.org/html/rfc6386). The method can trigger the CallEvents.Failed event in 60 sec, see the session limits for details.
Parameters
callUser
Starts an outgoing call to the specified Voximplant user. The JavaScript scenario that uses this method and user being called should be both associated with the same Voximplant application.
The method can trigger the CallEvents.Failed event in 60 sec, see the session limits for details.
Parameters
callUserDirect
Start an outgoing call to the specified Voximplant user in peer-to-peer mode.
The JavaScript scenario with this method and the destination user should be both within the same Voximplant application.
Audio playback and recording does not work. P2P mode is available only for calls between SDKs.
The method can trigger the CallEvents.Failed event in 60 sec, see the session limits for details. IMPORTANT: calling this method makes impossible to use the non-P2P mode for a new call and specified incomingCall.
So the following methods cannot be used: Call.say, Call.sendDigits, Call.sendMediaTo, Call.stopMediaTo.
Parameters
callWhatsappUser
Starts an outgoing call to the specified WhatsApp user. This method requires a WhatsApp Business account. Read more in the WhatsApp Business-initiated calls article.
Parameters
createASR
Creates a new ASR instance and starts recognition. You can attach sources later via the VoxMediaUnit sendMediaTo method.
Add the following line to your scenario code to use the function:
Parameters
createConference
Creates a new Conference instance. You can attach media streams later via the Conference.sendMediaTo or VoxEngine.sendMediaBetween methods.
Add the following line to your scenario code to use the function:
Parameters
createRecorder
Creates a new Recorder or ConferenceRecorder instance. You can attach sources later via the VoxMediaUnit sendMediaTo method.
Add the following line to your scenario code to use the function:
Parameters
createSequencePlayer
Creates a new SequencePlayer instance. You can attach media streams later via the SequencePlayer.sendMediaTo or VoxEngine.sendMediaBetween methods.
Parameters
createStreamingAgent
Creates a new StreamingAgent instance. You can attach sources later via the VoxMediaUnit sendMediaTo method.
Add the following line to your scenario code to use the function:
Parameters
createToneScriptPlayer
Creates a new Player instance with the specified ToneScript(https://en.wikipedia.org/wiki/ToneScript) sequence. You can attach media streams later via the Player.sendMediaTo or VoxEngine.sendMediaBetween methods.
Parameters
createTTSPlayer
Creates a new Player instance with the specified text (TTS is used to play the text). You can attach media streams later via the Player.sendMediaTo or VoxEngine.sendMediaBetween methods.
If the text length exceeds 1500 characters, the PlayerEvents.PlaybackFinished event is triggered with error description. After the very first playing, a phrase is cached; each createTTSPlayer instance stores the cache data up to 2 weeks. Note that cache addresses only the URL, without additional headers. The cached phrase is available for all applications and further sessions.
Parameters
createURLPlayer
Creates a new Player instance with specified audio file URL. You can attach media streams later via the Player.sendMediaTo or VoxEngine.sendMediaBetween methods.
After the very first playback, a file is cached; each ‘createURLPlayer’ instance stores the cache data up to 2 weeks. Note that cache addresses only the URL, without additional headers. The cached file is available for all applications and further sessions.
File download has a timeout of 12 seconds. Reaching this timeout causes the “Timeout is reached” error. The supported file formats are: mp3, ogg, flac, and wav (mp3, speex, vorbis, flac, and wav codecs respectively). Maximum file size is 10 Mb.
You can attach media streams later via the Player.sendMediaTo or VoxEngine.sendMediaBetween methods.
method etc. IMPORTANT: each call object can send media to any number of other calls (media units), but can receive only one audio stream. A new incoming stream always replaces the previous one.
Parameters
createWebSocket
Creates a new WebSocket instance. You can attach media streams later via the WebSocket.sendMediaTo or VoxEngine.sendMediaBetween methods.
Parameters
customData
Set or get custom string associated with current JavaScript session. There are two kinds of the customData values: one is for JavaScript session (i.e., VoxEngine object), another is for the particular call (i.e., Call.customData and web SDK parameter of the method). It is possible to use them at the same time because they are independent entities. Remember that if you receive some value from web SDK, it does not overwrite the VoxEngine’s value. Any of customData’s type values can be later obtained from call history via management API or control panel.
Parameters
destroyConference
Destroys an existing conference. Add the following line to your scenario code to use the function:
Parameters
disableStatisticsForIncomingWebsockets
Disables statistics for incoming WebSockets
disableTraceForIncomingWebsockets
Disables trace for incoming WebSockets
easyProcess
Adds all default event listeners to pass signaling information between two calls. The source code of the method is available on GitHub(https://github.com/voximplant/easyprocess).
Parameters
enableStatisticsForIncomingWebsockets
Enables statistics for incoming WebSockets
enableTraceForIncomingWebsockets
Enables trace for incoming WebSockets
enqueueACDRequest
Adds a new request to the specified queue. The request is dispatched to the free agent according to the agent’s status (must be “Ready”) and skills. Add the following line to your scenario code to use the function:
Parameters
enqueueTask
Appends the task to the SmartQueue.
Parameters
forwardCallToPSTN
Helper function to forward an incoming call to PSTN. The method handles numbers only in the E.164 format by default. If you need to handle a number in another format, pass an additional function (as a parameter) to the method. For more details see the GitHub repo.
Parameters
forwardCallToSIP
Helper function to forward an incoming call to a dialed SIP URI. For more details see the GitHub repo.
Parameters
forwardCallToUser
Helper function to forward an incoming call to a user of the current application. Dialed number is considered as username. For more details see the GitHub repo.
Parameters
forwardCallToUserDirect
Helper function to forward an incoming call to a user of the current application in the P2P mode. Dialed number is considered as username. Due to the P2P mode, media player and recording do not work. For more details see the GitHub repo.
Parameters
getSecretValue
Gets a value of the secret stored in the Voximplant panel.
Parameters
playSoundAndHangup
Helper function to play sound to incoming call. It terminates a call in three cases:
- playback is finished
- call failed
- call disconnected
Parameters
removeEventListener
Removes a handler for the specified AppEvents event.
Parameters
sendMediaBetween
Start sending media between mediaUnit1 and mediaUnit2. This method binds two audio/video streams.
Parameters
stopMediaBetween
Stops sending media between mediaUnit1 and mediaUnit2.
Parameters
terminate
Terminates the current JavaScript session. All audio/video streams are disconnected and scenario execution stops. Note that after this function, only the AppEvents.Terminating and AppEvents.Terminated events are triggered.
NOTE: if you are using this method inside a code block (e.g., an “if” block), it does not stop the execution of the current block. Use return; after using this method to exit the current code block.