GitHub | Documentation | Become a Patron

requestJoin called twice



  • Hi,

    I was testing the example 04-create-or-join-room from colyseus-examples. I added some console.logs around and I noticed that requestJoin is not behaving as I would expect.

    Always referring to that example, if I ask to create one room from client client.join('create_or_join', { create: true }), I see one requestJoin, with option.create and isNewRoom both set to true. So far so good. Then using another client (or browser tab, the outcome is the same in both cases), I ask to join client.join('create_or_join'). I see that requestJoin is called twice for the same roomId (I assume that means the same CreateOrJoinRoom instance), both times with option.create set to undefined, as expected, and with isNewRoom set to false. Then I see one onJoin event associated to that roomId. colyseus/monitor lists one room with two clients connected.

    The question is: why is requestJoin called twice? The first (and only one) instance is never being locked and maxClient is set to 4. Funny thing, both requestJoins return true.

    I'm not sure I fully understood rooms and their interactions with clients, but I really want to make sure this is not a colyseus issue that might influence other parts of the code.


  • administrators

    Hi @orangenote,

    I've recorded a video using the example you mentioned and it seems to be working as expected:

    https://www.youtube.com/watch?v=BwMkGGv1z5o

    One caveat, though, is when you're testing using multiple tabs, you'd need to wait for the join room request to complete before requesting another one (you can see I'm waiting for the logs to appear during the video). This is a current limitation when reserving room seats for clients with the same id (see GitHub issue)



  • Thanks for the quick response and for the heads up about the join issue.

    But unfortunately that didn't answer my question. I'll explain my situation more clearly.

    I have added one console.log line to CreateOrJoinRoom.requestJoin method:

    requestJoin (options, isNewRoom: boolean) {
      console.log(`roomId: ${this.roomId}, create: ${options.create}, isNewRoom: ${isNewRoom}`);
      return (options.create)
        ? (options.create && isNewRoom)
        : this.clients.length > 0;
    }
    

    Then went to http://localhost:2567/04-create-or-join-room.html and pressed Create once, then Join once.

    This is what I got in the server console:

    Listening on http://localhost:2567
    JOINING ROOM
    roomId: BJl3OCrCWX, create: true, isNewRoom: true
    CREATING NEW ROOM
    roomId: BJl3OCrCWX, create: undefined, isNewRoom: false --
    roomId: BJl3OCrCWX, create: undefined, isNewRoom: false -- why is requestJoin called twice?
    CREATING NEW ROOM