add online/offline api

This commit is contained in:
AmirHossein Mahmoodi
2025-05-06 16:44:27 +03:30
parent 43fd86f008
commit 63fa018851

View File

@@ -1,7 +1,7 @@
import { HttpService } from '@nestjs/axios'; import { HttpService } from '@nestjs/axios';
import { Injectable, Logger } from '@nestjs/common'; import { Injectable, Logger } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm'; import { InjectRepository } from '@nestjs/typeorm';
import { firstValueFrom } from 'rxjs'; import { firstValueFrom, retry } from 'rxjs';
import { Socket } from 'socket.io'; import { Socket } from 'socket.io';
import { Repository } from 'typeorm'; import { Repository } from 'typeorm';
import { ClientConnectionDto } from './dto/clientConnection.dto'; import { ClientConnectionDto } from './dto/clientConnection.dto';
@@ -30,7 +30,9 @@ export class SocketService {
if (endpoint) { if (endpoint) {
const url = `${process.env.SERVICE_URL}${endpoint}?telephone_id=${client.client_id}`; const url = `${process.env.SERVICE_URL}${endpoint}?telephone_id=${client.client_id}`;
try { try {
await firstValueFrom(this.httpService.get(url)); await firstValueFrom(
this.httpService.get(url, { timeout: 3000 }).pipe(retry(3)),
);
} catch (error) { } catch (error) {
this.logger.error( this.logger.error(
`❌ Failed to notify ${data.event} for client ${client.client_id}:`, `❌ Failed to notify ${data.event} for client ${client.client_id}:`,