broke down ws
This commit is contained in:
19
src/ws/state/utils/broadcasting.ts
Normal file
19
src/ws/state/utils/broadcasting.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
import { UserSocketService } from '../user-socket.service';
|
||||
import { WsNotificationService } from '../ws-notification.service';
|
||||
|
||||
export class Broadcaster {
|
||||
constructor(
|
||||
private readonly userSocketService: UserSocketService,
|
||||
private readonly wsNotificationService: WsNotificationService,
|
||||
) {}
|
||||
|
||||
async broadcastToFriends(friends: Set<string>, event: string, payload: any) {
|
||||
const friendIds = Array.from(friends);
|
||||
const friendSockets =
|
||||
await this.userSocketService.getFriendsSockets(friendIds);
|
||||
|
||||
for (const { socketId } of friendSockets) {
|
||||
this.wsNotificationService.emitToSocket(socketId, event, payload);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user