最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

typescript - How to add different namespace clients to the same room? - Stack Overflow

matteradmin3PV0评论

I created two socket.io namespaces because there is an agent and customer in chat application and their handleConnection, handleDisconnect functions and etc. are different. That is why I separated them instead of writing if-else blocks to differentiate who connects. So now the issue occurs: I can not add them to the same room, because room is bounded to the namespace which is created in. Is there any way to do so? Or separating them is not even correct? I tried to implement this and this to test, but they did not work either even there is of function in Server class.

TypeError: this.server.of is not a function at CustomerGateway.handleConnection 
@WebSocketGateway({ cors: { origin: '*' }, namespace: '/customer' })
export class CustomerGateway implements OnGatewayConnection, OnGatewayDisconnect {
  constructor(private readonly chatService: ChatService) {}

  @WebSocketServer() server: Server;

  async handleConnection(client: Socket) {
    console.log(`Connected customer: ${client.id}`);
    console.log(this.server.of('/customer'));
    const key = '';
    const room = `room:${key}`;
    client.join(room);
  }
Post a comment

comment list (0)

  1. No comments so far