Photon Chat Onsubscribe not responding

I am trying to send private message on a channel in chat. I am able to connect to the chat but not able to subscribe the chat channel Onsubscribe function is not responding on call of this function - > chatClient.Subscribe(new string[] { "invitationsChannel" }); calling this function after getting response connected to chat server.

Comments

  • Hi @Sudipta,

    Thank you for choosing Photon!

    Subscribe is for public chat channels. Sending private messages to a user does not require explicit subscription to a channel. You send private messages using SendPrivateMessage methods.

    What do you mean by "Onsubscribe not responding"? Do you mean "IChatClientListener.OnSubscribed" method not called?
    There should be a callback for channels subscription. You need to implement IChatClientListener interface which contains void OnSubscribed(string[] channels, bool[] results);.
    You can start publishing public messages into that channels once you are subscribed. You need to use PublishMessage methods.
  • SudiptaSudipta
    edited March 28
    Yeah that's what i mean. I have implemented IChatClientListener interface in my script but em not getting callback for any kind of chat either it's private or public message. Lemme show u what i did.


    Here is the code:-
    public class PlayFabManager : Photon.PunBehaviour, IChatClientListener
    {
    chatClient.SendPrivateMessage(id, "INVITE_SEND;" + id + this.PlayFabId + ";" + GameManager.Instance.nameMy + ";" + message);
         public void OnSubscribed(string[] channels, bool[] results)
        {
            Debug.Log("Subscribed to a new channel - set online status!" + results);
        }
    
        public void OnPrivateMessage(string sender, object message, string channelName)
        {
            Debug.Log("OnPrivateMessage called");
        }
    }
  • JohnTubeJohnTube mod
    edited March 28
    How are you using the chat client?

    I think you are mixing public and private channels.
    Private channels do not need Subscribe or Unsubscribe so you will not get OnSubscribed or OnUnsubcribed. You only get OnPrivateMessages if you call SendPrivateMessage.
    Public channels needs client to be subscribed in order to send messages using PublishMessage that you will receive in OnGetMessages. Then you can Unsusbcribe at any time and OnUnsubscribed will be called.

    How are you setting the IChatClientListener?
    I guess you are using something like this?
    public class PlayFabManager : Photon.PunBehaviour, IChatClientListener
    {
    // [...]
    chatClient = new ChatClient(this); 

  • SudiptaSudipta
    edited March 29
    i am using both things separately for i need to send private message, but on the other side em not getting response of the private message in OnPrivateMessages().

    Here is the proper code of implementation:-
    public void connectToChat() {
            chatClient = new ChatClient(this);
            GameManager.Instance.chatClient = chatClient;
            // Set your favourite region. "EU", "US", and "ASIA" are currently supported.
            ExitGames.Client.Photon.Chat.AuthenticationValues authValues = new ExitGames.Client.Photon.Chat.AuthenticationValues();
            authValues.UserId = this.PlayFabId;
            authValues.AuthType = ExitGames.Client.Photon.Chat.CustomAuthenticationType.Custom;
            authValues.AddAuthParameter("username", this.PlayFabId);
            authValues.AddAuthParameter("Token", authToken);
            chatClient.Connect(this.PhotonChatID, "1.0", authValues);
        }
    
    public void OnConnected()
        {
            Debug.Log("Photon Chat connected!!!");
            chatClient.Subscribe(new string[] { "invitationsChannel" });//this is for public messages
        }
    
     public void OnSubscribed(string[] channels, bool[] results)
        {
            Debug.Log("Subscribed to a new channel - set online status!" + results);
    }
    
    public void challengeFriend(string id, string message)
        {
            chatClient.SendPrivateMessage(id, "INVITE_SEND;" + id + this.PlayFabId + ";" + GameManager.Instance.nameMy + ";" + message);
    
            //chatClient.PublishMessage( "invitationsChannel", "So Long, and Thanks for All the Fish!" );
            Debug.Log("Send invitation to: " + id);
    
        }
    
    public void OnPrivateMessage(string sender, object message, string channelName)
        {
            Debug.Log("private message");
            if (!sender.Equals(this.PlayFabId))
            {
                if (message.ToString().Contains("INVITE_SEND"))
                {
                    string roomName = message.ToString().Split(';')[1];
                    int payout = Int32.Parse(message.ToString().Split(';')[3]);
                    GameManager.Instance.tableNumber = Int32.Parse(message.ToString().Split(';')[4]);
                    Debug.Log("INVITE_SEND " + message + "  " + sender + " room: " + roomName);
                    GameManager.Instance.payoutCoins = payout;
                    GameManager.Instance.invitationDialog.GetComponent<PhotonChatListener>().showInvitationDialog(0, message.ToString().Split(';')[2], sender, roomName);
    
                    //			GameManager.Instance.invitationDialog.GetComponent<Animator> ().Play ("InvitationDialogShow");
                    //			GameObject.Find ("InvitationDialog").GetComponent<Animator> ().Play ("InvitationDialogShow");
    
                }
    `    }
    }

    In this i am getting that em connected to chat successfully but when i am trying to send private message there is no response in OnPrivateMessages(), even i tried to send public message but its same OnGetMessages() also not giving any response.
  • SudiptaSudipta
    edited March 30
    yes em using like this
    public class PlayFabManager : Photon.PunBehaviour, IChatClientListener
    {
       public void connectToChat() {
            chatClient = new ChatClient(this);
            GameManager.Instance.chatClient = chatClient;
            // Set your favourite region. "EU", "US", and "ASIA" are currently supported.
            ExitGames.Client.Photon.Chat.AuthenticationValues authValues = new ExitGames.Client.Photon.Chat.AuthenticationValues();
            authValues.UserId = this.PlayFabId;
            authValues.AuthType = ExitGames.Client.Photon.Chat.CustomAuthenticationType.Custom;
            authValues.AddAuthParameter("username", this.PlayFabId);
            authValues.AddAuthParameter("Token", authToken);
            chatClient.Connect(this.PhotonChatID, "1.0", authValues);
        }
    
       public void OnConnected()
        {
            Debug.Log("Photon Chat connected!!!");
            chatClient.Subscribe(new string[] { "invitationsChannel" });
        }
    
        public void OnSubscribed(string[] channels, bool[] results)
        {
            Debug.Log("Subscribed to a new channel - set online status!" + results);
    
            //splashCanvas.SetActive (false);
    
            chatClient.SetOnlineStatus(ChatUserStatus.Online);
        }
    
        public void challengeFriend(string id, string message)
        {
            chatClient.SendPrivateMessage(id, "INVITE_SEND;" + id + this.PlayFabId + ";" + GameManager.Instance.nameMy + ";" + message);
    
            //chatClient.PublishMessage( "invitationsChannel", "So Long, and Thanks for All the Fish!" );
            Debug.Log("Send invitation to: " + id);
    
        }
    
        public void OnPrivateMessage(string sender, object message, string channelName)
        {
            Debug.Log("private message");
            if (!sender.Equals(this.PlayFabId))
            {
                if (message.ToString().Contains("INVITE_SEND"))
                {
                    string roomName = message.ToString().Split(';')[1];
                    int payout = Int32.Parse(message.ToString().Split(';')[3]);
                    GameManager.Instance.tableNumber = Int32.Parse(message.ToString().Split(';')[4]);
                    Debug.Log("INVITE_SEND " + message + "  " + sender + " room: " + roomName);
                    GameManager.Instance.payoutCoins = payout;
                    GameManager.Instance.invitationDialog.GetComponent<PhotonChatListener>().showInvitationDialog(0, message.ToString().Split(';')[2], sender, roomName);
    
                    //			GameManager.Instance.invitationDialog.GetComponent<Animator> ().Play ("InvitationDialogShow");
                    //			GameObject.Find ("InvitationDialog").GetComponent<Animator> ().Play ("InvitationDialogShow");
    
                }
           }
       }
    
    public void OnGetMessages(string channelName, string[] senders, object[] messages)
        {
            Debug.Log("Public Message");
            string msgs = "";
           for ( int i = 0; i < senders.Length; i++ )
           {
               msgs = string.Format("{0}{1}={2}, ", msgs, senders[i], messages[i]);
           }
           Console.WriteLine( "OnGetMessages: {0} ({1}) > {2}", channelName, senders.Length, msgs );
        }
    }
  • Could you please post the Unity logs (screenshot or text)?
    According to your report you should be seeing "Photon Chat connected!!!" and not "Subscribed to a new channel - set online status!".
    Are you attaching the "PlayFabManager" script to a scene object or to a prefab? Are you switching scenes?

    How are you using "invitationsChannel"? It seems to me you are not publishing any message into that channel as you are sending invitations via private messages only. There is not PublishMessage call.
  • SudiptaSudipta
    edited March 29
    https://drive.google.com/file/d/0B9lQacQnsWLHc3c3d0xBVVFDUUk/view?usp=sharing

    this is the log screenshot.

    i am attaching playfabmanager to scene object and yes when i get a response of connected to lobby i change my login seen to lobby scene but playfabmanager is also going to lobby scene it has DontDestroyOnLoad () function.

    For now yes em not sending any public message just using private message but not getting response, i tried public message, as em not able to get private message response but same problem with public message as well. i am using unity 5.6.0f1.
  • SudiptaSudipta
    edited March 30
    have you find the reason?
  • No I did not find anything.
    Do you get an error when you call PublishMessage or SendPrivateMessage?
    If not then you are sending messages successfully but the issue is in the callbacks.

    What I suggest:
    - Try a simple scene with the IChatClientListener as a separate class.
    - Try with two different clients and see if messages arrive.
    - Try another Unity version.
  • NO i am not getting error while sending message, the main problem is callbacks and okey lemme try this in new project with same chat id. If i got succeed that means my unity version is not supporting chat plugin. On the other hand my project is not working under unity 5.5 so i dont have much choice choosing different version i need minimum unity5.5 for my project
  • SudiptaSudipta
    edited March 30
    Sry for wasting your time i just checked and found a silly mistake that was done by me. I have interchanged appid and chatid in my variable. em really very for this mess. Thank you for helping me out.
Sign In or Register to comment.