Websocker Controller
The same events triggered by the webhook are sent via the websocket.
Here's a step-by-step guide for connecting to Socket.IO on the client/browser side, translated into English:
1. Include the Socket.IO Library
First, you need to include the Socket.IO client in your HTML page. You can do this by adding the following script tag to the header of your HTML:
<script src="https://cdn.socket.io/4.0.0/socket.io.min.js"></script>
Ensure you are using the latest version of the Socket.IO library or a version that is compatible with your server.
2. Connect to the Socket.IO Server
After including the library, you can establish a connection to the Socket.IO server using the following JavaScript code:
// Replace 'wss://api.domain.com' with your Socket.IO server's URL
const socket = io('wss://api.domain.com');
This code creates a new socket connection to the specified server.
3. Handling Connection Events
You can add handlers to deal with connection events, such as when the connection is successfully established or when there is a connection error:
socket.on('connect', function() {
console.log('Connected to the Socket.IO server!');
});
4. Communicating with the Server
Once the connection is established, you can start sending and receiving messages. For example, to send a message:
socket.emit('ping.server', 'ping');
socket.on('pong.server', function(data) {
console.log(data);
});
And to receive messages from the server:
socket.on('messages.upsert', function(msg) {
console.log('Message from server:', msg);
});
socket.on('qrcode.update', function(msg) {
console.log('Message from server:', msg);
});
socket.on('connection.update', function(msg) {
console.log('Message from server:', msg);
});
socket.on('auth.error', function(msg) {
console.log('Message from server:', msg);
});
[...]
5. Disconnecting
When you want to end the connection, you can do so using:
socket.disconnect();
This method will close the connection between your client and the Socket.IO server.
📄️ Defining websocket
Defining websocket
📄️ Retrieving information
Retrieving information
📄️ Updating information
Updating information
📄️ Deleting data
Deleting data