How to check room is already exist or not?

Is there any way to check given room name already exit or not before connecting to server. Let's assume that 2 players playing a game with room name "ABC123" at the same time other two players are also trying to connect the room with same name.

Comments

  • Hi @LudoKing,

    it is not possible to have two (or more) rooms with the same name. The second client who tries to create a room with a name that is already known to the server will receive an error message. In order to avoid this situation you maybe want to use PhotonNetwork.JoinOrCreateRoom(...) function which joins the room with the given name or creates it firstly if it doesn't exist and joins it afterwards.
  • JoinOrCreateRoom would save me a lot of hassle, is there a version of it for the Javascript Loadbalance?
  • vadim
    vadim mod
    edited March 2020
    Hi,

    'joinRoom' method has 'createIfNotExists' option and options to use during room creation.
    The call looks like this: client.joinRoom("room-name", {createIfNotExists: true}, createRoomOptions),
    where 'createRoomOptions' is the same object which you optionally pass to createRoom().

    See https://doc-api.photonengine.com/en/javascript/current/Photon.LoadBalancing.LoadBalancingClient.html#joinRoom