ルームクラスでは、テキストチャットの機能を提供しています。
Diarkis Roomは、テキストチャット機能に対応しています。
テキストチャットのデータは、ルームごとにサーバーのメモリに保存・管理されます。
チャットメッセージのデータを永続化するためには、ルームから外部のデータベースやストレージにチャットデータを送信する必要があります。外部のストレージにチャットデータを送信する方法はこちらを参照ください。
テキストチャットメッセージを送る
// Capture the response from the server
room.OnChatSyncResponse += (bool success, byte[] payload) =>
{
// If success is false, delivery of the chat message has failed.
// payload may contain error information.
};
// Send the message to others
room.SendChatMessage("Hello there!");
テキストチャットメッセージを受け取る
テキストチャットのメッセージは、イベントリスナーコールバックで受け取ります。
コールバックは、テキストチャットの送信者、タイムスタンプ、およびテキストメッセージを含む RoomChatData のインスタンスを引数として渡します。
public class RoomChatData
{
// Sender user ID
public string SenderUID;
// Timestamp of the chat message in milliseconds
public long Timestamp;
// Text chat message
public string Message;
}
room.OnChatSync += (Diarkis.Modules.Room.RoomChatData chatData) =>
{
// Handle the text chat message here
};
チャットの履歴を取得する
ルームに参加する際、ルームに参加する前に送信された全てのテキストチャットのメッセージを取得する必要がある場合があります。
ここでは、その方法を説明します。
// Receive the chat log from the server with this event listener callback
room.OnChatLog += (List<Diarkis.Modules.Room.RoomChatData> chatLogList) =>
{
// Handle the chat log
};
// Ask the server to get you the chat log
room.GetChatLog();