Hi , i have a question there is a way to handle error in the client side when the client lose connection with the server ?
handl error when client recconect(SOLVED)
@chaimae
Hi,
reference:
- https://docs.colyseus.io/colyseus/client/client/#reconnect-roomid-string-sessionid-string
Usage - Colyseus & Arena Cloud Documentation
Documentation for Colyseus Multiplayer Framework for Node.js - https://docs.colyseus.io/colyseus/server/room/#allowreconnection-client-seconds
Room - Colyseus & Arena Cloud Documentation
Documentation for Colyseus Multiplayer Framework for Node.js - https://github.com/colyseus/colyseus-unity3d/blob/master/Server/src/rooms/MyRoom.ts
GitHub
colyseus-unity-sdk/MyRoom.ts at master · colyseus/colyseus-unity-sdk
server:
async onLeave (client: Client, consented: boolean) {
// flag client as inactive for other users
this.state.players.get(client.sessionId).connected = false;
try {
if (consented) {
throw new Error("consented leave");
}
// allow disconnected client to reconnect into this room until 20 seconds
await this.allowReconnection(client, 20);
// client returned! let's re-activate it.
this.state.players.get(client.sessionId).connected = true;
} catch (e) {
// 20 seconds expired. let's remove the client.
this.state.players.delete(client.sessionId);
}
}
client:
private void OnLeaveRoom(int code)
{
WebSocketCloseCode parsedCode = WebSocketHelpers.ParseCloseCodeEnum(code);
LSLog.Log(string.Format("ROOM: ON LEAVE =- Reason: {0} ({1})", parsedCode, code));
_pingThread.Abort();
_pingThread = null;
_room = null;
if (parsedCode != WebSocketCloseCode.Normal && !string.IsNullOrEmpty(_lastRoomId))
{
JoinRoomId(_lastRoomId,null);
}
}