Photon playcanvas connection error

hello, i use photon inside playcanvas game engine.

and maybe 1 time of 3 i have this error.

can’t get any good info about it.

do you know what can it be about?

thank you

@DevilZ do you any idea?

1 Like

I’ve never encountered this error. What version of the SDK are you using? Perhaps you can try a different version?

1 Like

i use last one, 4.1.1.2

may i ask you another question:
how will you connect all users to one room?

i mean, if room does not exist, you have to create it, and if it does - just join.
i found a problem if multiple users try to create room at the same time.
how would you solve this issue?

I don’t know how Photon solves that, @DevilZ may know more.

But when using a different multiplayer engine that didn’t really provide a system for unique rooms, I ended up with the same problem: multiple rooms spawned when users created them at the same moment.

What I did is run a server query per user that listed all rooms with the same label, and if more than one where found, I would disconnect the user from the current room and connect him to the first room in the list.

The rooms list was ordered the same for all users so very soon all users will end up in the same room.

2 Likes

nice idea, thank you
not sure it’s the best practices, but maybe we can try…

Yeah, it’s a trick for a missing system. Normally if a user requests a room with a label that already exists, the server should connect him to an existing one.

Hope photon solves this in a better way.

1 Like

Hey @Dima_Romanchuk,

In addition to @Leonidas’s excellent answer, you would want to study the file demoloadbalancing.js. Here, you’ll see that there are two important buttons - join game and new game. We can use a combination of these two to achieve what you need.

This is a function I wrote that does exactly what you need -

function checkTheRooms() {
    if ($("#statetxt") !== "Error") {
        var getRooms = ($('#gamelist').find(":selected").text());
        if (getRooms === "") {
            $("#newgamebtn").click();
        }
        else {
            $("#joingamebtn").click();
        }
    }
    else {
        //user limit reached
    }
}

Please note my method uses jQuery.

You can then set up a button called “Join” in your custom UI that calls this function.

1 Like

thank you for reply

but there are some details:

  1. i want to join all users to one room, so i do not need room list
  2. as we have only 1 room, we don’t need to choise it, so i do not use that ui like ‘join’ button

now i use stuff like this in demoloadbalancing.js:


        let connectInterval = setInterval(() => {
            if(!this.isJoinedToRoom()) {        
                if(this.availableRooms().length > 0) {
                    this.joinRoom('tahuTest');
                } else this.createRoom('tahuTest');
            } else clearInterval(connectInterval);
        }, 7000);

it’s not good coding, but it minimized error appearing

I understand that. You can hide the photon UI using something like $("photon_container).hide(). Don’t remove the DOM element itself though, you will need that. My idea was to add a custom HTML button that is not in the Photon container that says “Join the room” and calls the function I had sent you. That way, you’re doing it the way Photon wanted you to without having to resort to setTimeout.