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

I created two socket.io namespaces because there is an agent and customer in chat application and their

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

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1743774166a4504915.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信