Skip to main content
Version: 1.3.0

Channel

You can implement channel joins and exits. You can also use callback when a new user joins or exits the channel.\

tip

When a channel group has been set in the console based on the user's country, language, countrycode, or guild, the user automatically enters the channel according to their properties when they connect to the chat server. To set the automatic channel group, check the console guide documentation.

caution

You cannot use language, country, countrycode, guild, and whisper as channel group names. These are reserved words used in the Auto Create Channel function.

Description

The following details callback methods, call methods, and information classes related to the channel.

Callback method

// Called when channel join is completed
public void OnJoinChannel(ChannelInfo channelInfo)
{
// channelInfo: Contains channel information, user list, and previous messages
}

// Called when channel leave is completed
public void OnLeaveChannel(ChannelInfo channelInfo)
{
// channelInfo: Information about the channel that was left
}

// Called when another user joins the channel
public void OnJoinChannelPlayer(
string channelGroup,
string channelName,
UInt64 channelNumber,
PlayerInfo player)
{
// player: Information about the user who joined
}

// Called when another user leaves the channel
public void OnLeaveChannelPlayer(
string channelGroup,
string channelName,
UInt64 channelNumber,
PlayerInfo player)
{
// player: Information about the user who left
}

Call method

// Only private channels can be created in an SDK.
// You will need to use the console for other channel types.

// This is the method that creates private channels. It inserts and delivers the channel group, channel number, channel name, maximum users, and password.
// If you do not enter a password, the channel will be created as a public channel.
// If the channel number is sent as 0, the server automatically grants the channel number.
ChatClient.SendCreatePrivateChannel(string channelGroup, UInt64 channelNumber = 0, string channelName = "default", uint maxCount = 50, string password = "")

// This is the channel join method of the open channel type. It passes the channel group and the channel's name as arguments.
ChatClient.SendJoinOpenChannel(string channelGroup, string channelName)

// This is the channel join method of the private channel type. It passes the channel group and the channel's number as arguments.
ChatClient.SendJoinPrivateChannel(string channelGroup, ulong channelNumber, string password = "")

// This is the channel exit method. It passes the channel group, channel name, and channel number as arguments.
ChatClient.SendLeaveChannel(string channelGroup, string channelName, UInt64 channelNumber = 0)
// These methods are related to the guild channel and are usable only if you are using BACKND Base's guild function.

// This is the guild channel join method.
ChatClient.SendJoinGuildChannel();

// This is the guild channel exit method.
ChatClient.SendLeaveGuildChannel();
If you are using BACKND Base's guild function, you must implement a separate logic for the guild chat entry and exit of a new guild.\

For example, you must call the following code after the guild creation (CreateGuildV3).

ChatClient.SendJoinGuildChannel();

You must call the following code after withdrawing from the guild (WithdrawGuildV3).

ChatClient.SendLeaveGuildChannel();

Additionally, if you set the guild registration acceptance to real-time notification, you must call the guild chat entry method when the OnApprovedGuildJoin callback occurs. Calling the method will automatically allow users to enter the guild chat channel of the guild they joined.

Guild chat will become unavailable until the user reconnects if the logic is not handled separately.

To create a guild channel using only Chat SDK, you must implement it using the following method:

Enter the following code when creating a guild. You need to use a channel group name other than guild as it is a reserved word used in the auto channel creation function. You are automatically connected to the channel when the guild is created.

ChatClient.SendCreatePrivateChannel("guilds", 1, "guildname", 100, "");

After reconnecting, you must call the method below to connect to the guild channel.

ChatClient.SendJoinPrivateChannel("guilds", 1);

For guild members, call the method above upon immediate guild join or acceptance, even if the callback has been implemented.

If withdrawal and kick callback is implemented on a guild member, the following method must be called for that member to exit the guild channel:

ChatClient.SendLeaveChannel("guilds", "guildname", 1);

Information class

ChannelInfo

Channel information that is provided when entering a channel.

public class ChannelInfo
{
// Channel information
public string ChannelGroup; // Channel group name
public string ChannelName; // Channel name
public UInt64 ChannelNumber; // Channel number
public uint MaxCount; // Maximum members

// Channel data
public Dictionary<string, PlayerInfo> Players; // List of connected users
public List<MessageInfo> Messages; // Previous chat messages
}

PlayerInfo

Information of users in the channel.

public class PlayerInfo
{
public string GamerName; // User name
public string Avatar; // Avatar
public string Language; // Language
public Dictionary<string, string> Metadata; // Additional information
}

Check previous messages

public void OnJoinChannel(ChannelInfo channelInfo)
{
// Check previous messages
foreach (var msg in channelInfo.Messages)
{
Debug.Log($"[Previous messages] {msg.GamerName}: {msg.Message}");
}

// Check users who are currently logged in
foreach (var player in channelInfo.Players)
{
Debug.Log($"Connected: {player.Value.GamerName}");
}
}