bug fixed

This commit is contained in:
AmirHossein Mahmoodi
2025-05-27 10:45:50 +03:30
parent ec28b21cf8
commit e17c7b899c
5 changed files with 18 additions and 6 deletions

11
package-lock.json generated
View File

@@ -34,6 +34,7 @@
"@types/express": "^4.17.17", "@types/express": "^4.17.17",
"@types/jest": "^29.5.2", "@types/jest": "^29.5.2",
"@types/node": "^20.3.1", "@types/node": "^20.3.1",
"@types/redis": "^4.0.11",
"@types/supertest": "^6.0.0", "@types/supertest": "^6.0.0",
"@typescript-eslint/eslint-plugin": "^7.0.0", "@typescript-eslint/eslint-plugin": "^7.0.0",
"@typescript-eslint/parser": "^7.0.0", "@typescript-eslint/parser": "^7.0.0",
@@ -2272,6 +2273,16 @@
"integrity": "sha512-hKormJbkJqzQGhziax5PItDUTMAM9uE2XXQmM37dyd4hVM+5aVl7oVxMVUiVQn2oCQFN/LKCZdvSM0pFRqbSmQ==", "integrity": "sha512-hKormJbkJqzQGhziax5PItDUTMAM9uE2XXQmM37dyd4hVM+5aVl7oVxMVUiVQn2oCQFN/LKCZdvSM0pFRqbSmQ==",
"dev": true "dev": true
}, },
"node_modules/@types/redis": {
"version": "4.0.11",
"resolved": "https://registry.npmjs.org/@types/redis/-/redis-4.0.11.tgz",
"integrity": "sha512-bI+gth8La8Wg/QCR1+V1fhrL9+LZUSWfcqpOj2Kc80ZQ4ffbdL173vQd5wovmoV9i071FU9oP2g6etLuEwb6Rg==",
"deprecated": "This is a stub types definition. redis provides its own type definitions, so you do not need this installed.",
"dev": true,
"dependencies": {
"redis": "*"
}
},
"node_modules/@types/send": { "node_modules/@types/send": {
"version": "0.17.4", "version": "0.17.4",
"resolved": "https://registry.npmjs.org/@types/send/-/send-0.17.4.tgz", "resolved": "https://registry.npmjs.org/@types/send/-/send-0.17.4.tgz",

View File

@@ -45,6 +45,7 @@
"@types/express": "^4.17.17", "@types/express": "^4.17.17",
"@types/jest": "^29.5.2", "@types/jest": "^29.5.2",
"@types/node": "^20.3.1", "@types/node": "^20.3.1",
"@types/redis": "^4.0.11",
"@types/supertest": "^6.0.0", "@types/supertest": "^6.0.0",
"@typescript-eslint/eslint-plugin": "^7.0.0", "@typescript-eslint/eslint-plugin": "^7.0.0",
"@typescript-eslint/parser": "^7.0.0", "@typescript-eslint/parser": "^7.0.0",

View File

@@ -1,9 +1,9 @@
import { Injectable, OnModuleInit } from '@nestjs/common'; import { Injectable, OnModuleInit } from '@nestjs/common';
import { createClient } from 'redis'; import { createClient, RedisClientType } from 'redis';
@Injectable() @Injectable()
export class RedisService implements OnModuleInit { export class RedisService implements OnModuleInit {
private client; private client: RedisClientType;
async onModuleInit() { async onModuleInit() {
this.client = createClient({ this.client = createClient({

View File

@@ -34,7 +34,7 @@ export class SocketGateway implements OnGatewayConnection {
await this.socketService.clientConnection({ await this.socketService.clientConnection({
user_id: token.user_id, user_id: token.user_id,
telephone_id: token.telephone_id, telephone_id: String(token.telephone_id),
socket_id: client.id, socket_id: client.id,
event: 'connected', event: 'connected',
}); });
@@ -46,7 +46,7 @@ export class SocketGateway implements OnGatewayConnection {
client.on('disconnect', async (reason) => { client.on('disconnect', async (reason) => {
await this.socketService.clientConnection({ await this.socketService.clientConnection({
user_id: token.user_id, user_id: token.user_id,
telephone_id: token.telephone_id, telephone_id: String(token.telephone_id),
socket_id: client.id, socket_id: client.id,
event: 'disconnected', event: 'disconnected',
description: reason, description: reason,

View File

@@ -10,7 +10,7 @@ import { RedisService } from 'src/redis/redis.service';
export interface ClientToken { export interface ClientToken {
user_id: number; user_id: number;
telephone_id: string; telephone_id: number;
} }
@Injectable() @Injectable()
@@ -110,7 +110,7 @@ export class SocketService {
async getAllOnlineClients(): Promise<ClientToken[]> { async getAllOnlineClients(): Promise<ClientToken[]> {
const client = this.redisService.getClient(); const client = this.redisService.getClient();
const keys = await client.keys('online_clients:*'); const keys = await client.keys('online_clients:*');
return keys.map((key) => { return keys.map((key: string) => {
const [user_id, telephone_id] = key.split(':')[1].split('-').map(Number); const [user_id, telephone_id] = key.split(':')[1].split('-').map(Number);
return { user_id, telephone_id }; return { user_id, telephone_id };
}); });