Placeholder-Software / Dissonance

Unity Voice Chat Asset
71 stars 5 forks source link

How does Dissonance actually sends data over Photon Pun? #237

Closed friuns2 closed 3 years ago

friuns2 commented 3 years ago

Hi again ;)

I started debugging how PhotonCommsNetwork sends data

When client speaks does it sends data first to MasterClient, and then master client sends data to other clients? This means data goes twice through server doubling traffic.

Is there way to switch mode to peer to peer to avoid this?

Dissonance 7.1.0

martindevans commented 3 years ago

Dissonance networking has a couple of modes of operation:

In PUN, the "p2p" connections should be established for every client to every other client and it should never fail (because it's still sent via the PUN network system, which guarantees it'll work). Look for PhotonClient.OnServerAssignedSessionId being called, which is where clients send a greeting to other clients. You can see P2P packets being sent in PhotonClient.SendP2P which sends directly too clients which is can, and then relays the rest via the server.

tl;dr: Voice packets are only sent through the server during initial session setup.

friuns2 commented 3 years ago

Thanks for quick reply. yes now i see there SendP2P function but i still see this in logs. I see p2p packet 100bytes is send to MasterClient and to others, on PUN it means it sends same packet twice to server image

here p2p packets relayed through server image

is it possible disable this relay functionality? i don't see any advantage using it in PUN

friuns2 commented 3 years ago

Also i think you have typo in Pun1 integration you calling base.Reliable from Unreliable function
(not sure if you support Pun1 anymore, i couldn't find it in Dissonance 8.1)  

I commented out those base implementation and everything still works, with no relay sended. not sure if it breaks anything :)

martindevans commented 3 years ago

Just to double check before I debug this any more - are you using PUN1 or PUN2? We deprecated the PUN1 integration a while ago.

friuns2 commented 3 years ago

PUN1 and Dissonance 7.1 I can't update to 8.1 because there no pun1 support anymore.

martindevans commented 3 years ago

Aha, that explains some of why I was confused looking through the code for the PUN2 integration! I suggest upgrading your version of Dissonance to 8.0.1 - it should be compatible with the old PUN1 package right away, the breaking change with version 8.0.0 was a very small change in the microphone interface. As for PUN1, I suggest downloading the PUN2 integration as well and comparing the code for differences. The PUN2 integration is based off the PUN1 integration (with some fixes).

I commented out those base implementation and everything still works, with no relay sended. not sure if it breaks anything :)

If you look at the implement of SendP2P it should send the packet directly to everyone it knows how to contact and them remove them from the destinations list. The base method is then called with this list, and relays it via the server to whoever could be not contacted through p2p. Check what items are being left in the list, there may be some reason why it's never being relayed.

martindevans commented 3 years ago

It's been a while so I'll close this discussion, feel free to re-open it if you have more questions :)