The Photon Forum
is Closed Permanently.

After many dedicated years of service, we have made the decision to retire our Forum and switch to read-only: we´ve saved the best to last! Your search result can be found below. Plus, we offer support via these channels:

Try Our
Documentation

Please check if you can find an answer in our extensive documentation on PUN.

Join Us
on Discord

Meet and talk to our staff and the entire Photon-Community via Discord.

Read More on
Stack Overflow

Find more information on Stack Overflow (for Circle members only).

Write Us
an E-Mail

Feel free to send your question directly to our developers.

How to disconnect and reconnect/rejoin in room

Gagan
2022-10-28 09:43:09

As a requirement, when the app goes in the background makes the user exit from the room and if the app comes in the foreground makes the user rejoin the room.

////For leave/////

OnApplicationPause()

////// For rejoin ////

OnApplicationFocus()

When the app comes in the foreground the user is not rejoining.

been trying this quite a long time, @photon any help will be appreciated.

Comments

DarkLouis
2022-10-30 18:20:22

Try to store the name of the room when you join (like in "previousRoom").

And when your application comes in the foreground you just do :

So it will be that :

////When you join/////

string roomToJoin = "abc"

PhotonNetwork.JoinRoom(roomToJoin );

////For leave/////

OnApplicationPause()

PhotonNetwork.LeaveRoom();

PhotonNetwork.Disconnect();

////// For rejoin ////

OnApplicationFocus()

PhotonNetwork.ConnectUsingSettings("0.5");

PhotonNetwork.JoinRoom(roomToJoin );

I wish it gonna be helpfull for you ;)

Gagan
2022-10-31 07:17:40

DarkLouis 2022-10-30T18:20:22+00:00

Try to store the name of the room when you join (like in "previousRoom").

And when your application comes in the foreground you just do :

PhotonNetwork.JoinRoom(previousRoom)  

So it will be that :

////When you join/////

string roomToJoin = "abc"

PhotonNetwork.JoinRoom(roomToJoin );

////For leave/////

OnApplicationPause()

PhotonNetwork.LeaveRoom();

PhotonNetwork.Disconnect();

////// For rejoin ////

OnApplicationFocus()

PhotonNetwork.ConnectUsingSettings("0.5");

PhotonNetwork.JoinRoom(roomToJoin );

I wish it gonna be helpfull for you ;)

this.previousRoom is having previous room value like this

this.previousRoom = PlayerPrefs.GetString(previousRoomPlayerPrefKey);

and getting error

ReJoinRoom failed. Client is not on Master Server or not yet ready to call operations. Wait for callback: OnJoinedLobby or OnConnectedToMaster.

DarkLouis
2022-10-31 16:32:07

Oh I think I know.

When you use Photon.Disconnect(), you disconnect from the master too.

So you need to reconnect the player to the master.

Back to top