question

jgagnon avatar image
jgagnon asked

[Playfab Party] Not able to communicate with other players

I repost on this section because i can't comment on the other.

We followed the documentation to integrate Playfab party in our project. The connection in the party is done correctly but sometimes unknown errors appear. In the game, only one computer is able to hear others. All other computers/projects hear nothing. We have tested with speech-to-text and the computers often receive the texts with some errors.

Here is the code:

 public class VoiceChatManager : MonoBehaviour
  {
      private static VoiceChatManager _instance;
      public static VoiceChatManager instance => _instance;
        
      public PlayFab.Party.PlayFabPlayer localPlayer;
      public PlayFabMultiplayerManager playFabMultiplayerManager;
        
      public string currentParty;
      public string localPlayerID;
      public Dictionary<string, PlayFab.Party.PlayFabPlayer> participants = new Dictionary<string, PlayFab.Party.PlayFabPlayer>();
      public List<string> proximityZone = new List<string>();
      public List<string> mutedParticipant = new List<string>();
      public bool isTalking;
        
      private void Awake()
      {
          _instance = this;
          DontDestroyOnLoad(gameObject);
        
          playFabMultiplayerManager = PlayFabMultiplayerManager.Get();
        
          playFabMultiplayerManager.OnNetworkJoined += OnPartyJoined;
          playFabMultiplayerManager.SpeechToTextMode = AccessibilityMode.Enabled;
          playFabMultiplayerManager.OnChatMessageReceived += OnChatMessageReceived;
          playFabMultiplayerManager.OnRemotePlayerJoined += OnRemotePlayerJoined;
          playFabMultiplayerManager.OnRemotePlayerLeft += OnRemotePlayerLeft;
      }
        
      public void Update()
      {
          if(localPlayer != null)
              isTalking = localPlayer.ChatState == ChatState.Talking;
          else
              isTalking = false;
      }
        
      private void OnChatMessageReceived(object sender, PlayFab.Party.PlayFabPlayer from, string message, ChatMessageType type)
      {
          if (type == ChatMessageType.SpeechToText)
          {
              Debug.Log(message);
          }
      }
        
      public void Login(string playerID)
      {
  #if !UNITY_GAMECORE && !UNITY_EDITOR
          return;
  #endif
        
          localPlayerID = playerID;
        
          if (Provider.clients.Count < 1)
          {
              playFabMultiplayerManager.ResetParty();
              StartCoroutine(CreateNetwork());
          }
          else
          {
              Debug.Log("[VoiceChat] Join Chat");
        
              GetServerID((networkID) =>
              {
                  Debug.Log("[VoiceChat] networkID");
                  playFabMultiplayerManager.JoinNetwork(networkID);
              });
          }
        
      }
        
      private IEnumerator CreateNetwork()
      {
          yield return null;
        
          PlayFabNetworkConfiguration config = new PlayFabNetworkConfiguration
          {
              MaxPlayerCount = 24,
          };
        
          playFabMultiplayerManager.CreateAndJoinNetwork(config);
      }
        
      private void OnPartyJoined(object sender, string networkId)
      {
          participants.Clear();
          currentParty = networkId;
        
          if (Provider.clients.Count == 1)
              SetServerPartyID(networkId);
        
          SDK.PartyChatControlSetAudioInput(PlayFabMultiplayerManager.Get().LocalPlayer._chatControlHandle,
          PARTY_AUDIO_DEVICE_SELECTION_TYPE.PARTY_AUDIO_DEVICE_SELECTION_TYPE_SYSTEM_DEFAULT, null, null);
          SDK.PartyChatControlSetAudioOutput(PlayFabMultiplayerManager.Get().LocalPlayer._chatControlHandle,
              PARTY_AUDIO_DEVICE_SELECTION_TYPE.PARTY_AUDIO_DEVICE_SELECTION_TYPE_SYSTEM_DEFAULT, null, null);
        
          Debug.Log($"[VoiceChat] you has a player has joined");
        
          localPlayer = playFabMultiplayerManager.LocalPlayer;
          playFabMultiplayerManager._SetVoiceLevel(localPlayer.EntityKey, 1, true);
          playFabMultiplayerManager._SetMuted(localPlayer.EntityKey, false, true);
        
        
          SDK.PartyChatControlGetPermissions(localPlayer._chatControlHandle, localPlayer._chatControlHandle, out PARTY_CHAT_PERMISSION_OPTIONS options);
        
          options = PARTY_CHAT_PERMISSION_OPTIONS.PARTY_CHAT_PERMISSION_OPTIONS_SEND_AUDIO |
                    PARTY_CHAT_PERMISSION_OPTIONS.PARTY_CHAT_PERMISSION_OPTIONS_SEND_MICROPHONE_AUDIO |
                    PARTY_CHAT_PERMISSION_OPTIONS.PARTY_CHAT_PERMISSION_OPTIONS_RECEIVE_AUDIO |
                    PARTY_CHAT_PERMISSION_OPTIONS.PARTY_CHAT_PERMISSION_OPTIONS_RECEIVE_MICROPHONE_AUDIO;
        
          SDK.PartyChatControlSetPermissions(localPlayer._chatControlHandle, localPlayer._chatControlHandle, options);
      }
        
      private void OnRemotePlayerJoined(object sender, PlayFab.Party.PlayFabPlayer player)
      {
          SDK.PartyChatControlGetPermissions(PlayFabMultiplayerManager.Get().LocalPlayer._chatControlHandle, player._chatControlHandle,
        out PARTY_CHAT_PERMISSION_OPTIONS options);
        
          options = PARTY_CHAT_PERMISSION_OPTIONS.PARTY_CHAT_PERMISSION_OPTIONS_RECEIVE_AUDIO |
                    PARTY_CHAT_PERMISSION_OPTIONS.PARTY_CHAT_PERMISSION_OPTIONS_SEND_AUDIO;
        
          SDK.PartyChatControlSetPermissions(PlayFabMultiplayerManager.Get().LocalPlayer._chatControlHandle, player._chatControlHandle,
              options);
        
          Debug.Log($"[VoiceChat] A player has joined");
          player._chatControlHandle = playFabMultiplayerManager.LocalPlayer._chatControlHandle;
        
          playFabMultiplayerManager._SetVoiceLevel(player.EntityKey, 1, false);
          playFabMultiplayerManager._SetMuted(player.EntityKey, false, false);
        
          participants.Add("00000000" + player._entityToken, player);
      }
        
      private void OnRemotePlayerLeft(object sender, PlayFab.Party.PlayFabPlayer player)
      {
          Debug.Log($"[VoiceChat] A player has left");
        
          participants.Remove("00000000" + player._entityToken);
      }
            
      public void Leave()
      {
  #if !UNITY_GAMECORE && !UNITY_EDITOR
          return;
  #endif
        
          Debug.Log("[VoiceChat] Leaving Chat");
          playFabMultiplayerManager.LeaveNetwork();
          currentParty = null;
      }
        
      public void SetServerPartyID(string _networkId)
      {
          string playerID = PlayFabManager.instance.serverTargetConnect.targetPlayerId;
          Debug.Log(playerID);
        
          try
          {
              string functionName = "SetServerPartyID";
              ExecuteCloudScriptRequest request = new ExecuteCloudScriptRequest()
              {
                  FunctionName = functionName,
                  FunctionParameter = new
                  {
                      targetPlayer = playerID,
                      worldKey = Provider.CurrentWorldKey,
                      networkId = _networkId
                  },
                  GeneratePlayStreamEvent = true
              };
        
              PlayFabClientAPI.ExecuteCloudScript(request, null, (error) =>
              {
                  UnityEngine.Debug.LogError($"[VoiceChat] PlayFabManager: {functionName} ERROR: {error.Error} MESSAGE: {error.ErrorMessage} DETAIL: {error.ErrorDetails}");
              });
          }
          catch (Exception e)
          {
              UnityEngine.Debug.LogError("PlayFabManager.PlayFabRequest(): Couldn't create/send the PlayFab request, an exception was detected! " + e);
          }
      }
        
      public void GetServerID(System.Action<string> callback)
      {
          var playerID = PlayFabManager.instance.serverTargetConnect.targetPlayerId;
        
          try
          {
              string functionName = "GetServerPartyID";
              ExecuteCloudScriptRequest request = new ExecuteCloudScriptRequest()
              {
                  FunctionName = functionName,
                  FunctionParameter = new
                  {
                      targetPlayer = playerID,
                      worldKey = Provider.CurrentWorldKey,
                  },
                  GeneratePlayStreamEvent = true
              };
        
              PlayFabClientAPI.ExecuteCloudScript(request, (response) =>
              {
                  Debug.Log(response.FunctionResult);
                  JObject result = JObject.Parse(response.FunctionResult.ToString());
                  JObject value = JObject.Parse(result["VocalIDS"].ToString());
                  JObject keys = JObject.Parse(value["Value"].ToString());
                  string key = keys[Provider.CurrentWorldKey].ToString();
        
                  Debug.Log(key);
                  callback?.Invoke(key);
        
              }, (error) =>
              {
                  UnityEngine.Debug.LogError($"[VoiceChat] PlayFabManager: {functionName} ERROR: {error.Error} MESSAGE: {error.ErrorMessage} DETAIL: {error.ErrorDetails}");
              });
          }
          catch (Exception e)
          {
              UnityEngine.Debug.LogError("PlayFabManager.PlayFabRequest(): Couldn't create/send the PlayFab request, an exception was detected! " + e);
          }
      }
        
      public bool IsTalking()
      {
          return isTalking;
      }
  }

I have tested on the demo scene given by the Guide but same result.

apissdksdocumentation
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
Neils Shi avatar image
Neils Shi answered

After my tests, the demo scene works fine. Clients can hear each other. Did you modify anything? Have you checked the device settings of other computers? Maybe there are some hardware issues.

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.