PhotonNetwork.networkingPeer.PeerState showing incorrect state
Options
Kiraaa23
✭
Hi guys,
I am trying to disconnect the player when app goes into to background and again trying to rejoin the player when he/she is back to Focus..I am trying to do this by checking PhotonNetwork.networkingPeer.PeerState, The problem is that even when is disconnected, in the PhotonNetwork.networkingPeer.PeerState it is showing as connected. Hence i am unable to call rejoin.
Please help me..Thanks in Advance
Here is my code to reconnect
I am trying to disconnect the player when app goes into to background and again trying to rejoin the player when he/she is back to Focus..I am trying to do this by checking PhotonNetwork.networkingPeer.PeerState, The problem is that even when is disconnected, in the PhotonNetwork.networkingPeer.PeerState it is showing as connected. Hence i am unable to call rejoin.
Please help me..Thanks in Advance
Here is my code to reconnect
using Photon; using PlayFab; using PlayFab.ClientModels; using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.Networking; public class ReconnectController : PunBehaviour,IPunCallbacks { private void OnApplicationFocus(bool Focus) { if (Focus) { Debug.Log("App in Focus"); } else { StartCoroutine(DisconnectPlayer()); } } private void Update() { Debug.Log(PhotonNetwork.networkingPeer.PeerState); if (PhotonNetwork.networkingPeer.PeerState == ExitGames.Client.Photon.PeerStateValue.Disconnected) { if (!PhotonNetwork.ReconnectAndRejoin()) { Debug.Log("Failed reconnecting and joining!!", this); } else { Debug.Log("Successful reconnected and joined!", this); } } } public override void OnDisconnectedFromPhoton() { Debug.Log("Disconnectingg "); } public override void OnFailedToConnectToPhoton(DisconnectCause cause) { Debug.LogWarningFormat(this, "OnFailedToConnectToPhoton, cause {0}", cause); MyEventManager.Instance.ShowMessage.Dispatch(cause.ToString(),false); PhotonNetwork.Reconnect(); } public override void OnConnectionFail(DisconnectCause cause) { Debug.LogWarningFormat(this, "OnConnectionFail, cause {0}", cause); MyEventManager.Instance.ShowMessage.Dispatch(cause.ToString(), false); } IEnumerator DisconnectPlayer() { Debug.Log("Application not in Focus"); PhotonNetwork.Disconnect(); Debug.Log(PhotonNetwork.networkingPeer.PeerState);///Showing as disconnected in the log while (PhotonNetwork.networkingPeer.PeerState == ExitGames.Client.Photon.PeerStateValue.Connected) { Debug.Log(PhotonNetwork.networkingPeer.PeerState); yield return null; } } }
0