colyseus / colyseus-unity-sdk

⚔ Colyseus Multiplayer SDK for Unity
https://docs.colyseus.io/getting-started/unity-sdk/
MIT License
371 stars 102 forks source link

joinOrCreate is not calling OnJoinHandler #91

Closed MateusMendesSantana closed 4 years ago

MateusMendesSantana commented 4 years ago

OnJoin happening before we have a chance to assign subscriptions

var tcs = new TaskCompletionSource<Room<T>>();

void OnError(string message)
{
  room.OnError -= OnError;
  tcs.SetException(new Exception(message));
};

void OnJoin()
{
  room.OnError -= OnError;
  tcs.TrySetResult(room);
}

room.OnError += OnError;
room.OnJoin += OnJoin;

ColyseusManager.Instance.AddRoom(room);

return await tcs.Task;

OnJoinHandler will not be called

var room = await client.JoinOrCreate<T>(roomName, options);
room.OnJoin += OnJoinHandler;
endel commented 4 years ago

Hi @MateusMendesSantana, this is a recent change - you don't need to use OnJoin += anymore, since the .JoinOrCreate() method will only return the room instance after OnJoin has completed internally.