Rate this page:

Creating an outbound connection

The first thing you should do to make an outbound connection is to create a WebSocket object using the VoxEngine.createWebSocket method. It accepts 2 parameters: URL in the format of 'wss: // + domain + path' and protocols (optional).

If everything is ok, you can start sending data to the WebSocket, for example, it could be audio sent via the call.sendMediaTo method. In case of audio, you can set a preferred encoding format, a tag, and some custom parameters. If you don’t set an encoding, PCM8 will be selected by default. The WebSocket.send method, in turn, will be sending a decoded data stream in JSON format via the WebSocket. Thus, you’ll be getting messages from the service handling your requests.

The WebSocket.close method will close the connection. Please note that the connection can be closed both from the client-side and the server-side.

See the picture below to learn how it all works:

The code for the scenario will look like this:

WebSocket scenario

WebSocket scenario