Socket.IO
SAYMON uses Socket.IO v4.5.0
library to implement a Comet server.
Socket.IO enables low-latency, bidirectional, and event-based communication between a client and a SAYMON 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');
// Handle server response
cn.on('incidents', msg => {
console.log(msg);
});
SAYMON Events
SAYMON uses custom Socket.IO events to notify clients about updates of parts of the system in real-time.
Each event corresponds to an internal Kafka topic.
Event | Description | Kafka topic |
---|---|---|
Fires when the bulk operation finishes. |
SERVER_EVENT |
|
Fires when a user changes UI representation of an entity. |
— |
|
Fires when the server receives data from server extension. * Event name is defined by the server extension. |
SERVER_EVENT |
|
Event that fires when a client notification is received. |
CLIENT_EVENT |
|
Fires when there is an error connecting to the Comet server. |
— |
|
Fires when an incident occurs, changes or moves from active list to history. |
INCIDENT |
|
Fires when the number of active incidents changes. |
INCIDENT |
|
This event fires when a job is created alongside the operation execution. |
SERVER_EVENT |
|
Event that fires when the job result was received. |
SERVER_EVENT |
|
Subscribe to MQTT messages. |
SERVER_EVENT |
|
Event that fires when a user adds, modifies or removes an Object or a Link. |
MODEL_EVENT |
|
Event that fires, when a stat of the specified entity is updated. |
ENTITY_STAT |
|
Fires when the entity’s state changes. |
ENTITY_STATE |
|
Subscribe to SNMP Traps. |
SERVER_EVENT |