Skip to content

Socket.IO

SAYMON uses Socket.IO library to implement a Comet server.

Socket.IO enables low-latency, bidirectional, and event-based communication between a client and a server.

Although Socket.IO uses WebSocket for transport when possible, it adds additional metadata to each packet. A WebSocket client won't be able to connect to a Socket.IO server, and a Socket.IO client won't be able to connect to a plain WebSocket server.

Connect to server

To connect to a Socket.IO server, use the socket.io-client package.

In this example, a Socket.IO client connects to a SAYMON server, subscribes to an Incidents event, and prints out every incident that occurs in the system.

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

// Comet settings
const COMET_CONNECT_TIMEOUT = 5000;
const sessionId = "..."
const conf = {
    cometHost: 'https://example.com',
    cometPort: '1234',
};

// Connect to a comet server
const url = `${conf.cometHost}` + (conf.cometPort ? `:${conf.cometPort}` : '');
const cn = comet.connect(url, {
    query: { forceNew: true, sessionId },
    timeout: COMET_CONNECT_TIMEOUT,
});

// Subscribe to an Incidents topic 
cn.emit('add-topics', 'incidents');

// Hande the server response
cn.on('incidents', msg => {
    console.log(msg);
});

SAYMON Events

SAYMON uses custom Socket.IO events to update parts of the system in real-time.

Each event corresponds to an internal Kafka topic.

Event Description Kafka topic
snmp-trap Subscribe to SNMP Traps SERVER_EVENT
mqtt Subscribe to MQTT messages. SERVER_EVENT
job-added This event fires when a job is created alongside the operation execution. SERVER_EVENT
job-result-received Event that fires when the job result was received. SERVER_EVENT
model-changed Event that fires when a user adds, modifies or removes an Object or a Link. MODEL_EVENT
client-notification Event that fires when a client notification is received. CLIENT_EVENT
stat Subscribe to the stat updates of a specified entity. ENTITY_STAT
state-change Fires when the entity's state changes. ENTITY_STATE
incidents Fires when an incident occurs, changes or moves from active list to history. INCIDENT
incident-count Fires when the number of active incidents changes. INCIDENT
bulk-finished Fires when the bulk operation finishes. SERVER_EVENT
error Fires when there is an error connecting to the Comet server.
custom-style-change Fires when a user changes UI representation of an entity.