Status API uses Socket.IO

Hi,
I am new to socket.io. I keep getting the connection error when try to establish the websocket connection, can anyone helps with it?

const io = require('socket.io-client');

// Replace with your actual access token and status channel ID
const accessToken = 'Your_Access_Token_Here'; // replace with my own access token
const statusChannel = 'Your_Status_Channel_ID_Here'; // replace with the channel i got from restfult api

// Establish a WebSocket connection
const socket = io.connect('https://rms.teltonika-networks.com/status', {
    transports: ['websocket'],
    query: {
        'token': accessToken
    }
});

// Listen for the connection event
socket.on('connect', () => {
    console.log('Successfully connected to the server.');

    // Subscribe to the status channel
    socket.emit('subscribe', {
        "channel": statusChannel
    });

    console.log(`Subscribed to status channel: ${statusChannel}`);
});

// Handle incoming messages on the subscribed channel
socket.on(statusChannel, (message) => {
    console.log('Received message:', message);
});

// Listen for connection errors
socket.on('connect_error', (err) => {
    console.error('Connection error:', err.message);
});

This topic was automatically closed after 15 days. New replies are no longer allowed.