Can't rejoin room in Unity3D

So you mean that in my Rejoin coroutine i just need to add

room.OnReadyToConnect += (sender, e) => 
{
    Debug.Log("Ready to connect to room!");
     StartCoroutine (room.Connect ());
};

or only StartCoroutine (room.Connect ()); and everything else till Rejoin remains the same

@usamasermad yes, like this:

room = client.ReJoin(roomName, sessionId);
room.OnReadyToConnect += (sender, e) => 
{
    Debug.Log("Ready to connect to room!");
     StartCoroutine (room.Connect ());
};

As you suggested I changed my code to this but didn't reconnected
0_1551707666373_new rejoin.PNG

and these are my logs for your convenience
0_1551707699468_rejoin logs.PNG

@usamasermad I see, do you possibly have onAuth() validation the server-side? If you do, I'd ask you to try a bit differently:

Dictionary<string, object> options = new Dictionary<string, object> ();
options.Add ("sessionId", sessionId);
options.Add(/* your authentication options */)

room = client.Join(roomName, options);
room.OnReadyToConnect += (sender, e) => 
{
    Debug.Log("Ready to connect to room!");
     StartCoroutine (room.Connect ());
};

Currently we don't have any kind of validation required for this room. It is just only named as onAuth() because we send email and password to the server in this room but that is only after clicking on register button which means we dont have to send anything automatically to the server

@usamasermad I've just tested this and apparently it works fine. Can you check the demo project on the official colyseus-unity3d repository?

I've organized a bit better the demo project and added a "Re-Join Room" button to demonstrate. The only thing I've changed in the Colyseus Client itself was the ability to call room.Leave(false) to force an "unconsented" leave in the server-side. (see release notes)

Hope this helps, let me know if you still can't perform a reconnect.

@endel Thanks a lot for your quick solution. Rejoin works like a charm for me now. New updated demo project is also very good organized and easy to understand and has cleared a lot of confusions.

@endel Hey sorry to interrupt but I have noticed that unity client cant reconnect if our connection is closed i.e client.OnClose. However Rejoin works fine if client is not closed

  • Like in this
    0_1551786126471_clientclose.PNG

Should i create new client and then try to Rejoin it with server or it is not yet implemented on serverside?

For your knowledge I am testing it by increasing my packet drop rate to 90%. It works fine if i leave the room with consented = false. But doesn't reconnect if client connection is closed

@usamasermad yes, you should ensure the Client connection is open before performing a ReJoin. If you're going to instantiate a new Client, make sure it has the same client.id as the one who initiated the first connection to the room (https://github.com/colyseus/colyseus-unity3d/blob/master/Assets/Plugins/Colyseus/Client.cs#L66)