private message

diegodiego
edited April 20 in Photon Chat
sorry for my bad english but i had to write this in the translator.
I'm having trouble sending and receiving private messages,
sending the message to the chatclient who sent it receives it. And the recipient does not receive. I really want to know what's wrong with my code.


using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Photon.Chat;
using Photon.Pun;
using Photon.Realtime;
using TMPro;

public class ChatManager : MonoBehaviour , IChatClientListener
{   
    public static ChatManager Instance = null;
    public ChatClient chat;
    public string AppID;
    public string Versao;
    public string ChannelGlobal = "Global";
    public string ChannelInvite = "ChannelInvite";
    public GameObject ContainerChatLog;
    public GameObject prefabMensagem;

    protected  ChatAppSettings chatAppSettings;
    




    private void Awake(){
        InstanciaUnica();
        Application.runInBackground = true;
        Conectar();
    }

    
    void Conectar(){
        chat = new ChatClient(this,ExitGames.Client.Photon.ConnectionProtocol.Tcp);
        chat.Connect(AppID,Versao,new Photon.Chat.AuthenticationValues(PhotonNetwork.LocalPlayer.NickName));
        
    }

    private void Update() {
        chat.Service();

    }

    void InstanciaUnica(){
        if(Instance == null){
            Instance = this;
            DontDestroyOnLoad(this);
        }else{
            GameObject.Destroy(this);
        }
    }

    public void EnviarLog(string Mensagem){
        GameObject NovaMensagem = Instantiate(prefabMensagem,Vector3.zero,Quaternion.identity);
        NovaMensagem.transform.SetParent(ContainerChatLog.transform);
        NovaMensagem.GetComponent<TextMeshProUGUI>().text = Mensagem;
        NovaMensagem.transform.localScale = Vector3.one;
    }

    void EnviarMensagemInicial(){
        chat.PublishMessage("Global","Concectado.");
    }

    public void EnviarConvite(string NomeJogador){
        
        chat.SendPrivateMessage(NomeJogador,"Convite");
        
    }

    #region IChatClientListener implementation

    public void DebugReturn (ExitGames.Client.Photon.DebugLevel level, string message)
    {
        
    }

    public void OnDisconnected ()
    {
        throw new System.NotImplementedException ();
    }

    public void OnConnected ()
    {
        Debug.Log("Chat Conectado");
        chat.SetOnlineStatus(ChatUserStatus.Online);
        chat.Subscribe(new string[]{"Global"});
        EnviarMensagemInicial();
        
    }

    public void OnChatStateChange (ChatState state)
    {
        
    }

    public void OnGetMessages (string channelName, string[] senders, object[] messages)
    {
        
        string msgs = "";
        for ( int i = 0; i < senders.Length; i++ )
        {   
            
            msgs = string.Format("{0}{1}: {2}", msgs, senders[i], messages[i]);
        }
        EnviarLog(msgs);

    }

    public void OnPrivateMessage (string sender, object message, string channelName){

        EnviarLog(channelName+ " " + sender +": " + message);
        
    }

    public void OnSubscribed (string[] channels, bool[] results)
    {
        
    }

    public void OnUnsubscribed (string[] channels)
    {
        
    }

    public void OnStatusUpdate (string user, int status, bool gotMessage, object message)
    {
        
    }

    public void OnUserUnsubscribed(string A, string B){

    }

    public void OnUserSubscribed(string A, string B){

    }



    #endregion
}

Comments

  • Hi @diego,

    Thank you for choosing Photon!

    In Photon Chat by design public and private messages are broadcast so the sender will receive them back yes.
    Some things to consider to troubleshoot remote/destination client not receiving private message:

    - make sure the client is connected
    - make sure the client is connected to the same region
    - make sure the client is connected to the same application (AppId)
    - make sure the client is connected to the same application version (AppVersion)

    If issue persists:
    You could also make use of public chat channel (subscribe & exchange a message in the same public chat channel and see if both receive it) or user/friend status (add user as a friend and change its status to see if you get the notification about status change) to debug this.

  • I can send messages and receive them publicly with all the chatclients that are open, but when I send the private message it does not reach the target. In fact, instead of reaching the target, the message returns to whoever sent it.
  • I appreciate the help but the error was so silly, I was treating a text mesh pro input as a text and not an input.
    thank you again
Sign In or Register to comment.