π¬Conversations
@WebSocketGateway({
cors: {origin: '*'}
})
export class ConversationsGateway implements OnGatewayConnection {
constructor(
private messageService: MessageService,
private conversationsService: ConversationsService,
) {}
@WebSocketServer()
server: Server;
async handleConnection(socket: Socket){
const conversationRoom = socket.handshake.query.room
const jwt = socket.handshake.headers.authorization.split(' ')[1]
socket.join(conversationRoom)
const socketPresenceValidity = await this.conversationsService.checkIfUserBelongsToConversationRoom(jwt, conversationRoom.toString())
if(socketPresenceValidity === false) {
socket.emit('error', "Unauthorized access: Authorization header token is expired, or client is not authorized to read room conversations.")
socket.disconnect(true)
}
else {
const messages = await this.messageService.loadConversationRoomMessages(conversationRoom.toString())
socket.emit('message', messages)
console.log(`Socket client ${socket.id} joined ${conversationRoom} room. Messages loaded`)
}
}


Last updated