Web socket - persistent connection

Please do elaborate on socket.io

How can it be used within the Losant Environment?

The way I need to use it is as follows:

  1. Create a socket connection useing a two-way communication (pushing information from Losant to and API)

1.1 Where can I plug the following socket connection code:

const Client = require(‘socket.io-client’);
socket = Client(SOCKET_SERVER_URL, { jsonp: false });
socket.on(‘connect_error’, (err) => {
console.log(err);
throw ‘Socket connection damaged, please check’;
});

  1. Create auth event to authenticate the API’s client id and client password (establish socket stability). Get a uth event for successful authentication.
    2.2 Where can I plug the following verification code:
    socket.emit(‘auth’, {
    client_id: ‘CLIENT_ID’,
    client_secret: ‘CLIENT_PASSWORD’,
    });
    socket.on(‘auth’, (data) => {
    console.log(data);
    });

2.2 Where will I be able to read the successful/failed authentication (JSON structure) for the auth event

  1. Push the data through the established socket.io once every X [min] with the event name: reading
    3.1 Where can I plug the following data push code:
    socket.emit(‘readings’,{
    ‘message_id’: ‘<MESSAGE_ID>’,
    ‘data’: {
    ‘Device_ID’: ‘’,
    ‘readings’: [{
    ‘Device_ID’: ‘’,
    ‘reading_time’:‘epoch_value’,
    ‘Name_of_Attribute_1’: ‘numerical_value’,
    ‘Name_of_Attribute_2’: ‘numerical_value’,
    ‘Name_of_Attribute_3’: ‘numerical_value’,
    ‘Name_of_Attribute_4’: ‘numerical_value’,
    ‘Name_of_Attribute_5’: ‘numerical_value’
    }]
    },
    });
    socket.on(‘errors’, (data) => {
    console.log(data);
    });
    socket.on(‘ack’, (data) => {
    console.log(data);
    });

3.2 Where will I be able to validate the following (JSON structure) ack event?
{
“code”, “”,
“ack”: true,
“id”: “<MESSAGE_ID>”
}