update
This commit is contained in:
@@ -15,13 +15,13 @@ export class SocketGateway implements OnGatewayConnection {
|
||||
constructor(private socketService: SocketService) {}
|
||||
|
||||
async handleConnection(client: Socket) {
|
||||
await this.socketService.ClientConnection({
|
||||
await this.socketService.clientConnection({
|
||||
client_id: client.handshake.auth.token,
|
||||
socket_id: client.id,
|
||||
event: 'connected',
|
||||
});
|
||||
client.on('disconnect', async (reason) => {
|
||||
await this.socketService.ClientConnection({
|
||||
await this.socketService.clientConnection({
|
||||
client_id: client.handshake.auth.token,
|
||||
socket_id: client.id,
|
||||
event: 'disconnected',
|
||||
@@ -31,28 +31,31 @@ export class SocketGateway implements OnGatewayConnection {
|
||||
}
|
||||
|
||||
@SubscribeMessage('sendMessageToClients')
|
||||
handleSendMessage(sendMessageDto: SendMessageDto) {
|
||||
const clients = this.getConnectedClients(sendMessageDto.auth);
|
||||
async handleSendMessage(sendMessageDto: SendMessageDto) {
|
||||
const clients = this.getConnectedClients(sendMessageDto.auths);
|
||||
if (clients.length === 0) {
|
||||
return {
|
||||
status: 0,
|
||||
message: 'Failed to find the clients!',
|
||||
};
|
||||
}
|
||||
return this.socketService.sendMessageToClients(
|
||||
|
||||
const result = await this.socketService.sendMessageToClients(
|
||||
clients,
|
||||
sendMessageDto.data,
|
||||
sendMessageDto.event,
|
||||
);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
getConnectedClients(auth: string[]): Socket[] {
|
||||
getConnectedClients(auths: string[]): Socket[] {
|
||||
const connectedClients = this.server.sockets.sockets;
|
||||
const clients: Socket[] = [];
|
||||
|
||||
const clients = [];
|
||||
for (const connectedClient of connectedClients) {
|
||||
if (auth.includes(connectedClient[1].handshake.auth.token)) {
|
||||
clients.push(connectedClient[1]);
|
||||
for (const client of connectedClients.values()) {
|
||||
if (auths.includes(client.handshake.auth.token)) {
|
||||
clients.push(client);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user