Two Players at same time create two rooms, JoinRandomOrCreateRoom not found in SDK

Hi,

I'm using (Real-time) Photon-Javascript_SDK.js (libversion=4.1.0.0) for COnstruct 2.

Sometimes, when two players try to join a game, it could happen that each will create its own room (instead of joining one room)

To solve this issue as mentioned in the below link:


I need to use JoinRandomOrCreateRoom, but no such function in the whole SDK. Can anyone help, please?

Answers

  • Hi,

    Please call joinRoom() with 'createIfNotExists' option: https://doc-api.photonengine.com/en/javascript/current/Photon.LoadBalancing.LoadBalancingClient.html#joinRoom

    You can find an example of such call in demo-loadbalancing.

  • Hi,

    Thanks for your reply.

    I tested demo-loadbalancing. But, I need to know the room name (and specified) in the function, which I don't know.

    this.joinRoom('rooName', { createIfNotExists: true }, {maxPlayers : 2}); // the issue will not showing here

    What I need is to allow (for example) two players to join a game (a room, any room) if not found will create one (with any name), but they both should join the same room. My observation is that sometimes (let say 1 out of 4), the two players if joining at the same time, could be created two different rooms (both waiting).

    What I am doing:

    1] join a random room

    2] If no match is found, create a room (with no name, Photon will create a random name)

    // the issue is happening here

    What do you think?

  • joinRoom() won't help in you case. I misread your question, sorry.

    JoinRandomOrCreateRoom is not supported in js sdk. You need to do this in 2 steps, exactly as you described. demo-particle implements such workflow, search for NoRandomMatchFound in app.js

  • Thanks Vadim.

    It seems it is a well-known issue. The document is outdated, you see:

    "Testing Matchmaking Early In Development

    If you are testing matchmaking early in development phase and try to join a random room from two clients at about the same time, there is a chance both clients end up on different rooms: this happens because join random room will not return a match for both clients and each one will probably create a new room as none found. So this is expected and OK. To avoid this use JoinRandomOrCreateRoom (see Quick Match) instead of JoinRandomRoom then CreateRoom. Otherwise, a possible workaround (for development purposes only) would be to add a random delay before (or after) attempting to join a room or retry again. You could also listen for application or lobby statistics to make sure a room at least exists or has been created."

    It says "So this is expected and OK", for me it is not expected and it should not be ok. Then it mentioned the solution by using "JoinRandomOrCreateRoom" which is not in the SDK anymore.

    I ended up doing the workaround as follows:

    1] Join a random room

    2] If not found, create one

    3] Wait for a random delay, if no user joined, then restart the process (from (1))

    Note: I found at https://forum.photonengine.com/discussion/comment/56359#Comment_56359, they confirmed the issue, and provided the implementation in PUN, is there any equivalent implementation in JS?

  • We will look into adding JoinOrCreateRoom as function to JS. It won't happen during the holidays, so .. early next year. We'll try to update this thread when it's out.

  • @Tobias Thanks for the update, appreciate your time and efforts.

  • Hi,

    We added joinRandomOrCreateRoom() in SDK v4.1.1.2 

  • Thank you very much for the update.👍️

  • Hi,

    I did update SDK (using joinRandomOrCreateRoom) but still the issue happened , in which it is still possible that two players might ended up with spreate rooms (both waiting).

    I checked the implementation:

    1] Join a rondom room (with CreateIfNotExists = 1)

    2] If not found create one.

    Which what I was doing before. Am I missing something, or this the best result that I can get?

  • Hi,

    Updating the SDK is not enough. You also need to change your code to use new joinRandomOrCreateRoom() method.

  • Hi,

    I did, of course. I noticed better results, but it is still happing.

    I am almost convinced, it is technically impossible to avoid this issue, it is just the Documentation confused me by saying you can avoid it. Do you believe it should not happen 100% by using 'joinRandomOrCreateRoom'?

    Can you try to reproduce the issue from your end, for example, try with a colleague to join a room at the same time multiple times (leave the room without a name to be generated randomaly)

  • JoinRandomOrCreateRoom() should work in 100% of the cases. But there are a few caveats: You can't use the same userID for both clients (so if you store it in the PlayerPrefs, this is tricky), users must be on the same region and game version string (and then a few more).

    To recap: You are using the latest JS SDK and you checked the Matchmaking Checklist to avoid known causes for this?