Send and Receive Private Messages
Sends a 1:1 private message to a friend currently connected to the application.
Call Information
SendPrivateMessage(string friendUserId, string message) {}
Call Details
| Parameter | Description | Type |
|---|---|---|
| friendUserId | Friend user ID | string |
| message | Message to send | string |
Callback Method Information
public void OnPrivateMessage(ChatInfoModel chatInfo, string message) {}
ChatInfoModel Class Details
The ChatInfoModel Class contains information about the channel and user who sent the message.
| Data Key | Description | Type |
|---|---|---|
| gameId | Game ID | string |
| channelId | Channel ID | string |
| userUniqueId | User ID | string |
| userName | User name | string |
Source Code
using UnityEngine;
using PlayNANOO.ChatServer;
using PlayNANOO.ChatServer.Models;
public class PlayNANOOChatExample : MonoBehaviour, IChatListener
{
ChatClient chatClient;
void Start()
{
chatClient = new ChatClient(this);
chatClient.SetPlayer("USER_ID", "USER_NAME");
chatClient.Connect();
}
void Update()
{
if (chatClient != null)
{
chatClient.Service();
}
}
public void OnConntected()
{
chatClient.Subscribe("CHANNEL_ID");
}
public void OnSubscribed(ChatInfoModel chatInfo)
{
Debug.Log("User Joined");
}
public void SendPrivateMessage()
{
string friendUserId = "string";
string message = "string";
chatClient.SendPrivateMessage(friendUserId, message);
}
public void OnPrivateMessage(ChatInfoModel chatInfo, string message)
{
Debug.Log(message);
}
}