GitHub Documentation

How to reconnect users on Unity Client?

  • Hi , I have a game running on heroku, but on certain time I get some of the follow code on the server:

    2020-09-24T18:02:17.725202+00:00 heroku[router]: at=info method=GET path="/sV4fSkj6g/trtp8tPvp?sessionId=vvWRdGKW1" request_id=914eb756-b46c-4042-b290-0284c35203a6 fwd="" dyno=web.1 connect=1ms service=574791ms status=101 bytes=129 protocol=https
    2020-09-24T18:02:17.711452+00:00 heroku[router]: at=info method=GET path="/sV4fSkj6g/ZNxVksd6g?sessionId=7mv_XdznN" request_id=d69e6f15-95d8-4463-915e-6f32aa6023e3 fwd="" dyno=web.1 connect=0ms service=596820ms status=101 bytes=129 protocol=https
    2020-09-24T18:02:17.725482+00:00 app[web.1]: player 7mv_XdznN leaved
    2020-09-24T18:02:17.733409+00:00 app[web.1]: player vvWRdGKW1 leaved

    then the player left the game but I need to recconnect it, I put the code of recconect on colyseus, but I don't know if any have an example to reconnect on Unity c#.

  • Solution:

    room.OnLeave += (code) => {
    Debug.Log("ROOM: ON LEAVE, code => " + code);

    async void ReconnectRoom()
    string roomId = PlayerPrefs.GetString("roomId");
    string sessionId = PlayerPrefs.GetString("sessionId");
    if (string.IsNullOrEmpty(sessionId) || string.IsNullOrEmpty(roomId))
    Debug.Log("Cannot Reconnect without having a roomId and sessionId");
    room = await client.Reconnect<State>(roomId, sessionId);
    Debug.Log("Reconnected into room successfully.");


© 2021 Lucid Sight, Inc