Help me to make photon chat is simple

Hi guys!
I imported photon chat to use. But the package more than 500 lines code. In a postion as a newbie. I cant understand all of line code. And I wonder why Photon Chat have no document like PUN or Bolt. It too little documentation as well as incomplete :(((
Currently, I just want implement the feature chat, with send chat to sever with formatted JSON, and receive message. Not want more feature like friend, status online,,.. I don't know which line to delete in Photon Chat package :(((

Comments

  • JohnTubeJohnTube mod
    edited July 2
    Hi @hieutran196,

    Thank you for choosing Photon!

    You do not need to delete anything.

    You need to implement a chat callbacks listener interface and periodically call chatClient.Service() like from an Update method of a MonoBehaviour. The rest is optional and up to you.

    Other than that, you can find documentation here and API reference here.

    Example of minimalist MyChatClient class you could use as a starting point:

    using ExitGames.Client.Photon;
    using Photon.Chat;
    using UnityEngine;
    
    public class MyChatClient : MonoBehaviour, IChatClientListener
    {
        private ChatClient chatClient;
    
        #region MonoBehaviour
    
        // Use this for initialization
        void Start()
        {
            chatClient = new ChatClient(this);
        }
    
        // Update is called once per frame
        void Update()
        {
            if (chatClient != null)
            {
                chatClient.Service();
            }
        }
    
        #endregion
    
        #region Public Methods
    
        public void Connect(string appId, string appVersion, AuthenticationValues authValues)
        {
            chatClient.Connect(appId, appVersion, authValues);
        }
    
        public bool SubscribeToPublicChannel(string channelName)
        {
            return chatClient.Subscribe(channelName);
        }
    
        public bool SendPrivateMessage(string targetUserId, object message)
        {
            return chatClient.SendPrivateMessage(targetUserId, message);
        }
    
        public bool PublishMessage(string channelName, object message)
        {
            return chatClient.PublishMessage(channelName, message);
        }
    
        #endregion
    
        #region IChatClientListener
    
        public void DebugReturn(DebugLevel level, string message)
        {
            if (this.chatClient.DebugOut != DebugLevel.ALL && level > this.chatClient.DebugOut)
            {
                return;
            }
            if (level == DebugLevel.ERROR)
            {
                Debug.LogError(message);
            }
            else if (level == DebugLevel.WARNING)
            {
                Debug.LogWarning(message);
            }
            else if (level == DebugLevel.INFO)
            {
                Debug.Log(message);
            }
            else if (level == DebugLevel.ALL)
            {
                Debug.Log(message);
            }
        }
    
        public void OnChatStateChange(ChatState state)
        {
            // todo: replace with your code
        }
    
        public void OnConnected()
        {
            // todo: replace with your code
        }
    
        public void OnDisconnected()
        {
            // todo: replace with your code
        }
    
        public void OnGetMessages(string channelName, string[] senders, object[] messages)
        {
            // todo: replace with your code
        }
    
        public void OnPrivateMessage(string sender, object message, string channelName)
        {
            // todo: replace with your code
        }
    
        public void OnStatusUpdate(string user, int status, bool gotMessage, object message)
        {
            // todo: replace with your code
        }
    
        public void OnSubscribed(string[] channels, bool[] results)
        {
            // todo: replace with your code
        }
    
        public void OnUnsubscribed(string[] channels)
        {
            // todo: replace with your code
        }
    
        public void OnUserSubscribed(string channel, string user)
        {
            // todo: replace with your code
        }
    
        public void OnUserUnsubscribed(string channel, string user)
        {
            // todo: replace with your code
        }
    
        #endregion
    }
Sign In or Register to comment.