OnUserSubscribed and OnUserUnsubscribed not calling

TeohTCTeohTC
edited July 28 in Photon Chat
Hi,

I facing problem that OnUserSubscribed and OnUserUnsubscribed not calling, I already referred to this post https://forum.photonengine.com/discussion/15651/onusersubscribed-not-called and enable PublishSubscribers but still not working when second user left the channel. Need some help on checking this. The OnSubscribed and Unsubscribed got call on client side

Photon PUN version: 2.19.3
Unity: 2019.4.3f1
Purpose: I using Photon Chat to create a party system to group the player before search game
//Subscribe to the channel
chatClient.Subscribe(channelName, 0, -1, new ChannelCreationOptions(){PublishSubscribers = true, MaxSubscribers = 3});

//Left the channel
chatClient.Unsubscribe(new string[]{party_ChannelName});

//The callback function
public void OnUserSubscribed(string channel, string user) {

    Debug.Log("Chat: User Subscribed " + user);

        //Check for party
    if(channel == party_ChannelName){

        Party_PartyTeamUpdate(false, ref user);

    }

}

//The callback function
public void OnUserUnsubscribed(string channel, string user) {

    Debug.Log("Chat: User Unsubscribed " + user);

    //Check for party
    if(channel == party_ChannelName){

        Party_PartyTeamUpdate(true, ref user);

    }

}

Comments

  • JohnTubeJohnTube mod
    edited July 28
    Hi @TeohTC,

    Make sure PublishSubscribers was enabled during channel creation.
    public void OnSubscribed(string[] channels, bool[] results)
        {
            for (int i = 0; i < channels.Length; i++)
            {
                if (party_ChannelName.Equals(channels[i]))
                {
                    if (results[i])
                    {
                        ChatChannel partyChannel;
                        if (this.ChatClient.TryGetChannel(party_ChannelName, false, out partyChannel))
                        {
                            if (!partyChannel.PublishSubscribers)
                            {
                               Debug.LogError("PublishSubscribers was not set during channel creation.");
                            }
                        }
                    }
                    else 
                    {
                           Debug.LogError("Party channel subscription failed.");
                    }
                }
            }
        }
    
  • TeohTCTeohTC
    edited July 28
    JohnTube wrote: »
    Hi @TeohTC,

    Make sure PublishSubscribers was enabled during channel creation.
    public void OnSubscribed(string[] channels, bool[] results)
        {
            for (int i = 0; i < channels.Length; i++)
            {
                if (party_ChannelName.Equals(channels[i]) && results[i])
                {
                    ChatChannel partyChannel;
                    if (this.ChatClient.TryGetChannel(party_ChannelName, false, out partyChannel))
                    {
                        if (!partyChannel.PublishSubscribers)
                        {
                            Debug.LogError("PublishSubscribers was not set during channel creation.");
                        }
                    }
                }
            }
        }
    

    yap, I tried to debug with this also and it return true
    void Party_Debug_CheckChannelSetting(){
            
            ChatChannel cc;
            
            chatClient.TryGetChannel(party_ChannelName, false, out cc);
    
            Debug.Log("Chat Debug: Publish Subscribers " + cc.PublishSubscribers.ToString());
    
        }
    
  • Increase log level and watch logs for errors.
    Maybe MaxSubscribers was reached for the channel and you missed those callbacks or the client failed to subscribe as the limit was hit.
    OK; if chatChannel.PublishSubscribers is true, what does chatChannel.Subscribers contain?

    Maybe users are on different regions or on a different AppId or a different AppVersion?
    So they end up on different channels each.
    Are you sure they can communicate with other or 'see' each other?

    If the issue persists...
    Try changing channel name, changing AppVersion, changing AppId, changing region, changing UserId...

    If all this does not help, let us know the minimal repro steps.
  • JohnTube wrote: »
    Increase log level and watch logs for errors.
    Maybe MaxSubscribers was reached for the channel and you missed those callbacks or the client failed to subscribe as the limit was hit.
    OK; if chatChannel.PublishSubscribers is true, what does chatChannel.Subscribers contain?

    Maybe users are on different regions or on a different AppId or a different AppVersion?
    So they end up on different channels each.
    Are you sure they can communicate with other or 'see' each other?

    If the issue persists...
    Try changing channel name, changing AppVersion, changing AppId, changing region, changing UserId...

    If all this does not help, let us know the minimal repro steps.

    Hi, thanks I solved the problem, at the end nothing wrong with Chat, there was some mistake in my custom message serialization
Sign In or Register to comment.