Java Colyseus Client problem with reconnect
-
Hi all, please help. I have turn based server. There is problem with implement reconnect feature (after network disconnected) with saving user sessionId and roomId
The client:
private val serverRoomListener = object : Room.Listener() { override fun onLeave() { Timber.e("leave") task = object : Timer.Task() { override fun run() { ServerClient.getInstance(ServerClient.Builder(url = SERVER_WS)).also { it.setListener(object: Client.Listener{ override fun onMessage(message: Any?) { } override fun onClose(code: Int, reason: String?, remote: Boolean) { } override fun onError(e: java.lang.Exception?) { } override fun onOpen(id: String?) { val rejoin = it.rejoin(currentRoom.name, it.id) if(rejoin.hasJoined()){ task.cancel() } } }) it.connect() } } } Timer.schedule(task, 10f, 0f, 0) }
Timer tick delay 10s
The server "colyseus": "^0.9.32":
onJoin(client, options?, auth?) { console.log(this.getLogTag(), options, auth, client.id); if (options.create) { this.state.masterPlayer = client.id } else { this.state.slavePlayer = client.id } console.log(this.getLogTag(), 'Client joined: ' + client.id); if (this.clients.length == 2) { this.lock(); this.state.state = State.GAME; let command = {}; this.clients.forEach(function (value) { command[value.id] = {} }); this.state.command = command } this.broadcastPatch() } async onLeave(client, consented?) { try { if (consented) { throw new Error("consented leave"); } console.log(this.getLogTag(), "Count users:", this.clients.length, consented); await this.allowReconnection(client); console.log(this.getLogTag(), 'Reconnect client: ' + client.id); } catch (e) { console.log(this.getLogTag(), 'Error: ' + e); console.log(this.getLogTag(), 'Client left: ' + client.id); if (client.id == this.state.masterPlayer) { this.state.masterPlayer = null; // this.unlock() } else if (client.id == this.state.slavePlayer) { this.state.slavePlayer = null; // this.unlock() } } }
reconnection server log http://prntscr.com/mvsyas
Thanks for help.
-
I have some new ideas https://github.com/colyseus/colyseus/issues/224
-
Hello @daimonkor I'm using also Colyseus Client on Android, this unofficial portage to Java: https://github.com/doorbash/colyseus-java
I've seen you are using Kotlin, did you make your own version from doorbash's library? I'm interested in your Kotlin lib :)
Thanks