http://localhost:8001//socket.io//5 tentatives · délai 1 sconst socket = io('/', { path: '/socket.io/', auth: { user_id: 'user_42', username: 'Alice' }, reconnection: true, reconnectionAttempts: 5, reconnectionDelay: 1000, });
{
"socketId": "abc12345",
"serverTime": "2026-06-07T10:00:00.000Z"
}
socket.on('connection-confirmed', (data) => { console.log('Socket ID:', data.socketId); });
{
"id": "n_1749290400.123",
"type": "info", // info | success | warning | error
"title": "Mon titre",
"message": "Mon message",
"data": { "event": "order.created", "ref": "ORD-42" }, // null si absent
"sender": "Alice",
"channel": "devops", // null si broadcast
"timestamp": "2026-06-07T10:00:00.000Z"
}
socket.on('notification-received', (n) => { console.log(`[${n.type}] ${n.title}: ${n.message}`); if (n.data) console.log('Data:', n.data); });
{
"notificationId": "n_1749290400.123",
"channel": "devops", // null si broadcast
"timestamp": "2026-06-07T10:00:00.000Z"
}
socket.on('notification-sent', (data) => { console.log('â EnvoyĂ©, id:', data.notificationId); });
{
"channel": "devops",
"message": "Vous avez rejoint « devops »",
"clientCount": 3,
"pendingCount": 0,
"timestamp": "2026-06-07T10:00:00.000Z"
}
{
"channel": "devops",
"message": "Vous avez quitté « devops »",
"timestamp": "2026-06-07T10:00:00.000Z"
}
get-channels)
listen
[
{ "name": "devops", "clientCount": 3 },
{ "name": "orders", "clientCount": 1 }
]
socket.on('channels-list', (channels) => { channels.forEach(c => console.log(c.name, c.clientCount)); });
get-stats
listen
{
"connectedClients": 5,
"activeChannels": 2,
"uptime": 3600.42, // secondes
"timestamp": "2026-06-07T10:00:00.000Z"
}
{
"errors": ["Le champ 'title' est obligatoire", "..."]
}
socket.on('error-message', (err) => { err.errors.forEach(e => console.error(e)); });
"nom-du-channel" // string directement, pas un objet
socket.emit('join-channel', 'devops');
"nom-du-channel" // string directement
socket.emit('leave-channel', 'devops');
server-stats)
emit
// aucun payload
socket.emit('get-stats');
channels-list)
emit
// aucun payload
socket.emit('get-channels');
channel absent)
emit
{
"channel": "devops", // optionnel â absent = broadcast
"type": "info", // info | success | warning | error
"title": "Mon titre", // obligatoire
"message": "Mon message", // obligatoire
"data": { // optionnel, objet libre
"event": "order.created",
"reference": "ORD-123",
"custom": "data"
}
}
socket.emit('send-notification', { channel: 'devops', type: 'warning', title: 'Alerte CPU', message: 'CPU Ă 90 % sur prod-01', data: { host: 'prod-01', metric: 'cpu', value: 90 }, });
const socket = io('/', { path: '/socket.io/', reconnection: true, reconnectionAttempts: 5, reconnectionDelay: 1000, }); socket.on('connect', () => { socket.emit('join-channel', 'notifications-app'); socket.emit('get-stats'); }); socket.on('notification-received', (notif) => { console.log(`[${notif.type}] ${notif.title}: ${notif.message}`); console.log('Data:', notif.data); }); socket.on('error-message', (err) => { console.error('Erreurs:', err.errors); });