socket.io
to emit real-time events, leveraging WebSocket technology. This makes integration development more efficient and straightforward for developers. WebSocket provides a full-duplex communication channel over a single, long-lasting connection, enabling real-time data flow between the client and the server.
Operating
WebSocket can only be connected after executing theset
command on the instance. This allows the WebSocket to be specific to each instance, and real-time communication is restricted to that instance.
- Functionality: Ideal for scenarios where you want more isolated real-time communication, focused on a single instance, allowing greater control and segmentation of events.
-
Connection: WebSocket connection requires the use of
/instance_name
in the URL:
Connecting to the WebSocket
In traditional mode, use the following URL format:instance_name
with your specific instance name.
WebSocket Connection Example
Here is a basic example of how to establish a WebSocket connection using JavaScript:event_name
with the specific event you want to listen to.
Handling Events
Once connected, you can listen to various events emitted by the server. Each event can carry data relevant to the event’s context. For instance, if you are listening for message updates, you may receive data containing the updated message content and metadata.Closing the Connection
To close the WebSocket connection, use thedisconnect
method: