PhotonVoice disconnection while paused

I am using PhotonVoice with the standard PhotonVoiceSettings. I instantiate an voice speaker object and its working fine (on Android).

I also have some replication going on directly with PUN.

When the app goes into background and then unpauses voice and networking continue to work.

If I pause the app for a little over 10 seconds and then return, the voice stops working but the other networking continues.

I turned on logging and I can see these messages when the voice stops:

PUNVoice: [PV] Player 2 voices removed on leave
PUNVoice: Player 2 voice #1 speaker unlinked

Then later when shutdown the app I get:

PUNVoice: Voice Client state: Disconnecting
PUNVoice: Voice Client state: Disconnected
PUNVoice: Voice Client state: Disconnected
OnStatusChanged: Disconnect
OnLeftRoom
...

Why is PUNVoice disconnecting earlier than PUN itself?
Can I change it to the same timesouts?
How can I detect that PUNVoice has disconnected and ask it to reconnect?

In my PhotonVoiceSettings I have AutoConnect, AutoDisconnect, AutoTransmit all set to true, so I'm not directly managing the voice connection.

Thanks

Jules

Comments

  • vadimvadim ✭✭✭
    Keeping connection while running in background is not supported by PhotonVoice yet.

    Simplest way to handle PhotonVoice disconnection is adding your code in UnityVoiceClient.OnStateChange method in PhotonVoiceNetwork.cs.

    It also should be possible to do so without Photon code change, by overriding PhotonVoiceNetwork.Client.OnStateChangeAction with your handler which in turn calls previous handler saved somewhere.

    We added keeping connection in background and more convenient state change handling in todo list.
  • Thanks
  • Just tried this, and it turns out that the PhotonVoiceNetwork.Client.OnStateChangeAction is not being called when Photon Voice unlinks the voice speaker due to going into background for 10 seconds, so this doesn't provide a way to detect the unlinking.

    We do get a LoadBalancing.EventCode.Leave event which calls the private function onPlayerLeave.

    I think the 10 seconds is the time before the application is actually being suspended, PUN keeps around for a while longer but PhotonVoice immediately removes the player and unlinks the audio.

    What I need is when my app unpauses it can detect that the voice has become unlinked and then a way to trigger a reconnect.

    How can I detect that the voice has been unlinked, can be relinked and then how relink?

    Thanks
  • vadimvadim ✭✭✭
    You need to detect that client got disconnected from server. Then join room again and voice will be inked automatically.
  • How do I do that?

    PUN is not being disconnected from the server, so I don't get any Photon events, such as Disconnected. Only the voice element is being punted and then not reconnecting.

    Sequence we have is:

    Client 1 connects to server, joins lobby, leaves lobby, creates room, instantiates voice object
    Client 2 connects to server, joins lobby, leaves lobby, joins room, instantiates voice object
    Client 1 gets copy of client 2 voice object, with linked audio clip
    Client 2 gets copy of client 1 voice object, with linked audio clip
    Client 2 pauses
    Internally Client 1 voice code unlinks voice (removes audio clip from audio source)
    Client 2 unpauses
    At this point both clients are in room, network communications via PUN are fine
    Voice is unlinked

    So, I can't check for disconnect event as it doesn't happen, I can't rejoin room as I never left.

    If I could detect that this has happened I could probably disconnect client 2 and then reconnect, but I can't see a way to detect that it has happened.

    I can poll the AudioSource and once it's clip has been not-null I know we've had an connection, then poll for it disappearing, and then if I've just been unpaused I could reconnect, but I'd need an API function to trigger the relink and I'm not sure the approach would b entirely reliable.

    The only safe solution I can think of is to always disconnect PUN if my app is paused, even for only a moment, and then reconnect on unpause, but it wouldn't be the best user experience.

    Suggestions please?

    Thanks

    Jules
  • I've worked around this by forcing a PUN disconnect on application pause and then a reconnect on unpause.
  • vadimvadim ✭✭✭
    I meant voice room client. It can connect/disconnect manually while PUN client is joined to a room.
    Good to know that you found working solution. A I wrote, we will fix keeping connection in background later.
Sign In or Register to comment.