Problem with second client joining voice room
The whole answer can be found below.
Try Our
Documentation
Please check if you can find an answer in our extensive documentation on Voice.
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).
Problem with second client joining voice room
VPadu
2020-06-30 14:27:54
Good day everyone!
I am writing this post because I have a problem with Photon Voice.
My program has two clients joining a room successfully. They also share their webcam so the connection works perfectly.
The problem is that the voice does not: the first client that joins the room correctly joins the voice room as well. The second client who joins can hear the first one, but cannot send its voice through the network; i.e. the first client does not here the second one.
I tried setting the LOG LEVEL to ALL and the image shows what is logged in the console.
[
](https://ibb.co/M6tM0kq)
This is a loop that goes on forever on the client that joined the room last.
Could you perhaps help me? It would be much appreciated.
Kind regards
Comments
More info:
The photon voice is set as mentioned in the suggested workflow page so I have a PhotonVoice prefab with PhotonVoiceNetwork, Recorder, PhotonVoiceView and PhotonView components and a speaker prefab
Hi @VPadu,
Thank you for choosing Photon!
Did you try enabling SupportLogger?
Maybe the second client fails to join the room somehow.
@JohnTube thanks for your answer.
Did not know about the supportlogger feature. I enabled it and I get in fact an error telling me that the user cannot join the specified game.
[
](https://ibb.co/v1KhKqj)
Do you have any idea why this happens? Do my two clients have the same ID?
Hi @VPadu,
Not sure how this happened but it looks like both clients use the same UserId.
How can we reproduce this?
I have a PhotonVoice prefab with PhotonVoiceNetwork
do not add PhotonVoiceNetwork to a prefab. I don't think we tell you to do this in the documentation. You need one instance of PhotonVoiceNetwork.
Dear @JohnTube
I now have a game object called PhotonVoiceTest which has the components PhotonVoiceNetwork, Recorder, PhotonView and PhotonVoiceView (instead of a prefab)
And it looks like this:
[
](https://imgbb.com/)
In this case, the documentation says "Optionally add a PhotonVoiceNetwork to the scene." and now I am not sure if this is the correct way to do it.
I do not have multiple instances of PhotonVoiceNetwork on one client, however each client has its own instance of PhotonVoiceNetwork.
The problem remains: the second client cannot join somehow
Sorry to bother you (maybe it is a very simple thing that I don't understand) but I don't have a lot of experience with unity.
Hi @VPadu,
Does this issue happen with the demos?
How do you connect to PUN/Voice?
Do you use custom authentication?
Do you connect to Photon Cloud or self-hosted Photon Server?
Which Photon Voice version is this? if not latest please update.
Dear @JohnTube
To answer your questions:
No, the issue does not happen with the demos (the demo I tried is the one with the zombie peluches)
I do not use custom authentication
I use Photon Cloud (I do not have my own server where photon is hosted)
I followed this tutorial to set up the connection.
That means that if no room are found, the client creates a new one and if one is found they connect to it.
The code looks like this
[
](https://ibb.co/FD85Hgb)
The Photon Voice version is 2.17 which I think is the most recent one
Hi @VPadu,
Not sure how you ran into this but if it's random it should not persist.
If client disconnects unexpectedly sometimes the server may keep its peer connection alive and relative actor active in the room for 10 seconds before it times out.
if the issue persists and it's 100% reproducible send me a repro project via email to [email protected].
Hey @VPadu,
I think that maybe you have multiple PhotonVoiceNetwork instances in your project.
Try changing PhotonVoiceNetwork's instance property code ("Assets\Photon\PhotonVoice\Code\PUN\PhotonVoiceNetwork.cs") with this and see if it helps.
The new code logs errors instead of warnings and auto destroy extra instances.
public static PhotonVoiceNetwork Instance
{
get
{
lock (instanceLock)
{
if (AppQuits)
{
if (instance.Logger.IsWarningEnabled)
{
instance.Logger.LogWarning("PhotonVoiceNetwork Instance already destroyed on application quit. Won't create again - returning null.");
}
return null;
}
if (!instantiated)
{
PhotonVoiceNetwork[] objects = FindObjectsOfType<PhotonVoiceNetwork>();
if (objects == null || objects.Length < 1)
{
GameObject singleton = new GameObject();
singleton.name = "PhotonVoiceNetwork singleton";
instance = singleton.AddComponent<PhotonVoiceNetwork>();
if (instance.Logger.IsInfoEnabled)
{
instance.Logger.LogInfo("An instance of PhotonVoiceNetwork was automatically created in the scene.");
}
}
else if (objects.Length >= 1)
{
instance = objects[0];
if (objects.Length > 1)
{
if (instance.Logger.IsErrorEnabled)
{
instance.Logger.LogError("{0} PhotonVoiceNetwork instances found. Using first one only and destroying all the other extra instances.", objects.Length);
}
for (int i = 1; i < objects.Length; i++)
{
Destroy(objects[i]);
}
}
}
instantiated = true;
}
return instance;
}
}
set
{
lock (instanceLock)
{
if (value == null)
{
if (instance.Logger.IsErrorEnabled)
{
instance.Logger.LogError("Cannot set PhotonVoiceNetwork.Instance to null.");
}
return;
}
if (instantiated)
{
if (instance.GetInstanceID() != value.GetInstanceID())
{
if (instance.Logger.IsErrorEnabled)
{
instance.Logger.LogError("An instance of PhotonVoiceNetwork is already set. Destroying extra instance.");
}
Destroy(value);
}
return;
}
instantiated = true;
instance = value;
}
}
}
protected override void OnDestroy()
{
base.OnDestroy();
lock (instanceLock)
{
if (instantiated && instance.GetInstanceID() == this.GetInstanceID())
{
instantiated = false;
}
}
}
I have a very similar problem, my setup is different and in my case I noticed that when the user that can't be heard changes microphone input (like turning on a bluetooth handsfree or manually changing it in OS settings) then the voice works, I'm trying to work this out too...
I have a single persistent instance of PhotonVoiceNetwork with a recorder and I instantiate (not photon instantiate) local prefabs with a photonview and photonvoiceview to which I then sync phtonviewID's over network
I've tried a number of configurations but none have given me stable results, if you could help I'd be grateful for life.
Dear @JohnTube
The code you gave me helped me discover that there was actually another instance of PhotonVoiceNetwork. I removed the one that I didn't need and the error displayed on the console disappeared (the client does not fail to connect).
The program however still does not work: the second client does not manage to send their voice across the network.
I am going to investigate why this happens and I will write what I discover.
Thanks for the help so far :smiley:
Hi @VPadu,
You can use VoiceDebugScript here, add it next to PhotonVoiceView.
Dear @JohnTube
I finally solved my problem.
The thing is that I did not completely understand how PhotonVoice works so when another client entered the room, since I do not need this functionality, I did not spawn a player. The PhotonView component was just already present in the scene so that's why it did not work.
Your VoiceDebugScript did not work so reading the discussion that you linked me made me understand how I should have used Photon Voice.
Thank you very much for your help, really. :heart:
Hope this discussion will help other people that made the same mistake as me.
Have a nice day everyone :smiley: