var io = require('socket.io-client'); var lst = [] const _clear_lst = () => { if (lst.length <= 199) return const chunk = Math.floor((lst.length / 2)) lst = lst.slice(chunk, chunk + lst.length); } const multisessionIdControll = (msgId) => { _clear_lst() let index = lst.findIndex((x) => x.id == msgId) console.log('INDEX: ', index) if (index == -1) { lst.push({ id: msgId }) } else { console.log('IGNORED ID: ', msgId) return } // console.log('LIST OF ID MESSAGE lst: ', lst) console.log('PASSOU.................................ID: ', msgId) } const initIO = (url) => { const socket = io(url, { reconnect: true }); socket.on('connect', async () => { console.log('Made socket connection2'); }); socket.on('messageId', messageId => { console.log('-------> messageId: ', messageId); multisessionIdControll(messageId) console.log('socket lst: ', lst) }); return socket; }; module.exports = { initIO, lst }