209 похожих чатов

Import { Logger, UseGuards } from '@nestjs/common'; import { ApiSecurity }

from '@nestjs/swagger';
import { OnGatewayConnection, SubscribeMessage, WebSocketGateway, WsResponse } from '@nestjs/websockets';
import { filter, map, Observable } from 'rxjs';
import { DEVICE_TOKEN_HEADER } from 'src/common/constant';
import { MessagingNotificationEventsEnum } from 'src/messaging/messaging-types/messaging-notification-events.enum';
import { Roles } from 'src/role/role.decorator';
import { RoleGuard } from 'src/role/role.guard';
import { Role } from 'src/role/role.type';
import { CurrentPlayer, CurrentPlayerType } from '../../../auth/auth-decorators/current-player.decorator';
import { NotificationEventDto, NotificationEventType } from '../../messaging-types/notification.dto';
import { MessagingNotificationEventsEventsService } from '../messaging-notification-events-services/messaging-notification-events-events.service';

@WebSocketGateway({
cors: {
origin: '*',
},
path: '/ws/messaging-notifications',
})
export class MessagingNotificationEventsGateway implements OnGatewayConnection {
private readonly logger = new Logger(MessagingNotificationEventsGateway.name);

constructor(private readonly messagingNotificationEventsEventsService: MessagingNotificationEventsEventsService) {}

// eslint-disable-next-line @typescript-eslint/no-explicit-any
handleConnection(client: any, ...args: any[]) {
client.headers = args[0].headers;
}

@ApiSecurity(DEVICE_TOKEN_HEADER)
@UseGuards(RoleGuard)
@Roles(Role.TEST, Role.USER)
@SubscribeMessage(MessagingNotificationEventsEnum.MessagingNotificationEventsStream)
onMessagingNotificationEventsStream(
@CurrentPlayer() player: CurrentPlayerType
): Observable<WsResponse<NotificationEventDto>> {
this.logger.debug(`onMessagingNotificationEventsStream: ${player.id}`);
return this.messagingNotificationEventsEventsService.listenMessagingNotificationEventsStream().pipe(
filter((event) => {
if (
event.type === NotificationEventType.UpdatedNotification &&
!!event.notification?.playerNotificationList.find((v) => v.playerId === player.id)
) {
return true;
}
if (event.type === NotificationEventType.DeletedPlayerNotification && event.playerId === player.id) {
return true;
}
if (event.type === NotificationEventType.DeletedNotification && event.playerId === player.id) {
return true;
}
return false;
}),
map((data) => ({ event: MessagingNotificationEventsEnum.MessagingNotificationEventsStream, data }))
);
}
}

4 ответов

10 просмотров

Тоесть когда в сервис прилетают данные, то сработает эта штука, я правильно же понимаю?

Стоп, это же прослушиваем событие какое-то и проверяем что там за тайп, потмо не понятные махинации в сервисе, и дальше что? Если мне нужно только емитить события, чет я слишком тупой до этого

IL'shat-Khamitov Автор вопроса
Vincent 🐲 Adler 🇺🇦
Стоп, это же прослушиваем событие какое-то и прове...

народ копит подключения сокетные и птом по этим подключениям ходит и пуляет события, а тут проще, шлем событие в поток, поток при выдаче фильтруется по юзер ид, и не нужно копить людей и по ним ходить

IL'shat Khamitov
народ копит подключения сокетные и птом по этим по...

У меня подключение сокетное одно, других не будет. Максимум ещё одно-два. А вот емитить события я бы хотел с других мест

Похожие вопросы

Обсуждают сегодня

A couple thoughts from a random internet stranger: 1. If you want this project to gain traction you cannot keep being negative. If I just came here after finding out about Kd...
Eric Wild
22
Bhai mera Wazirx Account locked kr diya hei inhone to use unlock kese kru ?? Kisi ke ye problem aayi aur solve ho gayi hei to batao ?
Govind Jarwal
33
Hello guys I was wondering whether if it is OK to download the monero block chain without using tor?? Does that effect the privacy of the wallet I want to connect the monero b...
Jackisow
13
Hello, I am Ashamer from UNCX, a DeFi service provider. I am contacting you to ask if there is any room for a potential collaboration. Is there anyone whom I can potentially t...
Ashamer
19
I know it seems like "fud" but its just common sense imho. Blockchains in their fundamental nature distribute the value creation function to the community but in Kadena its...
Bright Uncle Stephen EqualBet
13
Hi @Ben_WG , any ETA for copy traiding or the Launch pad? I thought this was for April?
Tony
13
Hello Marines :) I'm a FTM holder but I'm looking to invest in AI projects build on FTM can anyone suggest me a site where I can see projects like these in FTM network ?
Cryptoogle
8
Is Kadena onto something special? No one really knows. Good luck!
Bright Uncle Stephen EqualBet
40
Win two FREE dappcon_berlin Conference General Access tickets🌟 And Get a chance to meet us & other talented #Web3 Devs in Berlin between May 21-23😄 You just need to - ❤️&RT...
Stip11
2
Hypothetically if it was da Chicago bulls that fell through. What would a partnership look like? Would it be branding on the arena or would they be using Kda in someway.
Eric Wild
7
Карта сайта