Skip to main content

Subscribe to Channel

Explains how to enter (subscribe to) a specific channel.

Description

Enter a specific channel by calling the ChatManager.Instance.Subscribe() method. After entering, you can receive messages from that channel. Set the prevMessageCount parameter to retrieve previous chat history.

Method Information

ItemContent
MethodChatManager.Instance.Subscribe(string channel, int prevMessageCount = 0)
CallbackOnSubscribed(ChatUserInfo user) - Called when user enters

Parameters

ParameterTypeDescription
channelstringChannel name to subscribe to
prevMessageCountintNumber of previous messages to fetch (default: 0)

Unity C# Usage Example

using UnityEngine;

public class ChatExample : MonoBehaviour, IChatListener
{
private string myChannel = "Default Channel";

public void EnterChannel()
{
myChannel = "string";
// Fetch 10 previous messages
ChatManager.Instance.Subscribe(myChannel, 10);
}

public void OnSubscribed(ChatUserInfo user)
{
Debug.Log($"{user.visitorName} entered");
}

// ... Other IChatListener method implementations
}