Rate this page:

How to handle inbound WebSocket connections

Our platform provides the WebSocket module for the communication between a client and a third-party service in real-time. With this module, you can accept inbound WebSocket connections and send data through them.

Accepting an inbound connection

To make inbound WebSocket connections available, use the VoxEngine.allowWebSocketConnections method. Then, subscribe to the AppEvents.WebSocket event. Now you can accept the incoming connection and get a WebSocket object: event.WebSocket.

An accessSecureURL to a WebSocket can be obtained from the HTTP session initialization request or directly from the AppEvents.Started event. Please note that 'https' should be changed to 'wss' in the URL.

When you get the object, you can send data via the WebSocket using the call.sendMediaTo method.

See the picture below to learn how it all works:

Code

The code for your "InboundWebSocket" scenario will look like this:

Inbound WebSocket

Inbound WebSocket

Learn more about setting up the Voximplant side (application, rule, user) and the server side at How to send call audio via WebSocket.