Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | 11x 11x 11x 11x 11x 11x 11x 11x | import { Logger } from '@nestjs/common';
import { WebSocketGateway, WebSocketServer, OnGatewayConnection, OnGatewayDisconnect, SubscribeMessage, MessageBody } from '@nestjs/websockets';
import { Server, Socket } from 'socket.io';
@WebSocketGateway({ namespace: '/quick-rent', cors: { origin: process.env.FRONTEND_URL, credentials: true } })
export class QuickRentGateway implements OnGatewayConnection, OnGatewayDisconnect {
@WebSocketServer()
server!: Server;
private readonly logger = new Logger(QuickRentGateway.name);
handleConnection(client: Socket) {
this.logger.debug(`Client connected: ${client.id}`);
}
handleDisconnect(client: Socket) {
this.logger.debug(`Client disconnected: ${client.id}`);
}
@SubscribeMessage('join')
onJoin(client: Socket, room: string) {
client.join(room);
client.emit('joined', room);
}
@SubscribeMessage('leave')
onLeave(client: Socket, room: string) {
client.leave(room);
client.emit('left', room);
}
@SubscribeMessage('ping')
onPing(client: Socket, @MessageBody() data: any) {
client.emit('pong', data);
}
emitNewBid(requestId: number, payload: any) {
this.server.to(`auction-${requestId}`).emit('new_bid', payload);
}
emitStatus(requestId: number, payload: any) {
this.server.to(`auction-${requestId}`).emit('status', payload);
}
}
|