update
This commit is contained in:
@@ -28,6 +28,7 @@ export class NotificationsGateway implements OnGatewayConnection, OnGatewayDisco
|
||||
server!: Server;
|
||||
|
||||
private readonly logger = new Logger(NotificationsGateway.name);
|
||||
private readonly pingIntervals = new Map<string, NodeJS.Timeout>();
|
||||
|
||||
constructor(
|
||||
@Inject(forwardRef(() => NotificationService))
|
||||
@@ -41,6 +42,13 @@ export class NotificationsGateway implements OnGatewayConnection, OnGatewayDisco
|
||||
const authenticatedClient = client as AuthenticatedSocket;
|
||||
this.logger.log(`Admin connected: ${authenticatedClient.adminId}`);
|
||||
this.handleJoinRoom(authenticatedClient);
|
||||
|
||||
// Start ping interval for this client
|
||||
// const intervalId = setInterval(() => {
|
||||
// void authenticatedClient.emit('ping', { message: 'ping', timestamp: new Date().toISOString() });
|
||||
// }, 2000);
|
||||
|
||||
// this.pingIntervals.set(client.id, intervalId);
|
||||
} catch (error) {
|
||||
this.logger.error(
|
||||
`Connection authentication failed: ${error instanceof Error ? error.message : 'Unknown error'}`,
|
||||
@@ -53,6 +61,13 @@ export class NotificationsGateway implements OnGatewayConnection, OnGatewayDisco
|
||||
handleDisconnect(client: Socket) {
|
||||
this.logger.log(`Client disconnected: ${client.id}`);
|
||||
this.handleLeaveRoom(client);
|
||||
|
||||
// Clear ping interval for this client
|
||||
// const intervalId = this.pingIntervals.get(client.id);
|
||||
// if (intervalId) {
|
||||
// clearInterval(intervalId);
|
||||
// this.pingIntervals.delete(client.id);
|
||||
// }
|
||||
}
|
||||
|
||||
sendInAppNotification(repipient: { adminId: string; restaurantId: string }, payload: IInAppNotificationPayload) {
|
||||
@@ -65,7 +80,7 @@ export class NotificationsGateway implements OnGatewayConnection, OnGatewayDisco
|
||||
private getRoom(adminId: string, restaurantId: string) {
|
||||
return `restaurant:${restaurantId}-admin:${adminId}`;
|
||||
}
|
||||
|
||||
|
||||
handleLeaveRoom(client: AuthenticatedSocket) {
|
||||
const room = this.getRoom(client.adminId!, client.restId!);
|
||||
void client.leave(room);
|
||||
|
||||
Reference in New Issue
Block a user