Why events dont work the same on different clients in the nakama clients

on unity Client there Is Event called “OnPressenceUpdate”. When match is created and the presence is updated, one client receives on single Event with added 2 players to the match but another receives 2 events that on each of them on played has joined.

is there any reason for this or is it just a technical limitation?

Hello @virtouso,

Can you be more specific on what events or SDKs you’re observing these differences?

the client sdk is unity. and the callback is " socket.ReceivedMatchPresence"

Where can I find this event or callback?

public class NakamaAutomaticMatch : MonoBehaviour
{
private string emailText = "";
private string inputText = "";


private const string scheme = "http";
private const string host = "localhost";
private const int port = 7350;
private const string serverKey = "defaultkey";

private IClient client;
private ISocket socket;
private ISession session;

private IMatch match;
private string matchId = "";
private string joinMatchId = "";


void OnGUI()
{
    emailText = GUILayout.TextField(emailText, 25, GUILayout.Width(200));
    inputText = GUILayout.TextField(inputText, 25, GUILayout.Width(200));

    GUILayout.Space(10);


    if (GUILayout.Button("Auth", GUILayout.Width(100)))
    {
        Authenticate();
    }

    if (GUILayout.Button("Create", GUILayout.Width(100)))
    {
        CreateMatch();
    }

    if (GUILayout.Button("Send", GUILayout.Width(100)))
    {
        SendMessage(inputText);
    }

    if (GUILayout.Button("Leave", GUILayout.Width(100)))
    {
        socket.LeaveMatchAsync(match);
    }
}

private async Task Authenticate()
{
    client = new Client(scheme, host, port, serverKey);
    socket = Nakama.Socket.From(client);

    // Authenticate with device ID
    session = await client.AuthenticateEmailAsync(emailText, "123456789");

    Debug.LogError($"Authenticated: {session.UserId}");

    // Connect socket
    await socket.ConnectAsync(session);
    Debug.LogError("Socket connected.");

    // Listen to match data
    socket.ReceivedMatchState += OnReceivedMatchState;
    
    socket.ReceivedMatchmakerMatched += OnMatched;
    socket.ReceivedMatchPresence += OnMatchPresence;
  
}

private void OnMatchPresence(IMatchPresenceEvent message)
{
    Debug.LogError($"{message.MatchId} presence updated");

    foreach (var item in message.Joins)
    {
        Debug.LogError($"{item.Username} joined the match. {item.Persistence}  {item.Status}");
    }

    foreach (var item in message.Leaves)
    {
        Debug.LogError($"{item.Username} left the match {item.Persistence}  {item.Status}"); 
    }
}

private async void OnMatched(IMatchmakerMatched newMatch)
{
    Debug.LogError("matched");
    Debug.LogError(newMatch.MatchId);
    match = await socket.JoinMatchAsync(newMatch);
}


private void OnReceivedMatchState(IMatchState matchState)
{
    string receivedMessage = System.Text.Encoding.UTF8.GetString(matchState.State);
    Debug.LogError($"Received from match: {receivedMessage}");
}


private async void SendMessage(string message)
{
    if (match != null)
    {
        byte[] data = System.Text.Encoding.UTF8.GetBytes(message);
        await socket.SendMatchStateAsync(match.Id, 0, data);
        Debug.LogError($"Sent message: {message}");
    }
}

private async void CreateMatch()
{
    var ticket = await socket.AddMatchmakerAsync("*", 2, 2);

    Debug.LogError($"ticket id:{ticket.Ticket}");
}


}

its my whole sample code.

Apologies but I’m still not sure to which two callbacks you’re referring to, what issue you’re facing or what’s the question.

i have to send the logs here to show the problem. i will do it.

in previous examlpe:

_socket.ReceivedMatchPresence += OnMatchPresence;

  private void OnMatchPresence(IMatchPresenceEvent message)
  {
      Debug.LogError($"{message.MatchId} presence updated");

      foreach (var item in message.Joins)
      {
          Debug.LogError($"{item.Username} joined the match. {item.Persistence}  {item.Status}");
      }

      foreach (var item in message.Leaves)
      {
          Debug.LogError($"{item.Username} left the match {item.Persistence}  {item.Status}");
      }
  }

result of the above code for the first matched user:

    cb97c750-d4a4-4c55-87cc-e24dcbe8bcfd. presence updated
    vibFUuQxjp joined the match. False  
    LvpIOPlZSr joined the match. False  
    
    result of above code for seconds matched user:
    cb97c750-d4a4-4c55-87cc-e24dcbe8bcfd. presence updated
    vibFUuQxjp joined the match. False  
    cb97c750-d4a4-4c55-87cc-e24dcbe8bcfd. presence updated
    LvpIOPlZSr joined the match. False  

it means the event is called for seconds player 2 times but separately for each players.

i hope this clarifies.

So if I understood correctly, the question is why you sometimes see two separate events with a join each, and sometimes a single event with both joins?

This is not an issue nor a technical limitation, but rather an optimization, events can be batched within the same call or not depending on how the server processes them.