bug fixed
This commit is contained in:
11
package-lock.json
generated
11
package-lock.json
generated
@@ -34,6 +34,7 @@
|
||||
"@types/express": "^4.17.17",
|
||||
"@types/jest": "^29.5.2",
|
||||
"@types/node": "^20.3.1",
|
||||
"@types/redis": "^4.0.11",
|
||||
"@types/supertest": "^6.0.0",
|
||||
"@typescript-eslint/eslint-plugin": "^7.0.0",
|
||||
"@typescript-eslint/parser": "^7.0.0",
|
||||
@@ -2272,6 +2273,16 @@
|
||||
"integrity": "sha512-hKormJbkJqzQGhziax5PItDUTMAM9uE2XXQmM37dyd4hVM+5aVl7oVxMVUiVQn2oCQFN/LKCZdvSM0pFRqbSmQ==",
|
||||
"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": {
|
||||
"version": "0.17.4",
|
||||
"resolved": "https://registry.npmjs.org/@types/send/-/send-0.17.4.tgz",
|
||||
|
||||
@@ -45,6 +45,7 @@
|
||||
"@types/express": "^4.17.17",
|
||||
"@types/jest": "^29.5.2",
|
||||
"@types/node": "^20.3.1",
|
||||
"@types/redis": "^4.0.11",
|
||||
"@types/supertest": "^6.0.0",
|
||||
"@typescript-eslint/eslint-plugin": "^7.0.0",
|
||||
"@typescript-eslint/parser": "^7.0.0",
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import { Injectable, OnModuleInit } from '@nestjs/common';
|
||||
import { createClient } from 'redis';
|
||||
import { createClient, RedisClientType } from 'redis';
|
||||
|
||||
@Injectable()
|
||||
export class RedisService implements OnModuleInit {
|
||||
private client;
|
||||
private client: RedisClientType;
|
||||
|
||||
async onModuleInit() {
|
||||
this.client = createClient({
|
||||
|
||||
@@ -34,7 +34,7 @@ export class SocketGateway implements OnGatewayConnection {
|
||||
|
||||
await this.socketService.clientConnection({
|
||||
user_id: token.user_id,
|
||||
telephone_id: token.telephone_id,
|
||||
telephone_id: String(token.telephone_id),
|
||||
socket_id: client.id,
|
||||
event: 'connected',
|
||||
});
|
||||
@@ -46,7 +46,7 @@ export class SocketGateway implements OnGatewayConnection {
|
||||
client.on('disconnect', async (reason) => {
|
||||
await this.socketService.clientConnection({
|
||||
user_id: token.user_id,
|
||||
telephone_id: token.telephone_id,
|
||||
telephone_id: String(token.telephone_id),
|
||||
socket_id: client.id,
|
||||
event: 'disconnected',
|
||||
description: reason,
|
||||
|
||||
@@ -10,7 +10,7 @@ import { RedisService } from 'src/redis/redis.service';
|
||||
|
||||
export interface ClientToken {
|
||||
user_id: number;
|
||||
telephone_id: string;
|
||||
telephone_id: number;
|
||||
}
|
||||
|
||||
@Injectable()
|
||||
@@ -110,7 +110,7 @@ export class SocketService {
|
||||
async getAllOnlineClients(): Promise<ClientToken[]> {
|
||||
const client = this.redisService.getClient();
|
||||
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);
|
||||
return { user_id, telephone_id };
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user