fixed bugs with the web socket
parent
49a5471c01
commit
23438a0e7f
|
|
@ -84,6 +84,15 @@ export class MetricsGateway implements OnGatewayInit, OnGatewayConnection, OnGat
|
|||
}
|
||||
}
|
||||
|
||||
@SubscribeMessage('subscribe-metric')
|
||||
async handleSubscribeMetric(client: Socket, payload: { metric: string, interval?: number }) {
|
||||
const stopUpdates = await this.sendPeriodicUpdates(payload.metric, payload.interval);
|
||||
|
||||
// Сохраняем функцию остановки для этого клиента
|
||||
client.on('disconnect', () => stopUpdates());
|
||||
client.on('unsubscribe-metric', () => stopUpdates());
|
||||
}
|
||||
|
||||
// Метод для периодической отправки обновлений
|
||||
async sendPeriodicUpdates(metric: string, interval: number = 5000) {
|
||||
const timer = setInterval(async () => {
|
||||
|
|
|
|||
Loading…
Reference in New Issue