Message sent in chat area OnUserSubscribed and OnUserUnsubscribed

Options
Hello,

I want to send message to current chat channel when player join to that chat channel or leave it.

Player is subscribed to chat channel when method OnJoinedRoom is invoked with that code (through public method in my chat manager):
chatClient.Subscribe("Room: " + channelName, 0, -1, new ChannelCreationOptions() { PublishSubscribers = true, MaxSubscribers = 2 });

I tried invoke method mentioned above with MaxSubscribers = 100 for example.

In OnUserSubscribed method, I invoke that method:
chatClient.PublishMessage(channel, user + " join to chat channel " + channel);

Sometimes code is invoked, sometimes not.

Additionally, sender is different than user in message (something like that below):
matikumpel1: test123 join to chat channel Room: ejhd

When I tried send message with code mentioned below, I didn't receive any chat messages:
private void AddMessageToChannel(string message, string channelName)
    {
        int i = -1;
        ChatChannel chatChannel;
        chatClient.TryGetChannel(channelName, out chatChannel);
        if (chatChannel != null)
        {
            string messageToSend = "<i><color=#FF0000>" + message + "</color></i>";
            chatChannel.Add("System", messageToSend, i + 1);
        }
    }
AddMessageToChannel("Player " + user + " join to chat channel " + channel, channel);

When player left the room, OnUserUnsubscribed isn't invoked at all.

My question is when OnUserSubscribed and OnUserUnsubscribed is invoked and which user should add to message as sender and parameter "user" (user joining room or user who is already in room)? And why these methods sometimes is invoked and sometimes not?

I understand that Unsubscribe method should invoked only when I want to remove chat channel, because messages is still sent to chat when one player is still in room, but with error in Unity console.

Answers

  • KamilZ
    Options
    KamilZ wrote: »
    When player left the room, OnUserUnsubscribed isn't invoked at all.

    Sorry, OnUserUnsubscribed was invoked when I used PublishMessage method, but about minute later.