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.

Hi @orangenote,

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

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

Hi @endel
In the video, you explain about create and join rooms.
Can I get your source code about create and join rooms in the video? Because 04-create-or-join-room.html file is no longer available on your github (colyseus-examples).

I want to create a new room, but I'm a little confused by the workings of the create room, whether the room name or id can be changed according to the user input or not.

0_1587461601204_createroom.PNG
For example, if a user enters "myroom" in the input text, then a new room with the name "myroom" will automatically be created in the server.
And if user B is entered "myroom" in the input text, then the user B will automatically join the existing room.

Sorry for my bad English. Thank you.

Hi @defort, welcome! I think you're probably looking for this: https://discuss.colyseus.io/topic/345/is-it-possible-to-run-joinorcreatebyid

There no such thing as creating an identifier for a room by the client, what you can play with are the filters of the defined rooms.

Cool. It really works!
0_1587533899042_colyseuscreateroom.PNG
Thanks for your help @endel