admin管理员组

文章数量:1366075

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);
  }

本文标签: typescriptHow to add different namespace clients to the same roomStack Overflow