Photon Voice Stuck in Disconnecting State after Pause

Hey,

We are using PhotonVoice on Oculus Quest (android) for a VR game, Unity Version 2018.4.11 and Photon Voice v2.9 / PUN2: v2.14 .

The audio works smoothly when starting the app and we can hear other clients. However, after pausing the app and unpausing the app, the Photon Voice Networking state gets stuck in "Disconnecting" and no audio can be heard.

We have found a temporary solution is to check if the voice state is "Disconnecting" after Photon Network has successfully joined a room, force set the state to "Disconnected", and try to reconnect manually.
if (PhotonNetwork.InRoom && PhotonVoiceNetwork.Instance.ClientState == ClientState.Disconnecting) {
     PhotonVoiceNetwork.Instance.ClientState = ClientState.Disconnected;
     PhotonVoiceNetwork.Instance.ConnectAndJoinRoom();
}
This solution works, but we are concerned that force setting a state may cause other issues. Is there another way to handle this situation?

Comments

  • JohnTubeJohnTube mod
    edited October 2019
    Hi @snayss,

    Thank you for choosing Photon!

    PUN2 and Voice clients should have the same connection flow and network state.
    If Voice is disconnecting what about PUN2? maybe it's disconnecting also?

    By pausing you mean you send the application to the background on Android by clicking the back or home buttons?
    How long do you keep the application in the background?

    You could control how long the background ack-only thread keeps the connection alive:
    PhotonNetwork.KeepAliveInBackground: for the PUN2 client
    PhotonVoiceNetwork.Instance.KeepAliveInBackground: for the Photon Voice 2 client.

    When the client state is Disconnecting could you log the value of PhotonVoiceNetwork.Instance.Client.LoadBalancingPeer.PeerState.
    Could you also log PUN2's client state: PhotonNetwork.NetworkClientState.
  • Hi @JohnTube ,

    Thanks for your response, by pausing we just mean removing the Quest headset and waiting for a minute or so until it falls asleep.

    We are also noticing an issue where when disconnecting the PhotonNetwork from the current room, the PhotonVoiceNetwork stays in the Joined state. Then when we try to connect PhotonNetwork to a different room, PhotonNetwork succesfully joins and PhotonVoiceNetwork is still in the Joined state, however the native android error E AudioRecord-JNI: Error -38 during AudioRecord native read starts to spam, audio starts cutting and the app crashes.

    It seems like some state is not being cleared properly, or initialized twice, when switching between rooms. Do you know what could be causing this issue? Is there an action we are missing when switching rooms?

    Thanks for your help

  • Hi @snayss,

    Are you still on Photon Voice 2.9? if so, please update to latest.

    We are also noticing an issue where when disconnecting the PhotonNetwork from the current room, the PhotonVoiceNetwork stays in the Joined state.
    Did you set PhotonVoiceNetwork.AutoLeaveAndDisconnect to true?

    however the native android error E AudioRecord-JNI: Error -38 during AudioRecord native read starts to spam, audio starts cutting and the app crashes.
    What Recorder Microphone Type are you using? Unity or Photon?
  • snaysssnayss
    edited December 2019

    Yes seems like we are not on the latest Photon Voice . If we update to Photon Voice 2.12, is it mandatory to update Photon Network from 2.14 to the latest (2.16)?

    We have set PhotonVoiceNetwork.AutoLeaveAndDisconnect to true, and are using the Photon Recorder Microphone Type.

  • If we update to Photon Voice 2.12, is it mandatory to update Photon Network from 2.14 to the latest (2.16)?

    Yes that is the default recommended way.

    However, if you cannot update PUN for some reason, you could skip all files except "Photon/PhotonVoice". But it's still risky and I would recommend updating all.

    We have set PhotonVoiceNetwork.AutoLeaveAndDisconnect to true, and are using the Photon Recorder Microphone Type.

    OK. Thanks for the info.

    I will try to reproduce.

  • JohnTubeJohnTube mod
    edited December 2019
    Hi @snayss,

    There are three issues here:

    1. Photon Voice Networking state gets stuck in "Disconnecting"
    2. when disconnecting the PhotonNetwork from the current room, the PhotonVoiceNetwork stays in the Joined state.
    3. E AudioRecord-JNI: Error -38 during AudioRecord native read

    I have investigated this and tried to reproduce the first two.
    I think there has been a bug which prevented proper handling of automatic rooms switching.
    Could you try this PhotonVoiceNetwork version?

    Other than that, I could not reproduce 1 and I think 2 could be explained if PhotonVoiceNetwork.AutoConnectAndJoin if false and you called PhotonVoiceNetwork.Instance.ConnectAndJoinRoom() initially.
    3 maybe related to this also.

    That's why I need to make some clarifications about how PhotonVoiceNetwork and the PUN integration works currently:

    A. If you manually and explicitly call PhotonVoiceNetwork.Instance.ConnectAndJoinRoom() then
    PhotonVoiceNetwork.AutoLeaveAndDisconnect will be skipped when PUN client disconnects and the Voice client could remain connected / joined to a voice room.

    B. If you manually and explicitly call PhotonVoiceNetwork.Instance.Disconnect() or
    PhotonVoiceNetwork.Instance.Client.Disconnect() then PhotonVoiceNetwork.AutoConnectAndJoin
    will be skipped and Voice client could remain disconnected even if PUN client connects or joins a room.

    C. If you switch PUN rooms while still in the same Voice room, the Voice client will not try to switch Voice rooms unless PhotonVoiceNetwork.AutoConnectAndJoin is true. (No matter if B was used or not)

    A and B invert each other.
    Meaning if you make a successful explicitly disconnect call after an explicit connect call, AutoLeaveAndDisconnect will not longer be ignored/skipped. And vice versa.

    The idea behind this is that sometimes you want to choose a different behaviour and interfere with how things work.

    This behaviour also introduces extra complexity and maybe new issues.

    For instance once you call PhotonVoiceNetwork.Instance.ConnectAndJoinRoom() or PhotonVoiceNetwork.Instance.Disconnect()/PhotonVoiceNetwork.Instance.Client.Disconnect() either PhotonVoiceNetwork.AutoConnectAndJoin or PhotonVoiceNetwork.AutoLeaveAndDisconnectwill be ignored silently which could be confusing.

    So we will review all these and may refactor and improve the situation in the near future.
  • Hi @snayss,

    I just submitted version 2.13 to the Unity Asset Store.

    It would help if you could test it and see if you still have any issues.

    Thanks for your patience, your help and understanding.
Sign In or Register to comment.