Closed endel closed 5 years ago
looks reasonable any api changes?
Thanks @Wenish,
I've just tested on Android and it looks to be working. Need to check if onClose
events are being triggered properly (https://github.com/colyseus/colyseus-unity3d/issues/52) in case of internet connectivity lost and/or server going down.
The major API changes are the signature change for OnOpen
, OnClose
, OnLeave
, the deprecation of room.ReadyToConnect()
, and deprecation of using StartCoroutine()
in favor of await Client.Connect()
.
The guys from MessagePack-CSharp are working on releasing a new version for Unity lately (https://github.com/neuecc/MessagePack-CSharp/pull/542), so I'll wait a bit more to play with the MessagePack alternative. 🙏
I merge the code to the local working copy. Test it in the Editor Mode, it works except OnError() and OnClose(). OnError don't be invoked, because there is no code to register it for invoking as OnClose().
public Client (string _endpoint, string _id = null)
{
Id = _id;
endpoint = new UriBuilder(new Uri (_endpoint));
Auth = new Auth(endpoint.Uri);
connection = CreateConnection();
connection.OnMessage += (bytes) => ParseMessage(bytes);
connection.OnClose += (code) => OnClose?.Invoke(code);
}
No callbacks invoking is in case of internet connectivity lost and/or server going down, because exceptions will be caught outside Receive().
try
{
m_Socket = new ClientWebSocket();
await m_Socket.ConnectAsync(uri, CancellationToken.None);
OnOpen?.Invoke();
await Receive();
}
catch (Exception ex)
{
OnError?.Invoke(ex.Message);
}
Thanks @chsqn, I've made some changes to ensure OnError
/ OnClose
is called.
Also documented what has changed to use the Unity3d client here: https://github.com/colyseus/docs/pull/23/files
Let me know if you have any thoughts about these changes!
@endel in the docs, the params have no types? i guess thats not valid c# but maybe im wrong?
Thanks for reviewing @Wenish! C# is smart about the arguments on lambda expressions, the types are optional on them, look at this screenshot :)
i have a question about, handling server-matchmaking related error messages client side. I mainly talking about https://github.com/colyseus/colyseus-unity3d/blob/d90cc4670e3c02545b55b090908d7685cebd888a/Assets/Plugins/Colyseus/Events.cs
Wouldn't be more elegant to categorize the existing error messages with an error code?
So client side dont have to string compare like Error: Failed to auto-create room "room_name" during join request using options "
Off:
This changes what you mentioned in the PR sounds amazing. Most of the mentioned problems our team is already experienced and we had to do some work around especially the OnClose
not beeing called in IOS ASAP. 🙏
Hi @Xian55, thanks for your feedback. Would you mind trying out this branch (refactoring
) on your project, and check the iOS build if the OnClose
gets fixed?
This week I'm also working on version v0.11
of the server (and clients) with improved matchmaking (https://github.com/colyseus/colyseus/issues/176#issuecomment-520658934), and as this pull-request AND v0.11
introduces some breaking changes in the API, the changes of this PR will come only for v0.11
.
Cheers!
Closes https://github.com/colyseus/colyseus-unity3d/issues/74 https://github.com/colyseus/colyseus-unity3d/issues/65 https://github.com/colyseus/colyseus-unity3d/pull/80 https://github.com/colyseus/colyseus-unity3d/pull/53
System.Net.WebSockets
with a jslib fallback for WebGLOnOpen
,OnClose
, etc.Recv()
calls androom.ReadyToConnect()
JsonUtility
instead ofGameDevWare.Serialization
insideAuth.cs
Editor/
folder, preventing NUnit issues.GameDevWare.Serialization
, otherwise no replacement is necessary.If you have been using the Unity3D client, let me know your thoughts about these changes! /cc @Wenish @etherny @mobyjames